Fibaro Home Center 2 Programming

Fibaro Home Center 2 – Scenes – Download data from the web

5 views November 10, 2019 November 10, 2019 bicobro 0

The scene below requests a webservice for the value “True” or “False”. When true, it turns on a specific switch, when false it is turned off. In this case switch 169 is changed (see row 24 and 27), the switch is specific to your Home Center 2 device.

On row 11 you have to fill in the url to your webservice.

--[[
%% autostart
%% properties
%% weather
%% events
%% globals
--]]

local sourceTrigger = fibaro:getSourceTrigger();
function tempFunc()
    local requestUrl = "http://yourdomain.com/api"  
    local httpClient = net.HTTPClient()
    httpClient:request(requestUrl, {
        options = {
            method = "GET", 
            timeout = 5000,
            checkCertificate = false
        },
        success = function(resp)
           fibaro:debug("data" .. trim(resp.data))
           local isActive = trim(resp.data) -- "False" or "True"
           if isActive == "True" then
            fibaro:debug("-- MONITOR ON --")
            fibaro:call(169, "turnOn");              
         else          	  
            fibaro:debug("-- MONITOR OFF --")
            fibaro:call(169, "turnOff");
         end 
        end
        
    })
    
    setTimeout(tempFunc, 60 * 1000)
end

if (sourceTrigger["type"] == "autostart") then
    tempFunc()
else    
    local currentDate = os.date("*t");
    local startSource = fibaro:getSourceTrigger();
    if (
        startSource["type"] == "other"
    )
    then
        tempFunc()
    end
end

function trim(s)
   return (s:gsub("^%s*(.-)%s*$", "%1"))
end

 

Was this helpful?