Hi there. I am running 4.047 on my HC2. I am trying to use this command in LUA to see if there is rain forecast and if I have already set the rain delay to 24 hours then ignore the step. However it does not like the FHttp line.. What am I doing wrong?? The statement seems to work in a virtual device but not in a LUA scene. The error I get is
[ERROR] 22:22:46: line 11: attempt to index global 'Net' (a nil value) --]] local sourceTrigger = fibaro:getSourceTrigger(); -- Set authentication HC2 = Net.FHttp("192.168.1.xxx",80) HC2:setBasicAuthentication("admin", "password") -- get data table from the Sprinklers Panel response ,status, errorCode = HC2:GET("/api/panels/drenchers"); jsonTable = json.decode(response); fibaro:debug('Rain Delay Value: ' ..jsonTable.rainDelay);
I even tried the following.
local HC2 = Net.FHttp("127.0.0.1", 11111); -- get data table from the Sprinklers Panel local response ,status, errorCode = HC2:GET("/api/panels/drenchers"); local jsonTable = json.decode(response); fibaro:debug('Rain Delay Value: ' ..jsonTable.rainDelay);
still no joy.
This is my entire code.
----------------------------------------------------------------
--[[ %% autostart %% properties 3 WeatherConditionConverted %% globals --]] local sourceTrigger = fibaro:getSourceTrigger(); -- Set authentication local HC2 = Net.FHttp("127.0.0.1", 11111); -- get data table from the Sprinklers Panel local response ,status, errorCode = HC2:GET("/api/panels/drenchers"); local jsonTable = json.decode(response); fibaro:debug('Rain Delay Value: ' ..jsonTable.rainDelay); function tempFunc() local currentDate = os.date("*t"); local startSource = fibaro:getSourceTrigger(); if ( ( fibaro:getValue(3, "WeatherConditionConverted") == "rain" ) or ( fibaro:getValue(3, "WeatherConditionConverted") == "storm" ) and (string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "12:01") and ( tonumber(jsonTable.rainDelay == 0 ) ) ) then fibaro:call(319, "pressButton", "2"); fibaro:call(tonumber(fibaro:getGlobalValue("RajIphone")), 'sendPush', 'Sprinkler Delayed by 24 hours'); fibaro:call(2, "sendEmail", "Sprinkler Delay", "Sprinkler Delay by 24 hours"); 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" and ( tonumber(jsonTable.rainDelay == 0 ) ) ) then fibaro:call(319, "pressButton", "2"); fibaro:call(tonumber(fibaro:getGlobalValue("RajIphone")), 'sendPush', 'Sprinkler Delayed by 24 hours'); fibaro:call(2, "sendEmail", "Sprinkler Delay", "Sprinkler Delay by 24 hours"); end end ----------------------------------------------------------------