Re: Set Light to On based on motion detection between time
Posted: Wednesday 23 September 2020 9:28
Please test and share the log.
Open source Home Automation System
https://forum.domoticz.com/
Please test and share the log.
If I understand you correctly this is what should do that.Xavier82 wrote: Wednesday 23 September 2020 9:21 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.
The trigger of this script should be a switch (IDX 26) in Domoticz.
Code: Select all
return
{
on =
{
devices =
{
[26] = { '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
}Waaren,Xavier82 wrote: Wednesday 23 September 2020 9:43 Thanks again Waaren for this quick response.
Will test this and give feedback.
I have this when it's dark:waaren wrote: Wednesday 23 September 2020 9:04Like this?Melotron wrote: Wednesday 23 September 2020 6:51 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.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 }
Code: Select all
if (domoticz.devices(145).lux >= 0) and (domoticz.devices(145).lux <= 850) then
if domoticz.devices(147).state == "On" and -- iDetect - Anyone
domoticz.devices(3).state == "Off" and -- Virt_SLEEP
domoticz.devices(4).state == "Off" and -- Virt_TV
domoticz.devices(5).state == "Off" then -- Virt_Manuell
domoticz.devices(25).dimTo(60) -- Storarum: Golv
domoticz.devices(26).dimTo(60) -- Storarum: Tak
domoticz.devices(45).dimTo(40) -- Storarum: LED
domoticz.devices(101).dimTo(100) -- Storarum: Hue 1
domoticz.devices(102).dimTo(100) -- Storarum: Hue 2
domoticz.devices(101).setKelvin(45) -- Storarum: Hue 1
domoticz.devices(102).setKelvin(45) -- Storarum: Hue 2
domoticz.devices(93).dimTo(50) -- Storarum: Gardin LED
end end Please share both complete scripts. What happens and when might be clear for you as creator of the scripts but it is not for me.Melotron wrote: Wednesday 23 September 2020 10:50 I have this when it's dark:
And a similar script with .setKelvin(75) that's starting at 19:00 to 09:00. It's working quite ok with two scripts for it.
But it's two scripts for each environment script for each room.
And a bit of hassle when I need to update the script.
But I would love to find a way to have it in one script.
No that is not the right syntaxis.Melotron wrote: Wednesday 23 September 2020 11:26 Or would this work?
local Kelvin ['at 18:01-07:00'] = 75, ['at 07:01-18:00'] = 45
domoticz.devices(101).setKelvin(Kelvin)
Code: Select all
local Kelvin = domoticz.time.matchesRule('at 18:01-07:00') and 75 or 45 -- 75 during nighttime and 45 during day
domoticz.devices(101).setKelvin(Kelvin)
Thanks alot.waaren wrote: Wednesday 23 September 2020 11:54No that is not the right syntaxis.Melotron wrote: Wednesday 23 September 2020 11:26 Or would this work?
local Kelvin ['at 18:01-07:00'] = 75, ['at 07:01-18:00'] = 45
domoticz.devices(101).setKelvin(Kelvin)
use something likeand please have a look at the dzVents wiki. It is there to help youCode: Select all
local Kelvin = domoticz.time.matchesRule('at 18:01-07:00') and 75 or 45 -- 75 during nighttime and 45 during day domoticz.devices(101).setKelvin(Kelvin)
dzVents is Lua. A good start to understand the Lua syntax can be found here and hereMelotron wrote: Wednesday 23 September 2020 17:39 I've been looking there and its been a good help for me, but a few things like this with local and a few other things are hardly mentioned there.