Page 1 of 2
How to, create a cleaning-knob (or scene)?!
Posted: Friday 26 January 2024 17:21
by BarryT
Hi all, i hope someone can help me out a bit..
I have a lot of zigbee motion sensors (in every room) that will turn on the light (when the sensor says its dark enough to turn them on..)
this is done by a simple lua script, if motion detected turn on the light

the motion sensor has its own lux sensor, and so does not send a motion when the lux is to high.
this is working great, but now i want some higher level automation:
once or twice a week we are cleaning the house.
then we want to disable the motion sensors and set all the lights to 100+ white instead of some colors/dimmed lights.
now the question, is there a lua script somewhere, or someone can help me out with this?
Thanks a lot!
Barry
Re: How to, create a cleaning-knob (or scene)?!
Posted: Friday 26 January 2024 18:26
by HvdW
I'd make a new on/off switch named 'my new switch' or anything you like.
Knowing nothing about LUA I did it with dzvents
Code: Select all
return {
on = {
devices = {'my new switch'},
},
execute = function(domoticz, triggeredItem)
if domoticz.devices('my new botton').state == 'On' then
domoticz.devices('device one').setLevel(82)
domoticz.devices('device one').switchOn()
domoticz.devices('device two').setLevel(82)
domoticz.devices('device two').switchOn()
end
if domoticz.devices('my new botton').state == 'Off' then
domoticz.devices('device one').setLevel(oldlevel)
domoticz.devices('device one').switchOff()
domoticz.devices('device two').setLevel(oldlevel)
domoticz.devices('device two').switchOff()
end
end
}
Re: How to, create a cleaning-knob (or scene)?!
Posted: Friday 26 January 2024 18:30
by BarryT
HvdW wrote: βFriday 26 January 2024 18:26
I'd make a new on/off switch named 'my new switch' or anything you like.
Code: Select all
return {
on = {
devices = {'my new switch'},
},
execute = function(domoticz, triggeredItem)
if domoticz.devices('my new botton').state == 'On' then
domoticz.devices('device one').setLevel(82)
domoticz.devices('device one').switchOn()
domoticz.devices('device two').setLevel(82)
domoticz.devices('device two').switchOn()
end
if domoticz.devices('my new botton').state == 'Off' then
domoticz.devices('device one').setLevel(oldlevel)
domoticz.devices('device one').switchOff()
domoticz.devices('device two').setLevel(oldlevel)
domoticz.devices('device two').switchOff()
end
end
}
Thanks for answering and the script..!
But what about the motion detections wich i already have in my lua scripts, when this script is getting activated, my motion detections are overrule this script and the lights goes back to normal mode?
example of a my simple motion lua script:
Code: Select all
commandArray = {}
if (devicechanged['Motion'] == 'On') then commandArray['Lamp'] = 'Set Level 50'
elseif (devicechanged['Motion'] == 'Off') then commandArray['Lamp'] = 'Off'
end
return commandArray
i guess i have to include this in the new scipt?
Re: How to, create a cleaning-knob (or scene)?!
Posted: Friday 26 January 2024 19:07
by HvdW
Make a dump of the properties of the motion detection like
Code: Select all
domoticz.devices('motiondetection_1).dump()
or just a simple
Code: Select all
domoticz.devices('motiondetection_1).switchOff
whatever is the right command and place that before the switch and level command in the first script.
Code: Select all
return {
on = {
devices = {'my new switch'},
},
data = {},
logging = {},
execute = function(domoticz, triggeredItem)
if domoticz.devices('my new botton').state == 'On' then
domoticz.devices('motiondetection_1).switchOff()
domoticz.devices('device one').setLevel(82)
domoticz.devices('device one').switchOn()
domoticz.devices('motiondetection_2).switchOff()
domoticz.devices('device two').setLevel(82)
domoticz.devices('device two').switchOn()
end
if domoticz.devices('my new botton').state == 'Off' then
domoticz.devices('motiondetection_1).switchOn()
domoticz.devices('device one').setLevel(oldlevel)
domoticz.devices('device one').switchOff()
domoticz.devices('motiondetection_2).switchOn()
domoticz.devices('device two').setLevel(oldlevel)
domoticz.devices('device two').switchOff()
end
end
}
Re: How to, create a cleaning-knob (or scene)?!
Posted: Friday 26 January 2024 19:36
by Kedi
I don't think that Motion Sensors can be switched On or Off.
I would go for changing the motion lua scripts by adding a check if the 'Control' device is On of Off/
Re: How to, create a cleaning-knob (or scene)?!
Posted: Friday 26 January 2024 20:19
by BarryT
Okay guys, Thanks for answering so far!
But i just want to keep it simple as possible..
I know it is not that easy to do this in lua, same for blocky.
But, maybe i need to create dummy switches for every motion that i can turn off?
So when virtual switch is ON AND motion is ON, lamp ON.
Else if, virtual switch is OFF AND scène clean is ON lamp ON LEVEL 100
something like this?
Re: How to, create a cleaning-knob (or scene)?!
Posted: Friday 26 January 2024 20:19
by BarryT
Kedi wrote: βFriday 26 January 2024 19:36
I don't think that Motion Sensors can be switched On or Off.
I would go for changing the motion lua scripts by adding a check if the 'Control' device is On of Off/
How can i create a control device?
Re: How to, create a cleaning-knob (or scene)?!
Posted: Friday 26 January 2024 21:15
by waltervl
Make a dummy switch called 'vacuum cleaner active'.
And in your Lua script first check if the state of the switch is on. If the switch is on ignore the motion sensor status and switch your lights to 100%.
Re: How to, create a cleaning-knob (or scene)?!
Posted: Friday 26 January 2024 22:23
by BarryT
waltervl wrote: βFriday 26 January 2024 21:15
Make a dummy switch called 'vacuum cleaner active'.
And in your Lua script first check if the state of the switch is on. If the switch is on ignore the motion sensor status and switch your lights to 100%.
Thats exactly what i need, but how to 'ignore' the motion?

Re: How to, create a cleaning-knob (or scene)?!
Posted: Saturday 27 January 2024 8:24
by gizmocuz
And to make it more easier, create two Scenes
- All Lights On
- All lights Off
In those scenes place all lights, in the 'ON' scene set them to 100% white
In the Off scene, set them to off
As activator of the scene use the above dummy switch (or a real switch)
No need for scripting this
Maybe you can a wall switch that you can also double press, and use this action as activator for the scene?
Re: How to, create a cleaning-knob (or scene)?!
Posted: Saturday 27 January 2024 10:44
by Kedi
I had the same kind of problem when the window cleaner comes by and wants to clean all the windows.
So I created a Dummy switch that we can activate.
If activated (On) the current state of sunscreens and roller shutters are preserved.
Roller shutters and sunscreens are opened.
The state (On) of that switch is used in all my scripts concerning the sunscreens and roller shutters to prevent them from closing.
When the window cleaner is done, the Dummy switch is deactivated and every sunscreen and roller shutter is put back in the original state.
Next step
might be to trigger this Dummy switch by presence of the window cleaners phone.

Re: How to, create a cleaning-knob (or scene)?!
Posted: Saturday 27 January 2024 20:19
by BarryT
Thanks all, but i was hoping it was a bit easier but its not

After activating that scène, lamps full on, they goes on for 5 minutes and goes off because motion detected no motion after 5 minutes ago thats not going to work.
Even after activating the scene 'full on" and walk near the motion, it goes back to 50% because my script told it todo after motion.
So i guess my (motion) lua scripts needs to be more smart and to know that we need no motion because we want to have all lamps to be full on and stay full on..
Re: How to, create a cleaning-knob (or scene)?!
Posted: Saturday 27 January 2024 20:47
by Kedi
It is very easy. Put this at the beginning of every motion script.
Code: Select all
if domoticz.devices(<Dummy Switch>).state == "On" then
return
end
And create a script that switches "On" all the lights you want when the Dummy Switch is triggered and has state "On", and ofcourse "Off" when the state is "Off"
Re: How to, create a cleaning-knob (or scene)?!
Posted: Saturday 27 January 2024 21:37
by HvdW
Kedi wrote: βSaturday 27 January 2024 20:47
It is very easy.
There is no 'like' button on this website, so I 'like' your post in this way @Kedi.
Re: How to, create a cleaning-knob (or scene)?!
Posted: Saturday 27 January 2024 22:00
by Kedi
Off topic, but TNX
Re: How to, create a cleaning-knob (or scene)?!
Posted: Sunday 28 January 2024 15:23
by BarryT
Kedi wrote: βSaturday 27 January 2024 20:47
It is very easy. Put this at the beginning of every motion script.
Code: Select all
if domoticz.devices(<Dummy Switch>).state == "On" then
return
end
And create a script that switches "On" all the lights you want when the Dummy Switch is triggered and has state "On", and ofcourse "Off" when the state is "Off"
Sounds great to do, but this is not working at all..
Code: Select all
commandArray = {}
if domoticz.devices(DummyTestFull).state == "On" then print('This is an test...')
return
elseif (devicechanged['testmotion'] == 'On') then commandArray['testdimmer'] = 'Set Level 50'
elseif (devicechanged['testmotion'] == 'Off') then commandArray['testdimmer'] = 'Off'
end
return commandArray
does exactly nothing.
imo, this is working, but after motion detect the lamps goes back to 50% instead of staying on @100%:
Code: Select all
commandArray = {}
if (devicechanged['DummyTestFull'] == 'On') then
print('PoetsTest')
commandArray['testdimmer'] = 'Set Level 100'
return
--domoticz.devices(DummyTestFull).state == "On" then print('this is a test')
--return
elseif (devicechanged['testmotion'] == 'On') then commandArray['testdimmer'] = 'Set Level 50'
elseif (devicechanged['testmotion'] == 'Off') then commandArray['testdimmer'] = 'Off'
end
return commandArray
Re: How to, create a cleaning-knob (or scene)?!
Posted: Sunday 28 January 2024 15:50
by BarryT
So in simple words:
we have 19 (mqtt) motion sensors in our house, all of them are just switching on the lamp when its dark and when there is motion.
script:
Code: Select all
commandArray = {}
if (devicechanged['MotionHal'] == 'On') then commandArray['LampHal'] = 'Set Level 50'
elseif (devicechanged['MotionHal'] == 'Off') then commandArray['LampHal'] = 'Off'
end
return commandArray
this works perfect.
now i just want to have an override setting that turn on ALL lights to 100% and with color white and the motion detection OFF.
i believe it isnt that simple in domoticz?

Re: How to, create a cleaning-knob (or scene)?!
Posted: Sunday 28 January 2024 18:49
by BarryT
Well, nevermind.. I did some simple tricks in lua, i think i have it.
I have to do this for every lamp, but its better than none working script

I think this can be much easier, but for now its working.
Now i can change the brightness as well the color of the lamps, sometimes it can be simpler then i thought.
When "testpoets" is on, no motion needed, lamp is full bright 100% white, when "testpoets" is off, normal motion mode works again.
Thanks!
Code: Select all
commandArray = {}
if (devicechanged['testpoets'] == 'On') then
print('lampje was switched ON to 100% - cleaning mode!')
commandArray['OpenURL']='/json.htm?type=command¶m=setcolbrightnessvalue&idx=3376&hex=fffff&brightness=300&iswhite=false'
end
if otherdevices['testpoets'] == 'Off' and (devicechanged['testbeweging'] == 'On') then
commandArray['OpenURL']='/json.htm?type=command¶m=setcolbrightnessvalue&idx=3376&hex=D19126&brightness=300&iswhite=false'
print('lampje was switched ON to 50% - normal mode')
end
if otherdevices['testpoets'] == 'Off' and (devicechanged['testbeweging'] == 'Off') and otherdevices['testdimmer'] == 'On' then
commandArray['testdimmer']='Off'
print('lampje switched OFF')
end
return commandArray
Re: How to, create a cleaning-knob (or scene)?!
Posted: Sunday 28 January 2024 18:56
by Kedi
BarryT wrote: βSunday 28 January 2024 15:23
Kedi wrote: βSaturday 27 January 2024 20:47
It is very easy. Put this at the beginning of every motion script.
Code: Select all
if domoticz.devices(<Dummy Switch>).state == "On" then
return
end
And create a script that switches "On" all the lights you want when the Dummy Switch is triggered and has state "On", and ofcourse "Off" when the state is "Off"
Sounds great to do, but this is not working at all..
Code: Select all
commandArray = {}
if domoticz.devices(DummyTestFull).state == "On" then print('This is an test...')
return
elseif (devicechanged['testmotion'] == 'On') then commandArray['testdimmer'] = 'Set Level 50'
elseif (devicechanged['testmotion'] == 'Off') then commandArray['testdimmer'] = 'Off'
end
return commandArray
does exactly nothing.
My code presumed that your code was dzVents code.
In lua it is a little bit different. Perhaps try this. But I am not sure what device is what, but you know.
Code: Select all
commandArray = {}
if domoticz.devices("DummyTestFull").state == "Off" then
print('This is an test...')
if (devicechanged['testmotion'] == 'On') then
commandArray['testdimmer'] = 'Set Level 50'
else
commandArray['testdimmer'] = 'Off'
end
end
return commandArray
Re: How to, create a cleaning-knob (or scene)?!
Posted: Sunday 28 January 2024 19:28
by BarryT
Kedi wrote: βSunday 28 January 2024 18:56
BarryT wrote: βSunday 28 January 2024 15:23
Kedi wrote: βSaturday 27 January 2024 20:47
It is very easy. Put this at the beginning of every motion script.
Code: Select all
if domoticz.devices(<Dummy Switch>).state == "On" then
return
end
And create a script that switches "On" all the lights you want when the Dummy Switch is triggered and has state "On", and ofcourse "Off" when the state is "Off"
Sounds great to do, but this is not working at all..
Code: Select all
commandArray = {}
if domoticz.devices(DummyTestFull).state == "On" then print('This is an test...')
return
elseif (devicechanged['testmotion'] == 'On') then commandArray['testdimmer'] = 'Set Level 50'
elseif (devicechanged['testmotion'] == 'Off') then commandArray['testdimmer'] = 'Off'
end
return commandArray
does exactly nothing.
My code presumed that your code was dzVents code.
In lua it is a little bit different. Perhaps try this. But I am not sure what device is what, but you know.
Code: Select all
commandArray = {}
if domoticz.devices("DummyTestFull").state == "Off" then
print('This is an test...')
if (devicechanged['testmotion'] == 'On') then
commandArray['testdimmer'] = 'Set Level 50'
else
commandArray['testdimmer'] = 'Off'
end
end
return commandArray
Thanks man!
But i miss the full bright "knob" in this script.
The job in the script has to do 2 things:
normal mode = motion activated > lamp on to 50% dim with color: very warm white after motion detected, and lamp goes OFF after 3 minutes no motion.
cleaning mode = motion disabled > lamp has to STAY ON with 100% brightness and with color: cool white until we do clean-knob (poets) OFF and the function has to goo back to normal mode with motion detection enabled