DZ Vents Light timer Help Please  [Solved]

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

Moderator: leecollings

alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

DZ Vents Light timer Help Please

Post by alarm_guy1 »

Hi,
I have the following DZ Vents, It is supposed to turn my kitchen light on if lux level is below 30 and motion is detected, (this works fine) However after 5mins if the detector has not activated then the light should go off, and if the detector detects motion then the light should stay on for a further 5 mins.

However the light just stays on..

Any help appreciated

keith



return {
on = {
devices = {
"Kitchen MD Sensor",
"Kitchen Lights"
}
},
execute = function(dz, device)

local Sensor = dz.devices("Kitchen MD Sensor")
local Lux = dz.devices("Kitchen MD Lux").lux
local Lights = dz.devices ("Kitchen Lights")

if (Sensor.state == "On") and (Lights.state == "Off") and Lux < 30 then
Lights.switchOn()
elseif (Lights.state == "On") and Sensor.lastUpdate.minutesAgo > 1 then
Lights.switchOff().afterMin(5)
end

end
}
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 »

alarm_guy1 wrote: Friday 30 November 2018 22:51 I have the following DZ Vents, It is supposed to turn my kitchen light on if lux level is below 30 and motion is detected, (this works fine) However after 5mins if the detector has not activated then the light should go off, and if the detector detects motion then the light should stay on for a further 5 mins.
However the light just stays on..
Any help appreciated
Try this one.

Code: Select all

return  {
            on = { devices = { "Kitchen MD Sensor" }},
         
    execute = function(dz, item)
        local Lux = dz.devices("Kitchen MD Lux").lux
        local Lights = dz.devices("Kitchen Lights")
       
        if item.state == "On" and Lux < 30 then
            Lights.cancelQueuedCommands()
            Lights.switchOn().checkFirst()
            Lights.switchOff().afterMin(5)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Re: DZ Vents Light timer Help Please

Post by alarm_guy1 »

Thankyou,

I'll give it a try

cheers
alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Re: DZ Vents Light timer Help Please

Post by alarm_guy1 »

Hi,

Just had a chance to test this and nothing happens and I get the following error

2018-12-01 01:24:33.535 Status: dzVents: Info: Handling events for: "Kitchen MD Sensor", value: "Off"
2018-12-01 01:24:33.535 Status: dzVents: Info: ------ Start internal script: Kitchen Lights DZ: Device: "Kitchen MD Sensor (Usb Controller)", Index: 192
2018-12-01 01:24:33.536 Status: dzVents: Error (2.4.6): There is no device with that name or id: Kitchen MD Lux
2018-12-01 01:24:33.536 Status: dzVents: Error (2.4.6): An error occured when calling event handler Kitchen Lights DZ
2018-12-01 01:24:33.536 Status: dzVents: Error (2.4.6): .../scripts/dzVents/generated_scripts/Kitchen Lights DZ.lua:5: attempt to index a nil value
2018-12-01 01:24:33.536 Status: dzVents: Info: ------ Finished Kitchen Lights DZ

Cheers
alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Re: DZ Vents Light timer Help Please

Post by alarm_guy1 »

I have checked all spellings and re-copied and pasted item names from devices
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 »

alarm_guy1 wrote: Saturday 01 December 2018 2:28 Error (2.4.6): There is no device with that name or id: Kitchen MD Lux
Hi I added a couple of lines to see what happens during execution. Please change the two xxx in the script with the IDX numbers of the devices (without quotes). That might give a clue what is wrong.

Code: Select all

return  {
            on          =   { devices           =  {  "Kitchen MD Sensor" }
                            },
            
            logging     =   {   
                                level           =   domoticz.LOG_DEBUG,
                                marker          =   "Kitchen motion" 
                            },
                    
    execute = function(dz, item)

        local function logWrite(str,level)
            dz.log(str,level or dz.LOG_DEBUG)
        end

       -- local Lux = dz.devices("Kitchen MD Lux").lux
                local LuxDevice = dz.devices(xxx)                 -- <<<--- replace xxx by IDX of your Lux device
                local Lux = LuxDevice.lux
        -- local Lights = dz.devices("Kitchen Lights")
                local Lights = dz.devices(xxx)                       -- <<<--- replace xxx by IDX of your Kitchen lights
                            
        logWrite("name of Lux device: " .. LuxDevice.name)
        logWrite("name of Light     : " .. Lights.name)
       
        if item.state == "On" and Lux < 30 then
            Lights.cancelQueuedCommands()
            Lights.switchOn().checkFirst()
            Lights.switchOff().afterMin(5)
        end
    end
}     
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Re: DZ Vents Light timer Help Please

Post by alarm_guy1 »

Cheers

I will give it a test.
Although first impressions are it is functioning well.

entered kitchen, lights on
left kitchen lights off after 5 mins
entered kitchen lights on
left for 4 mins came back set timer on phone for 2 mins Lights stayed on.
Left room and lights went out.
The true test will be tonight when we are cooking as to whether we will be plunged into darkness..... as usual...
Many many thanks
alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Re: DZ Vents Light timer Help Please

Post by alarm_guy1 »

Hi thanks for the continued support, unfortunately we are still plunged into darkness after 5 mins, is there anyway to have every activation of the detector restart the 5 min timer.

many many thanks
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 »

alarm_guy1 wrote: Monday 03 December 2018 19:40 Hi thanks for the continued support, unfortunately we are still plunged into darkness after 5 mins, is there anyway to have every activation of the detector restart the 5 min timer.

many many thanks
Sure. If this not work as expected, I would be very interested in the loglines created by this script.

Code: Select all

return  {
            on          =   { devices           =  {  "Kitchen MD Sensor" }
                            },
            
            logging     =   {   
                                level           =   domoticz.LOG_DEBUG,
                                marker          =   "Kitchen motion" 
                            },
                    
    execute = function(dz, item)

        local function logWrite(str,level)
            dz.log(str,level or dz.LOG_DEBUG)
        end

       -- local Lux = dz.devices("Kitchen MD Lux").lux
                local LuxDevice = dz.devices(xxx)                 -- <<<--- replace xxx by IDX of your Lux device
                local Lux = LuxDevice.lux
        -- local Lights = dz.devices("Kitchen Lights")
                local Lights = dz.devices(xxx)                       -- <<<--- replace xxx by IDX of your Kitchen lights
                            
        logWrite(LuxDevice.name .. " ==>> Lux:   " .. Lux )
        logWrite(Lights.name ..    " ==>> State: " .. Lights.state)
       
        if Lux < 30 then
            Lights.cancelQueuedCommands()
            Lights.switchOn()
            Lights.switchOff().afterMin(5)
        end
    end
}     
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Re: DZ Vents Light timer Help Please

Post by alarm_guy1 »

A snippet from the log:

2018-12-03 17:43:59.067 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2018-12-03 17:44:29.248 Status: dzVents: Info: Handling events for: "Kitchen MD Sensor", value: "Off"
2018-12-03 17:44:29.248 Status: dzVents: Info: Kitchen motion: ------ Start internal script: Kitchen Lights DZ: Device: "Kitchen MD Sensor (Usb Controller)", Index: 192
2018-12-03 17:44:29.252 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen MD Lux: Lux device adapter
2018-12-03 17:44:29.254 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen Lights: Switch device adapter
2018-12-03 17:44:29.254 Status: dzVents: Debug: Kitchen motion: name of Lux device: Kitchen MD Lux
2018-12-03 17:44:29.255 Status: dzVents: Debug: Kitchen motion: name of Light : Kitchen Lights
2018-12-03 17:44:29.255 Status: dzVents: Info: Kitchen motion: ------ Finished Kitchen Lights DZ
2018-12-03 17:44:44.082 Status: dzVents: Info: Handling events for: "Kitchen MD Sensor", value: "On"
2018-12-03 17:44:44.083 Status: dzVents: Info: Kitchen motion: ------ Start internal script: Kitchen Lights DZ: Device: "Kitchen MD Sensor (Usb Controller)", Index: 192
2018-12-03 17:44:44.085 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen MD Lux: Lux device adapter
2018-12-03 17:44:44.088 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen Lights: Switch device adapter
2018-12-03 17:44:44.088 Status: dzVents: Debug: Kitchen motion: name of Lux device: Kitchen MD Lux
2018-12-03 17:44:44.088 Status: dzVents: Debug: Kitchen motion: name of Light : Kitchen Lights
2018-12-03 17:44:44.089 Status: dzVents: Debug: Kitchen motion: Constructed timed-command: On
2018-12-03 17:44:44.089 Status: dzVents: Debug: Kitchen motion: Constructed timed-command: Off
2018-12-03 17:44:44.091 Status: dzVents: Debug: Kitchen motion: Constructed timed-command: Off AFTER 300 SECONDS
2018-12-03 17:44:44.091 Status: dzVents: Info: Kitchen motion: ------ Finished Kitchen Lights DZ
2018-12-03 17:44:44.301 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2018-12-03 17:45:28.451 Status: OpenZWave: Received timeout notification from HomeID: 3246928100, NodeID: 8 (0x08)
2018-12-03 17:51:04.161 Status: dzVents: Info: Handling events for: "Kitchen MD Sensor", value: "Off"
2018-12-03 17:51:04.161 Status: dzVents: Info: Kitchen motion: ------ Start internal script: Kitchen Lights DZ: Device: "Kitchen MD Sensor (Usb Controller)", Index: 192
2018-12-03 17:51:04.164 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen MD Lux: Lux device adapter
2018-12-03 17:51:04.167 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen Lights: Switch device adapter
2018-12-03 17:51:04.167 Status: dzVents: Debug: Kitchen motion: name of Lux device: Kitchen MD Lux
2018-12-03 17:51:04.167 Status: dzVents: Debug: Kitchen motion: name of Light : Kitchen Lights
2018-12-03 17:51:04.167 Status: dzVents: Info: Kitchen motion: ------ Finished Kitchen Lights DZ
2018-12-03 17:51:04.701 Status: dzVents: Info: Handling events for: "Kitchen MD Sensor", value: "On"
2018-12-03 17:51:04.701 Status: dzVents: Info: Kitchen motion: ------ Start internal script: Kitchen Lights DZ: Device: "Kitchen MD Sensor (Usb Controller)", Index: 192
2018-12-03 17:51:04.704 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen MD Lux: Lux device adapter
2018-12-03 17:51:04.708 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen Lights: Switch device adapter
2018-12-03 17:51:04.708 Status: dzVents: Debug: Kitchen motion: name of Lux device: Kitchen MD Lux
2018-12-03 17:51:04.708 Status: dzVents: Debug: Kitchen motion: name of Light : Kitchen Lights
2018-12-03 17:51:04.708 Status: dzVents: Debug: Kitchen motion: Constructed timed-command: On
2018-12-03 17:51:04.709 Status: dzVents: Debug: Kitchen motion: Constructed timed-command: Off
2018-12-03 17:51:04.710 Status: dzVents: Debug: Kitchen motion: Constructed timed-command: Off AFTER 300 SECONDS
2018-12-03 17:51:04.710 Status: dzVents: Info: Kitchen motion: ------ Finished Kitchen Lights DZ
2018-12-03 17:51:04.953 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2018-12-03 17:53:32.655 Status: OpenZWave: Received timeout notification from HomeID: 3246928100, NodeID: 8 (0x08)
2018-12-03 17:54:14.087 Status: dzVents: Info: Handling events for: "Kitchen MD Sensor", value: "Off"
2018-12-03 17:54:14.087 Status: dzVents: Info: Kitchen motion: ------ Start internal script: Kitchen Lights DZ: Device: "Kitchen MD Sensor (Usb Controller)", Index: 192
2018-12-03 17:54:14.092 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen MD Lux: Lux device adapter
2018-12-03 17:54:14.096 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen Lights: Switch device adapter
2018-12-03 17:54:14.097 Status: dzVents: Debug: Kitchen motion: name of Lux device: Kitchen MD Lux
2018-12-03 17:54:14.097 Status: dzVents: Debug: Kitchen motion: name of Light : Kitchen Lights
2018-12-03 17:54:14.097 Status: dzVents: Info: Kitchen motion: ------ Finished Kitchen Lights DZ
2018-12-03 17:56:11.651 Status: dzVents: Info: Handling events for: "Kitchen MD Sensor", value: "On"
2018-12-03 17:56:11.652 Status: dzVents: Info: Kitchen motion: ------ Start internal script: Kitchen Lights DZ: Device: "Kitchen MD Sensor (Usb Controller)", Index: 192
2018-12-03 17:56:11.654 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen MD Lux: Lux device adapter
2018-12-03 17:56:11.657 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen Lights: Switch device adapter
2018-12-03 17:56:11.657 Status: dzVents: Debug: Kitchen motion: name of Lux device: Kitchen MD Lux
2018-12-03 17:56:11.657 Status: dzVents: Debug: Kitchen motion: name of Light : Kitchen Lights
2018-12-03 17:56:11.658 Status: dzVents: Debug: Kitchen motion: Constructed timed-command: On
2018-12-03 17:56:11.658 Status: dzVents: Debug: Kitchen motion: Constructed timed-command: On
2018-12-03 17:56:11.658 Status: dzVents: Debug: Kitchen motion: Constructed timed-command: Off
2018-12-03 17:56:11.659 Status: dzVents: Debug: Kitchen motion: Constructed timed-command: Off AFTER 300 SECONDS
2018-12-03 17:56:11.659 Status: dzVents: Info: Kitchen motion: ------ Finished Kitchen Lights DZ
2018-12-03 17:56:11.871 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2018-12-03 17:57:00.332 Status: dzVents: Info: Handling events for: "Kitchen MD Sensor", value: "Off"
2018-12-03 17:57:00.333 Status: dzVents: Info: Kitchen motion: ------ Start internal script: Kitchen Lights DZ: Device: "Kitchen MD Sensor (Usb Controller)", Index: 192
2018-12-03 17:57:00.337 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen MD Lux: Lux device adapter
2018-12-03 17:57:00.342 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen Lights: Switch device adapter
2018-12-03 17:57:00.342 Status: dzVents: Debug: Kitchen motion: name of Lux device: Kitchen MD Lux
2018-12-03 17:57:00.342 Status: dzVents: Debug: Kitchen motion: name of Light : Kitchen Lights
2018-12-03 17:57:00.343 Status: dzVents: Info: Kitchen motion: ------ Finished Kitchen Lights DZ
2018-12-03 17:57:01.766 Status: dzVents: Info: Handling events for: "Kitchen MD Sensor", value: "On"
2018-12-03 17:57:01.766 Status: dzVents: Info: Kitchen motion: ------ Start internal script: Kitchen Lights DZ: Device: "Kitchen MD Sensor (Usb Controller)", Index: 192
2018-12-03 17:57:01.771 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen MD Lux: Lux device adapter
2018-12-03 17:57:01.775 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen Lights: Switch device adapter
2018-12-03 17:57:01.776 Status: dzVents: Debug: Kitchen motion: name of Lux device: Kitchen MD Lux
2018-12-03 17:57:01.776 Status: dzVents: Debug: Kitchen motion: name of Light : Kitchen Lights
2018-12-03 17:57:01.776 Status: dzVents: Debug: Kitchen motion: Constructed timed-command: On
2018-12-03 17:57:01.777 Status: dzVents: Debug: Kitchen motion: Constructed timed-command: Off
2018-12-03 17:57:01.777 Status: dzVents: Debug: Kitchen motion: Constructed timed-command: Off AFTER 300 SECONDS
2018-12-03 17:57:01.777 Status: dzVents: Info: Kitchen motion: ------ Finished Kitchen Lights DZ
2018-12-03 17:57:01.992 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2018-12-03 17:57:32.052 Status: dzVents: Info: Handling events for: "Kitchen MD Sensor", value: "Off"
2018-12-03 17:57:32.052 Status: dzVents: Info: Kitchen motion: ------ Start internal script: Kitchen Lights DZ: Device: "Kitchen MD Sensor (Usb Controller)", Index: 192
2018-12-03 17:57:32.055 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen MD Lux: Lux device adapter
2018-12-03 17:57:32.059 Status: dzVents: Debug: Kitchen motion: Processing device-adapter for Kitchen Lights: Switch device adapter
2018-12-03 17:57:32.060 Status: dzVents: Debug: Kitchen motion: name of Lux device: Kitchen MD Lux
2018-12-03 17:57:32.060 Status: dzVents: Debug: Kitchen motion: name of Light : Kitchen Lights
2018-12-03 17:57:32.060 Status: dzVents: Info: Kitchen motion: ------ Finished Kitchen Lights DZ


The wife was on me as soon as i walked in the door (Not in a good way)
that she was being plunged into darkness every 5 or 10 mins
cheers
akamming
Posts: 337
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DZ Vents Light timer Help Please

Post by akamming »

Hi,

i had similar problems creating a lighting script. I found out that if you user forMin() or afterMin() clausules: The scheduled commands remain scheduled if you give new commands to the switch as a result to a new event creating weird behaviour. So you should always cancel scheduled eventes using cancelQueuedCommands() before you give a new switch commands.

For this purpose i created 2 functions in my code for turning on and off lights

Code: Select all


        local Timeout=60  -- numer of mins after which the lights should go out if no motion is detected 
        
        function SwitchOn(name)
            -- get device from name
            local device=domoticz.devices(name)

            -- turning off scheduled commands
            device.cancelQueuedCommands()
            if (device.active) then
                domoticz.log("Device["..device.name.."] already active, disabling scheduled commands and set new timeout["..Timeout.."]",domoticz.LOG_DEBUG)
                device.switchOff().afterMin(Timeout).silent()
            else
                domoticz.log("Device["..device.name.."] is off, turning on with scheduled turnoff timeout["..Timeout.."]",domoticz.LOG_DEBUG)
                device.switchOn().forMin(Timeout).silent()
            end
        end
    
        function SwitchOff(name)
            -- get device from name
            local device=domoticz.devices(name)
            
            -- disable queued commands
            device.cancelQueuedCommands()
            if (device.active) then
                domoticz.log("Device["..device.name.."] is active, turning off",domoticz.LOG_DEBUG)
                device.switchOff(device).silent()
            else
                domoticz.log( "Device["..device.name.."] is off, do nothing", domoticz.LOG_DEBUG)
            end
        end
        
if you incorporate this in your code it should work fine...
alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Re: DZ Vents Light timer Help Please

Post by alarm_guy1 »

Thankyou. I will try tomorrow night as I'm currently out cheers, I'll let u know how I get on
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 »

alarm_guy1 wrote: Monday 03 December 2018 20:10 The wife was on me as soon as i walked in the door (Not in a good way)
that she was being plunged into darkness every 5 or 10 mins
cheers
Excellent way of convincing your wife that you really need a test environment :D

Based on the log this should be better for your situation

Code: Select all

return  {
            on          =   { devices           =  {  "Kitchen MD Sensor" }
                            },
            
            logging     =   {   
                                level           =   domoticz.LOG_DEBUG,
                                marker          =   "Kitchen motion" 
                            },
                    
    execute = function(dz, item)

        local function logWrite(str,level)
            dz.log(str,level or dz.LOG_DEBUG)
        end

       -- local Lux = dz.devices("Kitchen MD Lux").lux
                local LuxDevice = dz.devices(xxx)                 -- <<<--- replace xxx by IDX of your Lux device
                local Lux = LuxDevice.lux
        -- local Lights = dz.devices("Kitchen Lights")
                local Lights = dz.devices(xxx)                       -- <<<--- replace xxx by IDX of your Kitchen lights
                            
        logWrite(LuxDevice.name .. " ==>> Lux:   " .. Lux )
        logWrite(Lights.name ..    " ==>> State: " .. Lights.state)
        logWrite(item.name ..      " ==>> State: " .. item.state)
       
        if Lux < 30 and item.state == "On" then
            Lights.cancelQueuedCommands()
            Lights.switchOn().checkFirst()
        elseif item.state == "Off" and Lights.state == "On" then 
            Lights.switchOff().afterSec(300) 
        end
    end
}     
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Re: DZ Vents Light timer Help Please

Post by alarm_guy1 »

Thankyou, I have swapped to the new script, seemed ok on breakfast duties, however the wife may cook for me tonight so, the moment I walk in the door we will know.... i'll keep you posted :-)
alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Re: DZ Vents Light timer Help Please  [Solved]

Post by alarm_guy1 »

Sorry for the delay, but we have not been in the kitchen recently for an extended period of time, but I would like to say a whole hearted big THANKYOU for the assistance and code as it appears to be functioning as expected.

THANKYOU
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 »

Hi waaren,

is there a possibility that when i change de dim level manually that when there is a movement again that the manually chosen dim level stays like this?


i tried it do it with the wiki but unfortunately i could not figure this out

hope you can help me
waaren wrote: Monday 03 December 2018 22:09
alarm_guy1 wrote: Monday 03 December 2018 20:10 The wife was on me as soon as i walked in the door (Not in a good way)
that she was being plunged into darkness every 5 or 10 mins
cheers
Excellent way of convincing your wife that you really need a test environment :D

Based on the log this should be better for your situation

Code: Select all

return  {
            on          =   { devices           =  {  "Kitchen MD Sensor" }
                            },
            
            logging     =   {   
                                level           =   domoticz.LOG_DEBUG,
                                marker          =   "Kitchen motion" 
                            },
                    
    execute = function(dz, item)

        local function logWrite(str,level)
            dz.log(str,level or dz.LOG_DEBUG)
        end

       -- local Lux = dz.devices("Kitchen MD Lux").lux
                local LuxDevice = dz.devices(xxx)                 -- <<<--- replace xxx by IDX of your Lux device
                local Lux = LuxDevice.lux
        -- local Lights = dz.devices("Kitchen Lights")
                local Lights = dz.devices(xxx)                       -- <<<--- replace xxx by IDX of your Kitchen lights
                            
        logWrite(LuxDevice.name .. " ==>> Lux:   " .. Lux )
        logWrite(Lights.name ..    " ==>> State: " .. Lights.state)
        logWrite(item.name ..      " ==>> State: " .. item.state)
       
        if Lux < 30 and item.state == "On" then
            Lights.cancelQueuedCommands()
            Lights.switchOn().checkFirst()
        elseif item.state == "Off" and Lights.state == "On" then 
            Lights.switchOff().afterSec(300) 
        end
    end
}     
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: Saturday 01 February 2020 14:50 is there a possibility that when i change de dim level manually that when there is a movement again that the manually chosen dim level stays like this?
Sorry but I don't understand what you want. I don't get the relation with the example you attached either so please elaborate and explain in detail what you want and what you tried so far.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
alarm_guy1
Posts: 132
Joined: Tuesday 14 January 2014 0:03
Target OS: Linux
Domoticz version:
Contact:

Re: DZ Vents Light timer Help Please

Post by alarm_guy1 »

I think what he is saying, is if you go into the room and the light comes on say 40%, and you subsequently dim that light to say 20%, when movement is detected the light will come back on at 40%, is there a way to make it come back on at the last dimmed level.. I THINK
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 »

Yes that's what I mean
alarm_guy1 wrote: Saturday 01 February 2020 18:11 I think what he is saying, is if you go into the room and the light comes on say 40%, and you subsequently dim that light to say 20%, when movement is detected the light will come back on at 40%, is there a way to make it come back on at the last dimmed level.. I THINK

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
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: 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests