The execute() function gets executed for every trigger you defined in the on = {} - section. I.e. yours executes once every two minutes, but also when one of the devices 199 or 43 changes state. To distinguish between the different reasons for executing, you need the 2nd parameter to the execute() function. I don't know what exactly it is you want to achieve with your script, so here's a template you can use to build what you want. I also added device 42 (your temperature sensor) to show that you can use this to trigger the notification whenever the temperature changes.
Code: Select all
return {
on = {
devices = {
199, 43, 42
},
timer = {
'every 2 minutes'
}
},
logging = {
level = domoticz.LOG_INFO,
marker = "Sauna"
},
execute = function(domoticz, item)
local Home = domoticz.devices(199)
local Sauna = domoticz.devices(43)
local TempDevice = domoticz.devices(42)
if nil == Home then
domoticz.log( 'Device 199 not found.', domoticz.LOG_ERROR)
elseif nil == Sauna then
domoticz.log( 'Device 43 not found.', domoticz.LOG_ERROR)
elseif nil == TempDevice then
domoticz.log( 'Device 42 not found.', domoticz.LOG_ERROR)
else
if item.isTimer then
domoticz.log( 'execute activated by timer ' .. item.name .. '.', domoticz.LOG_INFO)
-- to do: add code here to do whatever you want to do every 2 minutes.
elseif item.isDevice then
if item.idx == 199 then
domoticz.log( 'Device ' .. tostring(item.idx) .. ', ' .. item.name .. ' changed.', domoticz.LOG_INFO)
-- to do: add code here you want executed whenever device 199 changes state.
if item.active then
domoticz.log( 'Device ' .. tostring(item.idx) .. ', ' .. item.name .. ' switched on.', domoticz.LOG_INFO)
-- to do: add code here you want executed when device 199 switches on.
else
domoticz.log( 'Device ' .. tostring(item.idx) .. ', ' .. item.name .. ' switched off.', domoticz.LOG_INFO)
-- to do: add code here you want execiuted when device 199 switches off.
end
elseif item.idx == 43 then
domoticz.log( 'Device ' .. tostring(item.idx) .. ', ' .. item.name .. ' changed.', domoticz.LOG_INFO)
-- to do: add code here you want executed when device 43 changes state.
if item.active then
domoticz.log( 'Device ' .. tostring(item.idx) .. ', ' .. item.name .. ' switched on.', domoticz.LOG_INFO)
-- to do: add code her you want executed when device 43 switches on.
domoticz.notify( "Sauna", "Temperatuur is nu ".. tostring(math.floor(TempDevice.temperature+0.5)) .. " !", domoticz.PRIORITY_HIGH, "telegram")
else
domoticz.log( 'Device ' .. tostring(item.idx) .. ', ' .. item.name .. ' switched off.', domoticz.LOG_INFO)
-- to do: add code her you want executed when device 43 switches off.
end
elseif item.idx == 42 then
domoticz.log( 'Device ' .. tostring(item.idx) .. ', ' .. item.name .. ' changed.', domoticz.LOG_INFO)
if Sauna.active then
domoticz.notify( "Sauna", "Temperatuur is nu ".. tostring(math.floor(item.temperature+0.5)) .. " !", domoticz.PRIORITY_HIGH, "telegram")
end
else
domoticz.log( 'Unknown device '.. tostring(device.idx) .. ' triggered the script.', domoticz.LOG_ERROR)
end
end
end
-- if (Sauna.state == 'On') then and Home.state == 'On' then
-- Sauna.switchOff().afterSec(180)
-- end
-- if Sauna.state == 'On' then
-- domoticz.notify("Sauna","Temperatuur is nu "..Temp.." !",domoticz.PRIORITY_HIGH, "telegram")
-- end
end
}
This code has probably a lot of typos because I didn't test it all. But I hope it does give you an idea of what you can do in the execute() function.