Page 1 of 1
Switch lights on when dark
Posted: Tuesday 30 June 2020 12:43
by DRB2019
I'am struggling with the (simple) scipt below.
I do not have much experience with dzvents, but i want to learn it.
I have a dusk sensor, and when it switches to "on" i need to switch on some light in our room.
(depending on the state of another light and between a time limit)
Any help would be appreciated!
Code: Select all
return {
on = {
devices = {
'Schemerschakelaar1',
'Staande_lamp'
}
},
execute = function(domoticz,devices)
if Schemerschakelaar1.state == 'On' and
Staande_lamp.state == 'Off' and
(domoticz.time =='Between 11:30 and 22:20')
then
domoticz.devices('Staande_lamp').switchOn()
domoticz.devices('Dressoir').switchOn()
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
end
end
}
Re: Sitch lights on when dark
Posted: Tuesday 30 June 2020 14:02
by waaren
DRB2019 wrote: ↑Tuesday 30 June 2020 12:43
I have a dusk sensor, and when it switches to "On" i need to switch on some light in our room.
(depending on the state of another light and between a time limit)
Assuming the name of your dusk-sensor switch is Schemerschakelaar1 it could look like
Code: Select all
return
{
on =
{
devices =
{
'Schemerschakelaar1',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'dusk sensor',
},
execute = function(domoticz, item)
if item.state == 'On' and domoticz.devices('Staande_lamp').state == 'Off' and domoticz.time.matchesRule('at 11:30-22:20') then
domoticz.devices('Staande_lamp').switchOn()
domoticz.devices('Dressoir').switchOn()
domoticz.log('Device ' .. item.name .. ' was updated', domoticz.LOG_INFO)
end
end
}
Re: Sitch lights on when dark
Posted: Tuesday 30 June 2020 21:13
by DRB2019
waaren wrote: ↑Tuesday 30 June 2020 14:02
Assuming the name of your dusk-sensor switch is Schemerschakelaar1 it could look like
Your script works perfect!
I modified it a bit, so when the dusk sensor goes to 'Off' the lights also switch off. (fluctuation of light in the house).
Is there also a possibility to send a telegram message when the lights go on?
Code: Select all
return
{
on = {
timer = {'every 10 minutes'},
devices = {'Schemerschakelaar1'}
},
logging =
{
level = domoticz.LOG_ERROR, -- change to LOG_ERROR when ok (was LOG_DEBUG)
marker = 'dusk sensor',
},
execute = function(domoticz, item)
if item.state == 'On' and domoticz.devices('Staande_lamp').state == 'Off' and domoticz.time.matchesRule('at 15:30-22:20')
then
domoticz.devices('Staande_lamp').switchOn()
domoticz.devices('Dressoir').switchOn()
domoticz.log('Device ' .. item.name .. ' was updated', domoticz.LOG_INFO)
else
if item.state == 'Off' and domoticz.devices('Staande_lamp').state == 'On' and domoticz.time.matchesRule('at 15:30-22:20')
then
domoticz.devices('Staande_lamp').switchOff()
domoticz.devices('Dressoir').switchOff()
end
end
end
}
Re: Sitch lights on when dark
Posted: Tuesday 30 June 2020 21:52
by waaren
DRB2019 wrote: ↑Tuesday 30 June 2020 21:13
Is there also a possibility to send a telegram message when the lights go on?
Yes.
please have a look at the
dzVents wiki
notify(subject, message, priority, sound, extra, subsystem): Function. Send a notification (like Prowl). Priority can be like domoticz.PRIORITY_LOW, PRIORITY_MODERATE, PRIORITY_NORMAL, PRIORITY_HIGH, PRIORITY_EMERGENCY. For sound see the SOUND constants below. subsystem can be a table containing one or more notification subsystems. See domoticz.NSS_subsystem types.
why did you add?
It will not do anything in this script.
Re: Sitch lights on when dark
Posted: Tuesday 30 June 2020 23:12
by DRB2019
why did you add?
It will not do anything in this script.
I only want to run the script every 10 minutes.
Just to avoid the lights switching on and off quickly
How can you realize this?
I will dig in the notify function and try it out!
Re: Sitch lights on when dark [Solved]
Posted: Tuesday 30 June 2020 23:50
by waaren
DRB2019 wrote: ↑Tuesday 30 June 2020 23:12
I only want to run the script every 10 minutes. Just to avoid the lights switching on and off quickly
How can you realize this?
Could look like
Code: Select all
return
{
on = {
timer = {'every 10 minutes between 15:30 and 22:20'},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when ok (was LOG_DEBUG)
marker = 'dusk sensor',
},
execute = function(domoticz)
local dusk = domoticz.devices('Schemerschakelaar1')
if dusk.state == 'On' and domoticz.devices('Staande_lamp').state == 'Off' then
domoticz.devices('Staande_lamp').switchOn()
domoticz.devices('Dressoir').switchOn()
domoticz.log('Device ' .. item.name .. ' was updated', domoticz.LOG_INFO)
elseif dusk.state == 'Off' and domoticz.devices('Staande_lamp').state == 'On' then
domoticz.devices('Staande_lamp').switchOff()
domoticz.devices('Dressoir').switchOff()
end
end
}
Re: Sitch lights on when dark
Posted: Wednesday 01 July 2020 12:34
by DRB2019
It now works the way I want it!
Thanks !!
Also got telegram working: D, below the script I use.
Could look like
Code: Select all
return
{
on = {
timer = {'every 10 minutes between 15:30 and 22:20'},
},
logging =
{
level = domoticz.LOG_ERROR, -- change to LOG_ERROR when ok (was LOG_DEBUG)
marker = 'dusk sensor',
},
execute = function(domoticz)
local dusk = domoticz.devices('Schemerschakelaar1')
if dusk.state == 'On' and domoticz.devices('Staande_lamp').state == 'Off' then
domoticz.devices('Staande_lamp').switchOn()
domoticz.devices('Dressoir').switchOn()
domoticz.notify('Donker', 'Het is donker binnen', PRIORITY_HIGH, SOUND_PERSISTENT, nil, domoticz.NSS_TELEGRAM)
domoticz.log('Device ' .. item.name .. ' was updated', domoticz.LOG_INFO)
elseif
dusk.state == 'Off' and domoticz.devices('Staande_lamp').state == 'On' then
domoticz.devices('Staande_lamp').switchOff()
domoticz.devices('Dressoir').switchOff()
end
end
}
Re: Sitch lights on when dark
Posted: Wednesday 01 July 2020 13:48
by waaren
DRB2019 wrote: ↑Wednesday 01 July 2020 12:34
It now works the way I want it!
Please use English on the forum.
PRIORITY_HIGH and SOUND_PERSISTENT are no valid constants in dzVents you probably meant
domoticz.PRIORITY_HIGH and domoticz.SOUND_PERSISTENT
also please note that the SOUND constants are only used for the pushover notification subsystem in domoticz. For other notification susbsystems this parameter is ignored.
Re: Switch lights on when dark
Posted: Wednesday 01 July 2020 14:48
by DRB2019
I changed the script to
domoticz.PRIORITY_HIGH and domoticz.SOUND_PERSISTENT
Thanks!