DZ Vents Light timer Help Please  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Tamil112
Posts: 10
Joined: Friday 15 November 2019 14:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DZ Vents Light timer Help Please

Post by Tamil112 »

Script works,, but after motion is off and motion sensor is triggerd it goes back to the same level as started

i would like it be the same as chosen manually even after a motion trigger


waaren wrote: Sunday 02 February 2020 2:15
Tamil112 wrote: Saturday 01 February 2020 20:44 So when it turns on with motion and lux and when a user decide to dim or brighter manually that the level last used level stays on after there is movement with the pir
OK. If I understand correctly what you need... Below should do it. (but untested)

Code: Select all

local PIR = 'PIR'       -- change to name of your PIR
local light = 'light'   -- change to name of your light
local lux = 'lux'   -- change to name of your lux device

return  
{
    on =
    { 
        devices = 
        { 
            PIR,
            light,
        },
    },

    logging =
    {   
        level = domoticz.LOG_DEBUG,
        marker = 'memorize state', 
    },
    
    data = 
    { 
        lastLevel = { initial = 0 },
    },
    
    execute = function(dz, item)

        local PIR = dz.devices(PIR)
        local light = dz.devices(light)
        local lux = dz.devices(lux).lux
        
        if item == light then 
            if light.active then 
                dz.data.lastLevel = light.level 
            else
                dz.data.lastLevel = 'Off'
            end
            return
        end
        
        if item.active then
            if lux < 30 then 
                light.setLevel(99).silent() 
            end
        elseif tostring(dz.data.lastLevel) == 'Off' then
            light.cancelQueuedCommands()
            light.switchOff().afterSec(300).checkFirst().silent() 
        else
            light.cancelQueuedCommands()
            light.setLevel(dz.data.lastLevel).afterSec(300).silent() 
        end
    end
}
Tamil112
Posts: 10
Joined: Friday 15 November 2019 14:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DZ Vents Light timer Help Please

Post by Tamil112 »

Okay I have tested it.. It works but when motion is trigger after it was off I goes back to the normal dimlevel.. What I want is when the light is on that the script does not change after a new motion..

Motion is on = light dimlevel 60 on lux level
Motion is on = and light is dimlevel and changed manually stay
When motion is off = switch off after x seconds
When motion is on after off = light is on then don't change dimlevel that was changed manually keep dimlevel

Motion is off = and light is switchoff after x seconds
And motion is triggered on set dimlevel 60 on lux level
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by waaren »

Tamil112 wrote: Sunday 02 February 2020 19:52 Okay I have tested it.. It works but when motion is trigger after it was off I goes back to the normal dimlevel.. What I want is when the light is on that the script does not change after a new motion..
The testScript I posted should be sufficient to give you a start to try and implement the logic you require. If you tried and run into some code related problems I am happy to assist.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by madpatrick »

I'm trying to rebuild the example script, but still to difficult for me.
May some tip and tricks can support me

This is what i've tried

Code: Select all

local PIR = 'Motion Sensor Burglar'                 -- change to name of your PIR
local light = 'Wnk - Studeerkamer'                  -- change to name of your light
local lux = 'Motion Sensor - Lux'                   -- change to name of your lux device
local sunset  = timeofday['SunsetInMinutes']-30     -- time = sunset time - 30 minutes
local sunrise  = timeofday['SunriseInMinutes']+30   -- time = sunset time + 30 minutes
local Time = require('Time')                        -- current time
local timediff = zononder - Time                    -- time sunset - current time = 0 to trigger switch
local Sleep = '23:15'                               -- after sleep time switch off lamps unless PIR movement and LUX value < xx

return  
{
    on =
    { 
        devices = 
        { 
            PIR,
            light,
        },
    },

    logging =
    {   
        level = domoticz.LOG_DEBUG,
        marker = 'memorize state', 
    },
    
    data = 
    { 
        lastLevel = { initial = 0 },
    },
    
    execute = function(dz, item)

        local PIR = dz.devices(PIR)
        local light = dz.devices(light)
        local lux = dz.devices(lux).lux
        
        if item == light then 
            if light.active then 
                dz.data.lastLevel = light.level 
            else
                dz.data.lastLevel = 'Off'
            end
            return
        end
        
        if item.active then
            if lux < 100 and timediff = 0 then 
                light.switchOn().silent() 
            end
        elseif tostring(dz.data.lastLevel) == 'Off' then
            light.cancelQueuedCommands()
            light.switchOff().afterSec(300).checkFirst().silent() 
        else
            light.cancelQueuedCommands()
            light.switchoff().afterSec(300).silent() 
        end
    end
}  
The lights must switch on : 'SUNSET" with min LUX
The lights must switch off : after 'SLEEP' with no movement for 5 min

