Page 2 of 2

Re: Set Light to On based on motion detection between time

Posted: Wednesday 23 September 2020 9:28
by waaren
Xavier82 wrote: Wednesday 23 September 2020 9:12 Tested the enhancement but no result.
Please test and share the log.

Re: Set Light to On based on motion detection between time

Posted: Wednesday 23 September 2020 9:31
by waaren
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.
If I understand you correctly this is what should do that.

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
}

Re: Set Light to On based on motion detection between time

Posted: Wednesday 23 September 2020 9:43
by Xavier82
Thanks again Waaren for this quick response.
Will test this and give feedback.

Re: Set Light to On based on motion detection between time  [Solved]

Posted: Wednesday 23 September 2020 10:02
by Xavier82
Xavier82 wrote: Wednesday 23 September 2020 9:43 Thanks again Waaren for this quick response.
Will test this and give feedback.
Waaren,

Tested it, and works fine, thanks!

Re: Set Light to On based on motion detection between time

Posted: Wednesday 23 September 2020 10:50
by Melotron
waaren wrote: Wednesday 23 September 2020 9:04
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.
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
}
I have this when it's dark:

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  
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.

Re: Set Light to On based on motion detection between time

Posted: Wednesday 23 September 2020 11:16
by waaren
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.
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.

Re: Set Light to On based on motion detection between time

Posted: Wednesday 23 September 2020 11:26
by Melotron
Or would this work?

local Kelvin ['at 18:01-07:00'] = 75, ['at 07:01-18:00'] = 45

domoticz.devices(101).setKelvin(Kelvin)

Re: Set Light to On based on motion detection between time

Posted: Wednesday 23 September 2020 11:54
by waaren
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)
No that is not the right syntaxis.

use something like

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)
and please have a look at the dzVents wiki. It is there to help you

Re: Set Light to On based on motion detection between time

Posted: Wednesday 23 September 2020 17:39
by Melotron
waaren wrote: Wednesday 23 September 2020 11:54
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)
No that is not the right syntaxis.

use something like

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)
and please have a look at the dzVents wiki. It is there to help you
Thanks alot.
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.
I've also been looking for a good kelvin scale to convert 3000 and 7000, I have found by trial and error that 75 are almost 3000 and 45 are fairly close to 7000 lol

Re: Set Light to On based on motion detection between time

Posted: Wednesday 23 September 2020 17:52
by waaren
Melotron 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.
dzVents is Lua. A good start to understand the Lua syntax can be found here and here

If you found something that is dzVents and not in the wiki then please feel free to propose a new or better text. I'm more then happy to improve the wiki where needed.