Page 1 of 1

please help, simple light with motion detector

Posted: Wednesday 26 December 2018 8:16
by salopette
Hello, can someone please create simple script for light with motion detector.
I can not get it myself.

I have stairs with 6 lamps (on / off) and a motion detector (sends ON / OFF after 2min)

the button can be ignored

Thanks

Code: Select all

return {
active = true,
on = {
devices = {
'Zigbee Stick - BWM1',
'Zigbee Stick - Taster'
}
},
execute = function(domoticz, device)
    
local Taster = domoticz.devices('Zigbee Stick - Taster')    
local BWM = domoticz.devices('Zigbee Stick - BWM1')    

local lamp1 = domoticz.devices('Zigbee Stick-treppe1')
local lamp2 = domoticz.devices('Zigbee Stick-treppe2')
local lamp3 = domoticz.devices('Zigbee Stick-treppe3')
local lamp4 = domoticz.devices('Zigbee Stick-treppe4')
local lamp5 = domoticz.devices('Zigbee Stick-Flur OG1')
local lamp6 = domoticz.devices('Zigbee Stick-Flur OG2')

if (device.name == 'Zigbee Stick - BWM1' and device.state == 'On'
or device.name == 'Zigbee Stick - Taster' and device.state == 'Click') then

  if (lamp1.state == 'Off' or lamp2.state == 'Off' or lamp3.state == 'Off' or lamp4.state == 'Off' or lamp5.state == 'Off' or lamp6.state == 'Off') then
        lamp1.switchOn()
        lamp2.switchOn()
        lamp3.switchOn()
        lamp4.switchOn()
        lamp5.switchOn()
        lamp6.switchOn()
  else
        lamp1.switchOff()
        lamp2.switchOff()
        lamp3.switchOff()
        lamp4.switchOff()
        lamp5.switchOff()
        lamp6.switchOff()
    end
end
end
}

Re: please help, simple light with motion detector

Posted: Wednesday 26 December 2018 9:50
by havnegata
I was reading through the forum and came by this nice script by user @waaren. It's even got a check for lux-value:
http://www.domoticz.com/forum/viewtopic ... en#p200271

Re: please help, simple light with motion detector

Posted: Wednesday 26 December 2018 10:29
by salopette
Thanks, I will show it.
I'm new to DZVents, I've always used Blockly so far, but it's not supposed to be as good and flexible as DZvents.

Is there an easy way to learn dzvents?

Re: please help, simple light with motion detector

Posted: Wednesday 26 December 2018 11:03
by havnegata
The Wiki https://www.domoticz.com/wiki/DzVents:_ ... _scripting is always a good startingpoint for reference, but I haven't got any skills in programming, so my approach is to search the forum for similar problems and then I try to adopt to my needs.

Re: please help, simple light with motion detector

Posted: Wednesday 26 December 2018 13:09
by waaren
salopette wrote: Wednesday 26 December 2018 10:29 Thanks, I will show it.
I'm new to DZVents, I've always used Blockly so far, but it's not supposed to be as good and flexible as DZvents.

Is there an easy way to learn dzvents?
What about the video in this post

Re: please help, simple light with motion detector

Posted: Thursday 27 December 2018 20:07
by salopette
I got it now! Do not use timer or daytime

Code: Select all

return {
active = true,
on = {
devices = {
'Zigbee Stick - BWM1',
'Zigbee Stick - Taster'
}
},
execute = function(domoticz, device)
    
local Taster = 'Zigbee Stick - Taster'
local BWM = 'Zigbee Stick - BWM1'   

local lamp1 = domoticz.devices('Zigbee Stick-treppe1')
local lamp2 = domoticz.devices('Zigbee Stick-treppe2')
local lamp3 = domoticz.devices('Zigbee Stick-treppe3')
local lamp4 = domoticz.devices('Zigbee Stick-treppe4')
local lamp5 = domoticz.devices('Zigbee Stick-Flur OG1')
local lamp6 = domoticz.devices('Zigbee Stick-Flur OG2')

if (device.name == BWM and device.state == 'On'
    or device.name == Taster and device.state == 'Click') then

        lamp1.dimTo(5)
        lamp2.dimTo(5)
        lamp3.dimTo(5)
        lamp4.dimTo(20)
        lamp5.dimTo(30)
        lamp6.dimTo(30)
  else
        lamp1.switchOff()
        lamp2.switchOff()
        lamp3.switchOff()
        lamp4.switchOff()
        lamp5.switchOff()
        lamp6.switchOff()
    end
end
}