My idea was to calculate the difference in time of SUNSET and SLEEP. When this is 0 this can be used as a trigger.
Unfortunately it gives an error
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by waaren »

madpatrick wrote: Saturday 17 October 2020 16:28 I'm trying to rebuild the example script, but still to difficult for me.
May some tip and tricks can support me

The lights must switch on : 'SUNSET" with min LUX
The lights must switch off : after 'SLEEP' with no movement for 5 min

My idea was to calculate the difference in time of SUNSET and SLEEP. When this is 0 this can be used as a trigger.
Unfortunately it gives an error
No need to do the time calculations yourself. The complicated stuff is all done by dzVents internally...

Can you try this

Code: Select all

local PIR = 'Motion Sensor Burglar'                 -- change to name of your PIR
local light = 'Wnk - Studeerkamer'                  -- change to name of your light
local lux = 'Motion Sensor - Lux'                   -- change to name of your lux device
local Sleep = '23:15'                               -- after sleep time switch off lamps unless PIR movement and LUX value < xx
local retrigger = 'Retrigger using customEvent'

return
{
    on =
    {
        timer =
        {
            'at sunset',
            'at ' .. Sleep,
        },
        customEvents =
        {
            retrigger,
        }
    },


    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'light control',
    },

    execute = function(dz)

        local PIR = dz.devices(PIR)
        local light = dz.devices(light)
        local lux = dz.devices(lux).lux

        if dz.time.matchesRule('between sunset and '.. Sleep) then
            if lux < 100 then
                light.switchOn().checkFirst()
            else
                dz.emitEvent(retrigger).afterSec(300) -- try again in 5 min.
            end
        else
            if PIR.lastUpdate.secondsAgo > 300 then
                light.switchOff().checkFirst()
            else
                dz.emitEvent(retrigger).afterSec(300)
            end
        end

 end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by madpatrick »

Hi Waaren

Thanks again for your support

It looksl ike the lamps will not go off after sleep or PIR delay
I've set the time of sleep at an earlier time to let it trigger and the last PIR update was a few hours ago (according to the log)
(when we not at home the light must switch off automaticly, but stay on when are still in the room)

Unfortunately i don't understand the script to much the find it out my self. :(
Not sure how to enable the logging for you. I've set logging in Domoticz on Debug.
This is the only output:

Code: Select all

2020-10-17 22:05:00.316  Status: dzVents: Info: light control: ------ Start internal script: PIR Woonkamer:, trigger: "at 22:05"
2020-10-17 22:05:00.316  Status: dzVents: Debug: light control: Constructed timed-command: On
2020-10-17 22:05:00.316  Status: dzVents: Info: light control: ------ Finished PIR Woonkamer

Also i like to trigger the sunset earlier, so i changed it with 'minutesBeforeSunset ' to this

Code: Select all

local PIR       = 'Motion Sensor Burglar'               -- change to name of your PIR
local light     = 'Wnk - Studeerkamer'                  -- change to name of your light
local lux       = 'Motion Sensor - Lux'                 -- change to name of your lux device
local Sleep     = '22:05'                               -- after sleep time switch off lamps unless PIR movement and LUX value < xx
local retrigger = 'Retrigger using customEvent'
local minutesBeforeSunset = 20                          -- 20 min before sunset

return
{
    on =
    {
        timer =
        {
            'at sunset',
            'at ' .. Sleep,
        },
        customEvents =
        {
            retrigger,
        }
    },


    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'light control',
    },

    execute = function(dz)

        local PIR = dz.devices(PIR)
        local light = dz.devices(light)
        local lux = dz.devices(lux).lux

        if dz.time.matchesRule('between minutesBeforeSunset and '.. Sleep) then
            if lux < 100 then
                light.switchOn().checkFirst()
            else
                dz.emitEvent(retrigger).afterSec(300) -- try again in 5 min.
            end
        else
            if PIR.lastUpdate.secondsAgo > 300 then
                light.switchOff().checkFirst()
            else
                dz.emitEvent(retrigger).afterSec(300)
            end
        end

 end
}
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by waaren »

