I'am new to the world of dzVents and with some solutions I found on this forum I have made my own little script.
The goal is to turn on the outside lights at 7.00 unless the sun is already up. I have made a group with al the lights that I want to turn on named Buitenverlichting. Could somebody advise me if this script triggers the lights how I would like? The lights are turned off with Homekit at sunrise. So no need to included that in the script.
return {
on = {
timer = {
function(domoticz)
return (domoticz.time.matchesRule('at 07:00') and domoticz.time.matchesRule('before sunrise'))
end
}
},
execute = function(domoticz, triggeredItem, info)
local d = dz.groups("Buitenverlichting")
if (d.state ~= 'On') then
d.switchOn()
end
end
}
Mrtn83 wrote: ↑Monday 09 November 2020 19:13
Could somebody advise me if this script triggers the lights how I would like? The lights are turned off with Homekit at sunrise. So no need to included that in the script.
Allmost..
The only remaining problems are:
You use dz in the body of the execute function but you send domoticz as the first parameter to this function; you should use the same name for both.
'before sunrise' by itself is not a valid timerule. You could use 'between 00:00 and sunrise'
return
{
on =
{
timer =
{
'at 07:00',
},
},
execute = function(dz)
if dz.time.matchesRule('between 00:00 and sunrise') then
local d = dz.groups("Buitenverlichting")
if (d.state ~= 'On') then
d.switchOn()
end
end
end
}
return
{
on =
{
timer =
{
'at 07:00',
},
Off =
{
timer =
{
'at sunrise',
},
},
execute = function(dz)
if dz.time.matchesRule('between 00:00 and sunrise') then
local d = dz.groups("Buitenverlichting")
if (d.state ~= 'On') then
d.switchOn()
end
elseif dz.time.matchesRule("at sunrise") then
local d = dz.groups("Buitenverlichting")
if (d.state ~= 'Off') then
d.switchOff()
end
end
end
}
return
{
on =
{
timer =
{
'at 07:00',
'at sunrise',
},
},
execute = function(dz)
local d = dz.groups('Buitenverlichting')
if dz.time.matchesRule('at sunrise') then
if d.state ~= 'Off' then d.switchOff() end
elseif dz.time.matchesRule('between 00:00 and sunrise') and d.state ~= 'On' then
d.switchOn()
end
end
}
Great, thank you very much. For future entertainment. If I would change for instance sunrise to 12:00 would that work?
That way I could use the base of this script for other autimations.
Mrtn83 wrote: ↑Thursday 19 November 2020 14:12
Great, thank you very much. For future entertainment. If I would change for instance sunrise to 12:00 would that work?
That way I could use the base of this script for other autimations.
Changing sunrise.. You must have great powers.. very far beyond domoticz
But yes. For dzVents sunrise is just a time. The only difference with something like 12:01 is that the value of the sunrise time is set by domoticz at 00:00 every day if the location is set and for some locations it is not filled during midwinter.
My superpowers amaze me to from time to time .
Thank you very much for the explanation. No Midwinter where we live so that won't be an issue.
Am I correct that if I would change local d = dz.groups('Buitenverlichting') to local light = domoticz.devices('Buitenlamp achter') only the light Buitenlamp achter would go on?
Mrtn83 wrote: ↑Thursday 19 November 2020 16:25
Am I correct that if I would change local d = dz.groups('Buitenverlichting') to local light = domoticz.devices('Buitenlamp achter') only the light Buitenlamp achter would go on?
No you would have to change some more.. Most important is that you don't mix dz and domoticz. The first (and here the only) parameter of the execute function is the domoticz object.
If you use the name dz for it, you have to keep using that name in the body of this execute function.
return
{
on =
{
timer =
{
'at 07:00',
'at sunrise',
},
},
execute = function(dz)
local light = dz.devices('Buitenlamp achter')
if dz.time.matchesRule('at sunrise') then
if light.state ~= 'Off' then light.switchOff() end
elseif dz.time.matchesRule('between 00:00 and sunrise') and light.state ~= 'On' then
light.switchOn()
end
end
}