Aller au contenu
roberto.rattin@gmail.com

Scene activation with consumption monitoring device

Recommended Posts

Here is my problem:

I have to create a scene for my greenhouse that lets me start a heater and so far everything is simple.

I have a smart meter and I would like the heater to start only under certain conditions such as temperature type below 15 degrees, in a certain amount of time and consumption in watts less than 2900W.

No problem for the temperature and time interval but when I enter the consumption the scene "stripping".

Transforming a block scene I made this code that seems to work but actually runs only once even if there is the autostart.

What am I doing wrong?

Here is the lua code I am setting up:

 

 

--[[
%% autostart
%% properties
551 value
719 energy meter
%% weather
%% events
%% globals
--]]

local energyMeterID = 719
local sourceTrigger = fibaro:getSourceTrigger();
function tempFunc()
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
powerNow=api.get("/energy/now-1/now/single/devices/power/"..energyMeterID)
if (
 ( (tonumber(os.date("%H%M")) >= tonumber(string.format("%02d%02d", "16", "00")) and tonumber(os.date("%H%M")) <= tonumber(string.format("%02d%02d", "08", "59"))) and (math.floor(os.time()/60)-math.floor(1550131200/60))%1 == 0 )
and
 ( tonumber(fibaro:getValue(551, "value")) <= 15  and powerNow.W <= 2900 )
)
then
    fibaro:call(619, "turnOn");
end

setTimeout(tempFunc, 60*1000)
end
if (sourceTrigger["type"] == "autostart") then
tempFunc()
else

local energyMeterID = 719
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
powerNow=api.get("/energy/now-1/now/single/devices/power/"..energyMeterID)
if (
 ( (tonumber(os.date("%H%M")) >= tonumber(string.format("%02d%02d", "16", "00")) and tonumber(os.date("%H%M")) <= tonumber(string.format("%02d%02d", "08", "59"))) )
and
 ( tonumber(fibaro:getValue(551, "value")) <= 15  and powerNow.W <= 2900 )
or
startSource["type"] == "other"
)
then
    fibaro:call(619, "turnOn");
end

end

Partager ce message


Lien à poster
Partager sur d’autres sites

Is this code really working?

(tonumber(os.date("%H%M")) >= tonumber(string.format("%02d%02d", "16", "00")) and tonumber(os.date("%H%M")) <= tonumber(string.format("%02d%02d", "08", "59"))) 

It should not, you ask for a condition that will never be true : time>=1600 and time<0859, this will never hapen! you must put OR , try this:

(tonumber(os.date("%H%M")) <= 0859 or tonumber(os.date("%H%M")) >= 1600)

 

Partager ce message


Lien à poster
Partager sur d’autres sites

×