madpatrick wrote: Saturday 17 October 2020 22:24 I've set the time of sleep at an earlier time to let it trigger and the last PIR update was a few hours ago (according to the log)
(when we not at home the light must switch off automaticly, but stay on when are still in the room)

Unfortunately i don't understand the script to much the find it out my self. :(
Not sure how to enable the logging for you. I've set logging in Domoticz on Debug.
If you don't understand parts of the script then please try to search the wiki and if you still have questions after that feel free to ask here.
You don't have to set the logging in Domoticz to debug. I added some extra lines in the script to show what is going on.
Also i like to trigger the sunset earlier, so i changed it with 'minutesBeforeSunset ' to this

Code: Select all

dz.time.matchesRule('between minutesBeforeSunset and '.. Sleep) then
This will not work. See below script for the correct way of doing this

Code: Select all

local PIR       = 'Motion Sensor Burglar'               -- change to name of your PIR
local light     = 'Wnk - Studeerkamer'                  -- change to name of your light
local lux       = 'Motion Sensor - Lux'                 -- change to name of your lux device
local Sleep     = '22:05'                               -- after sleep time switch off lamps unless PIR movement and LUX value < xx
local retrigger = 'Retrigger using customEvent'
local minutesBeforeSunset = 20                          -- 20 min before sunset

return
{
    on =
    {
        timer =
        {
            'at sunset',
            'at ' .. Sleep,
        },
        customEvents =
        {
            retrigger,
        }
    },


    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'light control',
    },

    execute = function(dz)

        local PIR = dz.devices(PIR)
        local light = dz.devices(light)
        local lux = dz.devices(lux).lux

        dz.log(lux.name .. ' lux = ' .. lux,dz.LOG_DEBUG)
        dz.log(PIR.name .. ' was last updated ' .. PIR.lastUpdate.secondsAgo .. ' seconds ago',dz.LOG_DEBUG)
        dz.log(light.name .. ' state is ' .. light.state ,dz.LOG_DEBUG)
        
        -- the text between quotes and the variables  minutesBeforeSunset (20) and Sleep (22:05) will be concatenated to 
        --                             between 20 minutes before sunset and 22:05
        if dz.time.matchesRule('between ' .. minutesBeforeSunset .. ' minutes before sunset and ' .. Sleep) then 
            if lux < 100 then
                light.switchOn().checkFirst()
                dz.log(light.name .. ' switched On or already On',dz.LOG_DEBUG)
            else
                dz.emitEvent(retrigger).afterSec(300) -- try again in 5 min.
                dz.log('Script will start again in 5 minutes',dz.LOG_DEBUG)
            end
        else
            if PIR.lastUpdate.secondsAgo > 300 then
                light.switchOff().checkFirst()
                dz.log(light.name .. ' switched Off or already Off',dz.LOG_DEBUG)
            else
                dz.emitEvent(retrigger).afterSec(300)
                dz.log('Script will start again in 5 minutes',dz.LOG_DEBUG)
            end
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by madpatrick »

Waaren,

Should the timer event also be changed

Code: Select all

        timer =
        {
            'at sunset',
            'at ' .. Sleep,
        },
in to

Code: Select all

  timer =
        {
            'at '.. minutesBeforeSunset,
            'at ' .. Sleep,
        },


I''ve change the timmer to a fixed time test to the script, but i get an error

Code: Select all

dzVents: Error: (3.0.2) light control: ...ticz/scripts/dzVents/generated_scripts/PIR Woonkamer.lua:37: attempt to concatenate a table value (local 'lux')
dzVents: Error: (3.0.2) light control: ...ticz/scripts/dzVents/generated_scripts/PIR Woonkamer.lua:38: attempt to index a nil value (field 'lastUpdated')
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by waaren »

madpatrick wrote: Sunday 18 October 2020 9:23 Should the timer event also be changed
No. If you do that you will get 'at 20' and that does not work. If you want it to trigger on 20 minutes before sunset you should make it something like

