I have multiple mysensors node. A node contains temp and relay, to act in future a heater.
I did write a simple lua code, but events are fired twice (I can see in log switches and text log)
I did read several posts and if I understand well, this is 'cause node answer late.
In effect seems to me reasonable. If my scripts doesn't read the "new" values, obviously it re-fire the trigger. I did comment the parts where trigger is fired at least twice.
This is the code, under LUA > Devices.
Code: Select all
commandArray = {}
-- get the minutes (e.g. at 11:47:53 m will value 47
local m = os.date('%M')
-- ogni 2 minuti
if (m % 2 == 0) then
print("The 2 minutes script interval reached")
-- get the temperature from termostato
temperature = otherdevices_svalues['Termostato']:match("([^;]+)");
temperature = tonumber(temperature);
print("La temperatura rilevata è " .. temperature);
-- shutdown the caldaia
if ( temperature > 28) then
if otherdevices['Caldaia'] ~= 'Off' then
-- this is fired at least twice...
commandArray['Caldaia'] = 'Off';
print('>>> EVENTO! Ho spento la caldaia');
end
end
-- shuton the caldaia
if ( temperature <= 28) then
if otherdevices['Caldaia'] ~= 'On' then
-- this is fired at least twice...
commandArray['Caldaia'] = 'On';
print('>>> EVENTO! Ho acceso la caldaia');
end
end
end
return commandArray
Code: Select all
2017-07-22 17:10:11.521 LUA: The 2 minutes script interval reached
2017-07-22 17:10:11.521 LUA: La temperatura rilevata è 30.6
[b]2017-07-22 17:10:11.522 LUA: >>> EVENTO! Ho spento la caldaia[/b]
2017-07-22 17:10:11.524 EventSystem: Script event triggered: Programmazione caldaia
2017-07-22 17:10:11.568 LUA: The 2 minutes script interval reached
2017-07-22 17:10:11.569 LUA: La temperatura rilevata è 30.6
[b]2017-07-22 17:10:11.569 LUA: >>> EVENTO! Ho spento la caldaia[/b]
2017-07-22 17:10:11.581 EventSystem: Script event triggered: Programmazione caldaia
2017-07-22 17:10:11.632 LUA: The 25 minutes script interval reached
2017-07-22 17:10:11.633 LUA: La temperatura rilevata è 30.6
2017-07-22 17:10:11.584 (ArduinoLocalGateway) Lighting 2 (Caldaia)
I'm looking for a wait/sleep of something, but seems to me that does not exists?
Thank you to all.