Page 1 of 1
Switch light/switches to Off with one switch
Posted: Saturday 14 November 2020 13:45
by Bospieper
Hi,
I have in my home several lamps en switches running with dzvents timebased scripts. When I go to bed, in most cases the most of lamps and switches are on because there are persons in my household which going to bed much later then I

I've tried to program a device who can do this, but as soon all lights/switches are off one minute later they are activited by there own script and the light/switches go on. What I want: I am alone at home and a lamp is programmed to go off at 01:00. I am going to bed at 23:00 and I want the lamp switched off. How do I program this ? If only I have a hint in the right direction

Thanx in advance.
re: Switch light/switches to Off with one switch
Posted: Saturday 14 November 2020 17:19
by waaren
Bospieper wrote: ↑Saturday 14 November 2020 13:45
they are activited by there own script and the light/switches go on.
I guess you need to modify this 'own' script so the logic in the script can check if the lights need to be switched on in this case.
Re: Switch light/switches to Off with one switch
Posted: Saturday 14 November 2020 19:27
by Bospieper
Hi Waaren,
I give you an example of one of my scripts. Maybe you can piont me out in the right direction.
Thanx.
Code: Select all
return {
active = true,
on =
{
timer =
{
'20 minutes before sunset',
'between sunset and 60 minutes after sunset',
'between 60 minutes after sunset and 120 minutes after sunset',
'between 120 minutes after sunset and 23:50',
'at 23:50'
},
devices =
{
'light'
},
},
logging =
{
level = domoticz.LOG_INFO, -- set to domoticz.LOG_ERROR when all ok
marker = 'Lamp bank',
},
execute = function(dz, timer )
local light = dz.devices('Switch- lamp boven bank')
if dz.time.matchesRule('20 minutes before sunset') then
light.dimTo(5)
elseif dz.time.matchesRule('between sunset and 60 minutes after sunset') then
light.dimTo(20)
end
if dz.time.matchesRule('between 60 minutes after sunset and 120 minutes after sunset') then
light.dimTo(25)
elseif dz.time.matchesRule('between 120 minutes after sunset and 23:50') then
light.dimTo(15)
end
if dz.time.matchesRule('at 23:50') then
light.switchOff().checkFirst()
end
end
}
Re: Switch light/switches to Off with one switch
Posted: Saturday 14 November 2020 19:52
by waaren
Bospieper wrote: ↑Saturday 14 November 2020 19:27
Hi Waaren,
I give you an example of one of my scripts. Maybe you can piont me out in the right direction.
Sure,
this extra script will be triggered on a master switch
Code: Select all
return
{
on =
{
timer =
{
'at 05:13', -- a quiet time on a moment that you know everyone is sleeping (or at least should) to reset the master switch
},
devices =
{
'masterSwitch', -- virtual switch to trigger a Scene that will switch all lights off
},
},
logging =
{
level = domoticz.LOG_DEBUG -- set to domoticz.LOG_ERROR when all ok
marker = 'One switch to rule them all',
},
execute = function(dz, item )
local master = dz.devices('masterSwitch')
local allLights = dz.scenes('All lights Off')
if item.isTimer then
master.switchOff().checkFirst().silent()
elseif item.active then
allLights.switchOn() -- trigger the scene that switches off all lights
end
end
}
this is your modified script that will evaluate the state of the masterswitch to decide if any further action is required
Code: Select all
return
{
active = true,
on =
{
timer =
{
'20 minutes before sunset',
'between sunset and 60 minutes after sunset',
'between 60 minutes after sunset and 120 minutes after sunset',
'between 120 minutes after sunset and 23:50',
'at 23:50'
},
devices =
{
'light'
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when all ok
marker = 'Lamp bank',
},
execute = function(dz, timer )
local master = dz.devices('masterSwitch') -- virtual switch to trigger a Scene that will switch all lights off
if master.active then
dz.log('Rest of script will be ignored because master switch is activated and every light should stay off',dz.LOG_DEBUG )
return
end
local light = dz.devices('Switch- lamp boven bank')
if dz.time.matchesRule('20 minutes before sunset') then
light.dimTo(5)
elseif dz.time.matchesRule('between sunset and 60 minutes after sunset') then
light.dimTo(20)
end
if dz.time.matchesRule('between 60 minutes after sunset and 120 minutes after sunset') then
light.dimTo(25)
elseif dz.time.matchesRule('between 120 minutes after sunset and 23:50') then
light.dimTo(15)
end
if dz.time.matchesRule('at 23:50') then
light.switchOff().checkFirst()
end
end
}
Re: Switch light/switches to Off with one switch
Posted: Saturday 14 November 2020 20:25
by Bospieper
Hi Waaren,
Thanks for the help. If I'am correct then the first script checks at the given time if the masterswitch is off, if not then the second script is activated and causus the lamp to switch to OFF.
But when I'am allone at home and I want the lamp by masterswitch go off before the off-time in its own script ?
Re: Switch light/switches to Off with one switch
Posted: Saturday 14 November 2020 21:02
by waaren
Bospieper wrote: ↑Saturday 14 November 2020 20:25
If I'am correct then the first script checks at the given time if the masterswitch is off, if not then the second script is activated and causus the lamp to switch to OFF.
No that is not how it works.
The first script is triggered by the masterswitch and triggers a scene (that you have to create) That scene should switch Off all lights.
The second script (a modified version of yours) only does something when the masterswitch is Off.
Re: Switch light/switches to Off with one switch (SOLVED) [SOLVED]
Posted: Sunday 15 November 2020 7:58
by Bospieper
Yes, I understand now how it's working. I am gonna adjust my scripts and try this tonight.
Thanx again for your assistence, I let you no if it's working.
For now the problem is SOLVED.
Grz
Re: Switch light/switches to Off with one switch
Posted: Sunday 15 November 2020 18:16
by Bospieper
Hi Waaren,
After handling some device name problems the scripts are working but not with the expected result. Here is a copy from my log:
- Spoiler: show
Code: Select all
2020-11-15 18:14:45.169 Activating Scene/Group Device: Switch- masterswitch (On)
2020-11-15 18:14:45.175 (Test) Light/Switch (Switch- masterswitch)
2020-11-15 18:14:45.183 (Nefit) onMessage called with: PUBLISH
2020-11-15 18:14:45.334 (Nefit) onMessage called with: PUBLISH
2020-11-15 18:14:45.358 Activating Scene/Group: [Alles uit]
2020-11-15 18:14:45.360 Activating Scene/Group Device: Switch- masterswitch (On)
2020-11-15 18:14:45.365 (Test) Light/Switch (Switch- masterswitch)
2020-11-15 18:14:45.505 Activating Scene/Group: [Alles uit]
2020-11-15 18:14:45.507 Activating Scene/Group Device: Switch- masterswitch (On)
2020-11-15 18:14:45.512 (Test) Light/Switch (Switch- masterswitch)
2020-11-15 18:14:45.648 Activating Scene/Group: [Alles uit]
2020-11-15 18:14:45.650 Activating Scene/Group Device: Switch- masterswitch (On)
2020-11-15 18:14:45.655 (Test) Light/Switch (Switch- masterswitch)
2020-11-15 18:14:45.830 Activating Scene/Group: [Alles uit]
2020-11-15 18:14:45.832 Activating Scene/Group Device: Switch- masterswitch (On)
2020-11-15 18:14:45.837 (Test) Light/Switch (Switch- masterswitch)
2020-11-15 18:14:45.973 Activating Scene/Group: [Alles uit]
2020-11-15 18:14:45.975 Activating Scene/Group Device: Switch- masterswitch (On)
2020-11-15 18:14:45.979 (Test) Light/Switch (Switch- masterswitch)
2020-11-15 18:14:45.159 Status: dzVents: Info: Handling events for: "Switch- masterswitch", value: "On"
2020-11-15 18:14:45.159 Status: dzVents: Info: One switch to rule them all: ------ Start internal script: Allesuit: Device: "Switch- masterswitch (Test)", Index: 1197
2020-11-15 18:14:45.160 Status: dzVents: Debug: One switch to rule them all: Processing device-adapter for Alles uit: Scene device adapter
2020-11-15 18:14:45.160 Status: dzVents: Debug: One switch to rule them all: Constructed timed-command: On
2020-11-15 18:14:45.160 Status: dzVents: Info: One switch to rule them all: ------ Finished Allesuit
2020-11-15 18:14:45.161 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-15 18:14:45.322 Status: dzVents: Info: Handling events for: "Switch- masterswitch", value: "On"
2020-11-15 18:14:45.322 Status: dzVents: Info: One switch to rule them all: ------ Start internal script: Allesuit: Device: "Switch- masterswitch (Test)", Index: 1197
2020-11-15 18:14:45.323 Status: dzVents: Debug: One switch to rule them all: Processing device-adapter for Alles uit: Scene device adapter
2020-11-15 18:14:45.323 Status: dzVents: Debug: One switch to rule them all: Constructed timed-command: On
2020-11-15 18:14:45.323 Status: dzVents: Info: One switch to rule them all: ------ Finished Allesuit
2020-11-15 18:14:45.324 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-15 18:14:45.479 Status: dzVents: Info: Handling events for: "Switch- masterswitch", value: "On"
2020-11-15 18:14:45.479 Status: dzVents: Info: One switch to rule them all: ------ Start internal script: Allesuit: Device: "Switch- masterswitch (Test)", Index: 1197
2020-11-15 18:14:45.479 Status: dzVents: Debug: One switch to rule them all: Processing device-adapter for Alles uit: Scene device adapter
2020-11-15 18:14:45.480 Status: dzVents: Debug: One switch to rule them all: Constructed timed-command: On
2020-11-15 18:14:45.480 Status: dzVents: Info: One switch to rule them all: ------ Finished Allesuit
2020-11-15 18:14:45.481 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-15 18:14:45.639 Status: dzVents: Info: Handling events for: "Switch- masterswitch", value: "On"
2020-11-15 18:14:45.639 Status: dzVents: Info: One switch to rule them all: ------ Start internal script: Allesuit: Device: "Switch- masterswitch (Test)", Index: 1197
2020-11-15 18:14:45.640 Status: dzVents: Debug: One switch to rule them all: Processing device-adapter for Alles uit: Scene device adapter
2020-11-15 18:14:45.640 Status: dzVents: Debug: One switch to rule them all: Constructed timed-command: On
2020-11-15 18:14:45.640 Status: dzVents: Info: One switch to rule them all: ------ Finished Allesuit
2020-11-15 18:14:45.641 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-15 18:14:45.799 Status: dzVents: Info: Handling events for: "Switch- masterswitch", value: "On"
2020-11-15 18:14:45.799 Status: dzVents: Info: One switch to rule them all: ------ Start internal script: Allesuit: Device: "Switch- masterswitch (Test)", Index: 1197
2020-11-15 18:14:45.800 Status: dzVents: Debug: One switch to rule them all: Processing device-adapter for Alles uit: Scene device adapter
2020-11-15 18:14:45.800 Status: dzVents: Debug: One switch to rule them all: Constructed timed-command: On
2020-11-15 18:14:45.800 Status: dzVents: Info: One switch to rule them all: ------ Finished Allesuit
2020-11-15 18:14:45.801 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-15 18:14:45.955 Status: dzVents: Info: Handling events for: "Switch- masterswitch", value: "On"
2020-11-15 18:14:45.955 Status: dzVents: Info: One switch to rule them all: ------ Start internal script: Allesuit: Device: "Switch- masterswitch (Test)", Index: 1197
2020-11-15 18:14:45.956 Status: dzVents: Debug: One switch to rule them all: Processing device-adapter for Alles uit: Scene device adapter
2020-11-15 18:14:45.956 Status: dzVents: Debug: One switch to rule them all: Constructed timed-command: On
2020-11-15 18:14:45.956 Status: dzVents: Info: One switch to rule them all: ------ Finished Allesuit
Re: Switch light/switches to Off with one switch
Posted: Sunday 15 November 2020 21:59
by waaren
Bospieper wrote: ↑Sunday 15 November 2020 18:16
After handling some device name problems the scripts are working but not with the expected result. Here is a copy from my log:
It seems that you included the master Switch as one of the devices in the scene. That will not work.
Re: Switch light/switches to Off with one switch (SOLVED)
Posted: Friday 20 November 2020 2:41
by Bospieper
Hi Waaren,
It took me some time before I could test the script but I can tell you now that it's working. As you had noted I had for some strange reason the masterswitch included in the scene 'Alles uit' . After removing the switch the script works !
Thanxs for your help.