Code: Select all

minutesBeforeSunset .. ' minutes before sunset' -- This will be concatenated to 20 minutes before sunset (see the wiki !)
I''ve change the timmer to a fixed time test to the script, but i get an error
You probably left out the first lines of the script (before the first return)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by madpatrick »

waaren wrote: Sunday 18 October 2020 12:54
No. If you do that you will get 'at 20' and that does not work. If you want it to trigger on 20 minutes before sunset you should make it something like

Code: Select all

minutesBeforeSunset .. ' minutes before sunset' -- This will be concatenated to 20 minutes before sunset (see the wiki !)
Now I understand the timer better on the Wiki.
I think i need to add " 'at .." before minutesBeforeSunset ?

Code: Select all

'at'  .. minutesBeforeSunset .. ' minutes before sunset', -- This will be concatenated to 20 minutes before sunset
You probably left out the first lines of the script (before the first return)
No. All local are mentioned before 'return' as you posted
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by waaren »

madpatrick wrote: Sunday 18 October 2020 14:33 No. All local are mentioned before return as you posted
OK. Below script will help debugging. Please let it run once and collect the loglines.

Code: Select all

local PIR       = 'Motion Sensor Burglar'               -- change to name of your PIR
local light     = 'Wnk - Studeerkamer'                  -- change to name of your light
local lux       = 'Motion Sensor - Lux'                 -- change to name of your lux device
local Sleep     = '22:05'                               -- after sleep time switch off lamps unless PIR movement and LUX value < xx
local retrigger = 'Retrigger using customEvent'
local minutesBeforeSunset = 20                          -- 20 min before sunset

return
{
    on =
    {
        timer =
        {
            'at sunset',
            'at ' .. Sleep,
            'every minute', -- only for testing
            
        },
        customEvents =
        {
            retrigger,
        }
    },


    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'light control',
    },

    execute = function(dz)
	
	    allDevices = {}
		dz.devices().forEach(function(dv)
			allDevices[#allDevices + 1] = dv.name .. ' type:' .. dv.deviceType .. ', subType: ' .. dv.deviceSubType
		end)
	
	    dz.utils.dumpTable(allDevices)
	    
	    dz.log(PIR,dz.LOG_FORCE)	
        dz.log(light,dz.LOG_FORCE)	
        dz.log(lux,dz.LOG_FORCE)	

        local PIR = dz.devices(PIR)
        local light = dz.devices(light)
        local lux = dz.devices(lux).lux


		
		
        dz.log(lux.name .. ' lux = ' .. lux,dz.LOG_DEBUG)
        dz.log(PIR.name .. ' was last updated ' .. PIR.lastUpdate.secondsAgo .. ' seconds ago',dz.LOG_DEBUG)
        dz.log(light.name .. ' state is ' .. light.state ,dz.LOG_DEBUG)
        
        -- the text between quotes and the variables  minutesBeforeSunset (20) and Sleep (22:05) will be concatenated to 
        --                             between 20 minutes before sunset and 22:05
        if dz.time.matchesRule('between ' .. minutesBeforeSunset .. ' minutes before sunset and ' .. Sleep) then 
            if lux < 100 then
                light.switchOn().checkFirst()
                dz.log(light.name .. ' switched On or already On',dz.LOG_DEBUG)
            else
                dz.emitEvent(retrigger).afterSec(300) -- try again in 5 min.
                dz.log('Script will start again in 5 minutes',dz.LOG_DEBUG)
            end
        else
            if PIR.lastUpdate.secondsAgo > 300 then
                light.switchOff().checkFirst()
                dz.log(light.name .. ' switched Off or already Off',dz.LOG_DEBUG)
            else
                dz.emitEvent(retrigger).afterSec(300)
                dz.log('Script will start again in 5 minutes',dz.LOG_DEBUG)
            end
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by madpatrick »

I'm getting this error which i can figure out

Code: Select all

2020-10-18 15:48:33.470 Error: dzVents: Error: (3.0.2) error loading module 'Test_Script' from file '/var/domoticz/scripts/dzVents/generated_scripts/Test_Script.lua':
2020-10-18 15:48:33.470 ...moticz/scripts/dzVents/generated_scripts/Test_Script.lua:36: unexpected symbol near ')'

Code: Select all

        dz.devices().forEach(function(dv))
            dz.log(dv.name .. ' type:' .. dv.deviceType .. ', subType: ' .. dv.deviceSubType, dz.LOG_FORCE )
        end)
Tried to remove ) at line 38 after 'end', but no luck

-------- edit ----------
removed ) after 'function(dv))'
No error in log now with start of the script

When the script is triggered it give this errror

Code: Select all

2020-10-18 16:00:00.317 Error: dzVents: Error: (3.0.2) light control: An error occurred when calling event handler Test_Script
2020-10-18 16:00:00.317 Error: dzVents: Error: (3.0.2) light control: ...moticz/scripts/dzVents/generated_scripts/Test_Script.lua:37: attempt to concatenate a nil value (field 'deviceSubType')
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by waaren »

madpatrick wrote: Sunday 18 October 2020 15:50
Tried to remove ) at line 38 after 'end', but no luck
Can you try again. I corrected the error :oops: at line 36 and reposted the script.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by madpatrick »

Looks better

Code: Select all

2020-10-18 17:39:00.182 Status: dzVents: Info: light control: ------ Start internal script: Test_Script:, trigger: "at 17:39"
2020-10-18 17:39:00.182 Status: dzVents: > 1: Memory Usage type:General, subType: Percentage
2020-10-18 17:39:00.182 Status: dzVents: > 2: HDD / type:General, subType: Percentage
2020-10-18 17:39:00.182 Status: dzVents: > 3: HDD /boot type:General, subType: Percentage
2020-10-18 17:39:00.182 Status: dzVents: > 4: HDD /var/flexshare/shares type:General, subType: Percentage
2020-10-18 17:39:00.182 Status: dzVents: > 5: CPU_Usage type:General, subType: Percentage
2020-10-18 17:39:00.182 Status: dzVents: > 6: Fibaro stekker type:Light/Switch, subType: Switch
2020-10-18 17:39:00.182 Status: dzVents: > 7: Fibaro stekker [W] type:Usage, subType: Electric
2020-10-18 17:39:00.182 Status: dzVents: > 8: Wnk - Keukenzijde type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 9: Wnk - Keukenzijde [W] type:Usage, subType: Electric
2020-10-18 17:39:00.183 Status: dzVents: > 10: Wnk - Tuinzijde type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 11: Wnk - Tuinzijde [W] type:Usage, subType: Electric
2020-10-18 17:39:00.183 Status: dzVents: > 12: Wnk - Erker type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 13: Wnk - Erker [W] type:Usage, subType: Electric
2020-10-18 17:39:00.183 Status: dzVents: > 14: Buitenlamp - Voordeur type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 15: Buitenlamp - Voordeur [W] type:Usage, subType: Electric
2020-10-18 17:39:00.183 Status: dzVents: > 16: Buitenlamp - Garage voor type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 17: Ventilatie Hoog [Q1] type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 18: Ventilatie Laag [Q2] type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 19: Ventilatie Hoog [Q1] [W] type:Usage, subType: Electric
2020-10-18 17:39:00.183 Status: dzVents: > 20: Ventilatie Laag [Q2] [W] type:Usage, subType: Electric
2020-10-18 17:39:00.183 Status: dzVents: > 21: Everspring TempHum type:Temp + Humidity, subType: WTGR800
2020-10-18 17:39:00.183 Status: dzVents: > 22: Hal - Lamp type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 23: Hal - Lamp [W] type:Usage, subType: Electric
2020-10-18 17:39:00.183 Status: dzVents: > 24: Sensor - Achterdeur type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 25: Sensor - Deur Garage type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 26: Sirene Alarm type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 27: Motion Sensor Sensor type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 28: Motion Sensor Burglar type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 29: Motion Sensor - Lux type:Lux, subType: Lux
2020-10-18 17:39:00.183 Status: dzVents: > 30: Alarm mode type:Light/Switch, subType: Selector Switch
2020-10-18 17:39:00.183 Status: dzVents: > 31: Domoticz Security Panel type:Security, subType: Security Panel
2020-10-18 17:39:00.183 Status: dzVents: > 32: RM1 Sensor type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 33: RM1 Smoke type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 34: RM1 Heat type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 35: Temperatuur Overloop type:Temp, subType: LaCrosse TX3
2020-10-18 17:39:00.183 Status: dzVents: > 36: CO Sensor type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 37: CO Carbon Monoxide type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 38: CO Heat type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 39: Temperatuur Zolder type:Temp, subType: LaCrosse TX3
2020-10-18 17:39:00.183 Status: dzVents: > 40: Toon Scenes type:Light/Switch, subType: Selector Switch
2020-10-18 17:39:00.183 Status: dzVents: > 41: Toon Thermostaat type:Thermostat, subType: SetPoint
2020-10-18 17:39:00.183 Status: dzVents: > 42: Temperatuur Kamer type:Temp, subType: LaCrosse TX3
2020-10-18 17:39:00.183 Status: dzVents: > 43: Toon Auto Program type:Light/Switch, subType: Selector Switch
2020-10-18 17:39:00.183 Status: dzVents: > 44: Ketelstand type:Light/Switch, subType: Selector Switch
2020-10-18 17:39:00.183 Status: dzVents: > 45: Ketel Temp IN type:Temp, subType: LaCrosse TX3
2020-10-18 17:39:00.183 Status: dzVents: > 46: Ketel Temp UIT type:Temp, subType: LaCrosse TX3
2020-10-18 17:39:00.183 Status: dzVents: > 47: Keteldruk type:General, subType: Pressure
2020-10-18 17:39:00.183 Status: dzVents: > 48: Tuinlamp - Licht type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 49: Tuinlamp - Stroom type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 50: Tuinlamp - Q1 [W] type:Usage, subType: Electric
2020-10-18 17:39:00.183 Status: dzVents: > 51: Tuinlamp - Q2 [W] type:Usage, subType: Electric
2020-10-18 17:39:00.183 Status: dzVents: > 52: Wnk - Openhaard type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 53: Wnk - Openhaard [W] type:Usage, subType: Electric
2020-10-18 17:39:00.183 Status: dzVents: > 54: SolarEdge kWh Meter type:General, subType: kWh
2020-10-18 17:39:00.183 Status: dzVents: > 55: P1 Gas type:P1 Smart Meter, subType: Gas
2020-10-18 17:39:00.183 Status: dzVents: > 56: P1 Elektra type:P1 Smart Meter, subType: Energy
2020-10-18 17:39:00.183 Status: dzVents: > 57: ModulationLevel type:General, subType: Percentage
2020-10-18 17:39:00.183 Status: dzVents: > 58: Ketel Setpoint type:Temp, subType: LaCrosse TX3
2020-10-18 17:39:00.183 Status: dzVents: > 59: HDD /media/camera1 type:General, subType: Percentage
2020-10-18 17:39:00.183 Status: dzVents: > 60: HDD /media/camera2 type:General, subType: Percentage
2020-10-18 17:39:00.183 Status: dzVents: > 61: HDD /media/backup type:General, subType: Percentage
2020-10-18 17:39:00.183 Status: dzVents: > 62: Process Usage type:General, subType: Custom Sensor
2020-10-18 17:39:00.183 Status: dzVents: > 63: Wnk - Studeerkamer type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 64: Wnk - Studeerkmer [W] type:Usage, subType: Electric
2020-10-18 17:39:00.183 Status: dzVents: > 65: Hal-ES2 type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 66: Hal-ES1 type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 67: Hal-ES3 type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 68: Hal-ES4 type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 69: Hal-DS2 type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 70: Hal-DS1 type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 71: Hal-DS3 type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 72: Hal-DS4 type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 73: Squeezebox Touch type:Lighting 2, subType: AC
2020-10-18 17:39:00.183 Status: dzVents: > 74: Buitenlamp - Garage achter type:Light/Switch, subType: Switch
2020-10-18 17:39:00.183 Status: dzVents: > 75: Buitenlamp - Garage achter type:Usage, subType: Electric
2020-10-18 17:39:00.183 Status: dzVents: > 76: Buienradar type:General, subType: Text
2020-10-18 17:39:00.183 Status: dzVents: > 77: RegenData type:Rain, subType: TFA
2020-10-18 17:39:00.183 Status: dzVents: !Info: light control: Motion Sensor Burglar
2020-10-18 17:39:00.183 Status: dzVents: !Info: light control: Wnk - Studeerkamer
2020-10-18 17:39:00.184 Status: dzVents: !Info: light control: Motion Sensor - Lux
2020-10-18 17:39:00.184 Status: dzVents: Info: light control: ------ Finished Test_Script
2020-10-18 17:39:00.184 Error: dzVents: Error: (3.0.2) light control: An error occurred when calling event handler Test_Script
2020-10-18 17:39:00.184 Error: dzVents: Error: (3.0.2) light control: ...moticz/scripts/dzVents/generated_scripts/Test_Script.lua:48: attempt to index a number value (local 'lux')
.

Not sure what happened, but i lost my configuration settings of the PIR in domoticz.
The sensor is still available, but no config settings.
The only thing i've changed was the lux value
Maybe this give now the error with the lux
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by madpatrick »

Waaren

Another question.
If you (re)start the script after the triggermoment (minutesBeforeSunset), will the script start or will it wait for the next day ?

according to the WIKI:

Code: Select all

One important note: if Domoticz, for whatever reason, skips a timer event then you may miss the trigger! Therefore, you should build in some fail-safe checks or some redundancy if you have critical time-based stuff to control. There is nothing dzVents can do about it
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by waaren »

madpatrick wrote: Sunday 18 October 2020 18:45
One important note: if Domoticz, for whatever reason, skips a timer event then you may miss the trigger! Therefore, you should build in some fail-safe checks or some redundancy if you have critical time-based stuff to control. There is nothing dzVents can do about it
Dzvents does not look back to see if it missed any scripts because the script-, dzVents=, domoticz- or your system was inactive at the time of the trigger. It will patiently wait until a trigger will become active. If that takes 3 seconds or 3 weeks will make no difference.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by madpatrick »

The light switched on yesterday evening after i've switch them of earlier

The script is triggered by "sleep" (at 23:00), but this did to put on the lights.
The lux is of course below <20 (trigger point) at night and no lights on.....

Code: Select all

2020-10-18 23:00:00.438  Status: dzVents: Info: -=# light control: ------ Start internal script: PIR Woonkamer:, trigger: "at 23:00"
2020-10-18 23:00:00.438  Status: dzVents: Debug: -=# light control: Processing device-adapter for Woonkamer: Group device adapter
2020-10-18 23:00:00.438  Status: dzVents: Debug: -=# light control: Woonkamer state is Off
2020-10-18 23:00:00.439  Status: dzVents: Debug: -=# light control: Constructed timed-command: On
2020-10-18 23:00:00.439  Status: dzVents: Debug: -=# light control: Constructed timed-command: On
2020-10-18 23:00:00.439  Status: dzVents: Debug: -=# light control: Woonkamer switched On or already On
2020-10-18 23:00:00.439  Status: dzVents: Info: -=# light control: ------ Finished PIR Woonkamer
Can this be a solution to add a function not to switch if time > sleep ?

Code: Select all

if lux < 20 and dz.time ('before '..Sleep) then
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by waaren »

madpatrick wrote: Monday 19 October 2020 8:36 The light switched on yesterday evening after i've switch them of earlier
Can you try again after changing line

Code: Select all

if dz.time.matchesRule('between ' .. minutesBeforeSunset .. ' minutes before sunset and ' .. Sleep) then 
to

Code: Select all

if dz.time.matchesRule('between ' .. minutesBeforeSunset .. ' minutes before sunset and ' .. Sleep) and not(dz.time.matchesRule('at ' .. Sleep)) then 
If stil not OK after this the please use PM and share complete script an loglines
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by madpatrick »

Waaren,

The script is running and the test yesterday evening went good.
Just some finetuning within time and lux value

The only point is the logging of LUX and PIR. I've sent this to you via PM

Many thanks for your support
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by madpatrick »

Small update:
Logging is now also working :D :D
Small typo in the script

This is the correct part of the script for logging

Code: Select all

dz.log(' lux = ' .. lux,dz.LOG_DEBUG)
dz.log(PIR.name .. ' was last updated ' .. PIR.lastUpdate.secondsAgo .. ' seconds ago',dz.LOG_DEBUG)
dz.log(light.name .. ' state is ' .. light.state ,dz.LOG_DEBUG)
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest