Set Light to On based on motion detection between time [Solved]
Moderator: leecollings
-
- Posts: 178
- Joined: Tuesday 07 June 2016 22:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Netherlands
- Contact:
Set Light to On based on motion detection between time
Hi all,
I searched the forum but couldn't find what I was looking for....
Could any one help me with a dzvents script to activate the light on our frontdoor when the camera with motion detection has detected motion between 00.00 hours and sunrise?
I have the next setup:
Camera connected to Domoticz but also to Synology Surveillance Station.
In Surveillance station I have setup an action rule based on url to Domoticz to IDX of Camera.
The action rule in Surveillance Station is triggered by motion of the camera.
But now I'm stuck...
So what should the script do?
It would be great of the light goes on when motion is detected between 00:00 hours and sunrise.
I hope somebody can help me with this.
Thanks in advance
Regards,
Xavier
I searched the forum but couldn't find what I was looking for....
Could any one help me with a dzvents script to activate the light on our frontdoor when the camera with motion detection has detected motion between 00.00 hours and sunrise?
I have the next setup:
Camera connected to Domoticz but also to Synology Surveillance Station.
In Surveillance station I have setup an action rule based on url to Domoticz to IDX of Camera.
The action rule in Surveillance Station is triggered by motion of the camera.
But now I'm stuck...
So what should the script do?
It would be great of the light goes on when motion is detected between 00:00 hours and sunrise.
I hope somebody can help me with this.
Thanks in advance
Regards,
Xavier
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
How does this call to domoticz looks like and what is it supposed to do?
Is the domoticz version number in your profile correct and if so is there a reason why you have not upgraded to a more recent stable release?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 178
- Joined: Tuesday 07 June 2016 22:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
Hi Waaren,
updated my profile.
Version is 2020.2 stable.
The call from Surveillance station is an action based on a URL wich triggers the IDX of a switch in domoticz namen " Camera Motion Detection".
Normally this has as an action that when motion is detected I receive a notificaties in telegram with a snapshot of the camera.
updated my profile.
Version is 2020.2 stable.
The call from Surveillance station is an action based on a URL wich triggers the IDX of a switch in domoticz namen " Camera Motion Detection".
Normally this has as an action that when motion is detected I receive a notificaties in telegram with a snapshot of the camera.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
Can you try with this dzVents script?Xavier82 wrote: ↑Monday 21 September 2020 19:40 Hi Waaren,
updated my profile.
Version is 2020.2 stable.
The call from Surveillance station is an action based on a URL wich triggers the IDX of a switch in domoticz namen " Camera Motion Detection".
Normally this has as an action that when motion is detected I receive a notificaties in telegram with a snapshot of the camera.
Code: Select all
return
{
on =
{
devices =
{
['Camera Motion Detection'] = { 'between 00:00 and sunrise' },
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Camera',
},
execute = function(dz, item)
local light = dz.devices('Name of your light')
local offDelay = 300
if item.active then -- state == 'On'
light.cancelQueuedCommands()
light.switchOn()
light.switchOff().afterSec(offDelay)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 178
- Joined: Tuesday 07 June 2016 22:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
Thanks for the code but I get this error:
2020-09-21 23:25:09.101 Error: dzVents: Error: (3.0.2) error loading module 'Voordeur verlichting' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Voordeur verlichting.lua':
2020-09-21 23:25:09.101 ...ripts/dzVents/generated_scripts/Voordeur verlichting.lua:11: <eof> expected near '='
2020-09-21 23:25:09.101 Error: dzVents: Error: (3.0.2) error loading module 'Voordeur verlichting' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Voordeur verlichting.lua':
2020-09-21 23:25:09.101 ...ripts/dzVents/generated_scripts/Voordeur verlichting.lua:11: <eof> expected near '='
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
There was an error in the script which is now corrected please try again but note that the script in its current form will only work after 00:00Xavier82 wrote: ↑Monday 21 September 2020 23:26 Thanks for the code but I get this error:
2020-09-21 23:25:09.101 Error: dzVents: Error: (3.0.2) error loading module 'Voordeur verlichting' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Voordeur verlichting.lua':
2020-09-21 23:25:09.101 ...ripts/dzVents/generated_scripts/Voordeur verlichting.lua:11: <eof> expected near '='
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 178
- Joined: Tuesday 07 June 2016 22:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
Thanks, error is gone for now.waaren wrote: ↑Monday 21 September 2020 23:32There was an error in the script which is now corrected please try again but note that the script in its current form will only work after 00:00Xavier82 wrote: ↑Monday 21 September 2020 23:26 Thanks for the code but I get this error:
2020-09-21 23:25:09.101 Error: dzVents: Error: (3.0.2) error loading module 'Voordeur verlichting' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/Voordeur verlichting.lua':
2020-09-21 23:25:09.101 ...ripts/dzVents/generated_scripts/Voordeur verlichting.lua:11: <eof> expected near '='
Will keep an eye on it

-
- Posts: 178
- Joined: Tuesday 07 June 2016 22:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
So I checked the logging this morning, but the light didn't go on. I had several motion detections (a cat walked by). I receive a notificaties in telegram on my Phone but it looks like the script hasn' t been triggered.
I have adjusted the name of the lamp in the script.
Any idea why not?
I have adjusted the name of the lamp in the script.
Any idea why not?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
Can you share the exact URL that activates the device with the telegram action?Xavier82 wrote:
Any idea why not?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 178
- Joined: Tuesday 07 June 2016 22:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
Sure, the URL in Synology Surveillance Station which is triggered on motion is:
http://<IP_ADRES_Domoticz>:<port domoticz>/json.htm?type=command¶m=switchlight&idx=26&switchcmd=On
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
Please try again after changing cancelQueuedCommand to cancelQueuedCommands
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 178
- Joined: Tuesday 07 June 2016 22:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
Waaren,
I made the adjustment.
Will keep you posted about this.
Greetz,
Xavier
I made the adjustment.
Will keep you posted about this.
Greetz,
Xavier
-
- Posts: 62
- Joined: Tuesday 22 November 2016 21:04
- Target OS: Linux
- Domoticz version: 2020.2
- Location: Gothenburg
- Contact:
Re: Set Light to On based on motion detection between time
Hi.
I've been trying to get a similar script running for myself for a few motion sensors.
I'am getting the following error :
The script that I'am using are this:
It would be wonderful to get a scrip like this working even for setting a warmer kelvin on the lamps after sunset too =)
//Magnus Svensson
I've been trying to get a similar script running for myself for a few motion sensors.
I'am getting the following error :
Code: Select all
2020-09-22 18:52:11.225 ...ticz/scripts/dzVents/generated_scripts/dz timer test.lua:4: '}' expected near '='
Code: Select all
return
{
on =
{ devices = { 118 = { 'between sunset and sunrise' }, }, },
execute = function(domoticz)
local myTextDevice = 82
if domoticz.devices(118).state == 'On' then
myTextDevice.updateText('Motion')
domoticz.devices(42).switchOn()
domoticz.devices(42).switchOff().afterSec(40)
end
end }
//Magnus Svensson
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
Syntax to use isMelotron wrote: ↑Tuesday 22 September 2020 19:05 Hi.
I've been trying to get a similar script running for myself for a few motion sensors.
I'am getting the following error :Code: Select all
2020-09-22 18:52:11.225 ...ticz/scripts/dzVents/generated_scripts/dz timer test.lua:4: '}' expected near '='
Code: Select all
return
{
on =
{
devices =
{
[118] = { 'between sunset and sunrise' },
},
},
execute = function(domoticz)
local myTextDevice = 82
if domoticz.devices(118).state == 'On' then
myTextDevice.updateText('Motion')
domoticz.devices(42).switchOn()
domoticz.devices(42).switchOff().afterSec(40)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 62
- Joined: Tuesday 22 November 2016 21:04
- Target OS: Linux
- Domoticz version: 2020.2
- Location: Gothenburg
- Contact:
Re: Set Light to On based on motion detection between time
Thanks alot =)waaren wrote: ↑Tuesday 22 September 2020 21:10Syntax to use isMelotron wrote: ↑Tuesday 22 September 2020 19:05 Hi.
I've been trying to get a similar script running for myself for a few motion sensors.
I'am getting the following error :Code: Select all
2020-09-22 18:52:11.225 ...ticz/scripts/dzVents/generated_scripts/dz timer test.lua:4: '}' expected near '='
Code: Select all
return { on = { devices = { [118] = { 'between sunset and sunrise' }, }, }, execute = function(domoticz) local myTextDevice = 82 if domoticz.devices(118).state == 'On' then myTextDevice.updateText('Motion') domoticz.devices(42).switchOn() domoticz.devices(42).switchOff().afterSec(40) end end }
Its finally working.
Are there any way to put the time at the devices like :
domoticz.devices(42).switchOn().at(between sunset and sunrise)
//Magnus Svensson
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
Sorry but I don't understand what you try to achieve. switchOn() can be delayed until a moment in future but not between aaa and bbb.
Can you please explain ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 62
- Joined: Tuesday 22 November 2016 21:04
- Target OS: Linux
- Domoticz version: 2020.2
- Location: Gothenburg
- Contact:
Re: Set Light to On based on motion detection between time
I want to have a low Kelvin during daytime and a higher Kelvin after the sun goes down.
I can achieve that with 2 scripts, but I could shrink my scripts down by setting times when a specific lamp should be on in a script.
I can achieve that with 2 scripts, but I could shrink my scripts down by setting times when a specific lamp should be on in a script.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
Like this?
Code: Select all
return
{
on =
{
timer =
{
'at sunset',
'at sunrise',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when tested and OK
marker = 'lights at night',
},
execute = function(dz)
local light = dz.devices(42)
if dz.time.matchesRule('at sunrise') then
light.switchOff()
else
light.switchOn()
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 178
- Joined: Tuesday 07 June 2016 22:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
Waaren,
Tested the enhancement but no result.
For testing now I made a second actionrule in Synology Surveillance Station which is:
http://<IP_ADRES_Domoticz>:<port domoticz>/json.htm?type=command¶m=switchlight&idx=186&switchcmd=On
IDX 186 is the IDX of my frontdoor light which I want to activate.
When testing the light goes on indeed, but how can I be sure the light only goes on between the entered time and goes off after 300seconds?
This is the code for now:
Tested the enhancement but no result.
For testing now I made a second actionrule in Synology Surveillance Station which is:
http://<IP_ADRES_Domoticz>:<port domoticz>/json.htm?type=command¶m=switchlight&idx=186&switchcmd=On
IDX 186 is the IDX of my frontdoor light which I want to activate.
When testing the light goes on indeed, but how can I be sure the light only goes on between the entered time and goes off after 300seconds?
This is the code for now:
Code: Select all
return
{
on =
{
devices =
{
['Voordeurlamp'] = { 'between 00:00 and sunrise' },
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Camera',
},
execute = function(dz, item)
local light = dz.devices('Voordeurlamp')
local offDelay = 300
if item.active then -- state == 'On'
light.cancelQueuedCommands()
light.switchOn()
light.switchOff().afterSec(offDelay)
end
end
}
-
- Posts: 178
- Joined: Tuesday 07 June 2016 22:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Netherlands
- Contact:
Re: Set Light to On based on motion detection between time
mmmzzz, when rethinking about this....
What actually should happen is that the lamp on the frontdoor goes on WHEN "Camera motion dection" between 00:00 and sunrise FOR 5 minutes.
In other words I would like to re-use already existing scripts in Surveillance Station and Domoticz.
The trigger of this script should be a switch (IDX 26) in Domoticz.
Can this be done?
What actually should happen is that the lamp on the frontdoor goes on WHEN "Camera motion dection" between 00:00 and sunrise FOR 5 minutes.
In other words I would like to re-use already existing scripts in Surveillance Station and Domoticz.
The trigger of this script should be a switch (IDX 26) in Domoticz.
Can this be done?
Who is online
Users browsing this forum: No registered users and 1 guest