please help, simple light with motion detector

Moderator: leecollings

Post Reply
salopette
Posts: 187
Joined: Tuesday 07 March 2017 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Germany
Contact:

please help, simple light with motion detector

Post 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
}
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

Re: please help, simple light with motion detector

Post 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
salopette
Posts: 187
Joined: Tuesday 07 March 2017 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Germany
Contact:

Re: please help, simple light with motion detector

Post 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?
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

Re: please help, simple light with motion detector

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: please help, simple light with motion detector

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
salopette
Posts: 187
Joined: Tuesday 07 March 2017 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Germany
Contact:

Re: please help, simple light with motion detector

Post 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
}
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests