Doorswitch to turn on and off a light Topic is solved

Moderator: leecollings

User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Doorswitch to turn on and off a light

Post by waaren »

dutchronnie wrote: Sunday 05 January 2020 19:03 I see in the log door goes open and door is closed.
Can you share that complete part of the log where you see the the door opening and closing ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
James83
Posts: 16
Joined: Thursday 28 November 2019 0:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Belgium
Contact:

Re: Doorswitch to turn on and off a light

Post by James83 »

Hi,

I have some of the same door/window sensors. They send a 'On' command for both the open and close state but with a different EV1527 code.

Maybe try to change:

Code: Select all

if door == open then
...
elseif door == closed then
...
with

Code: Select all

if door.name == open.name then
...
elseif door.name == closed.name then
...
:?:

Jimmy
RPI4, Philips Hue, Tradfri, Sonoff, MQTT, Zigbee2Mqtt, RFXCom 433, Octoprint,...
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Doorswitch to turn on and off a light

Post by waaren »

James83 wrote: Sunday 05 January 2020 20:11 Maybe try to change:

Code: Select all

if door == open then
...
elseif door == closed then
...
with

Code: Select all

if door.name == open.name then
...
elseif door.name == closed.name then
...
Always worth a try but in this case that should not make a difference. In door == open, I compare the device object to the triggering object. Here it will have the same result as checking the names (a string). Name is just one attribute of the object so in theory you can get a false positive when checking only this attribute (different objects with equal name attributes)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Re: Doorswitch to turn on and off a light

Post by dutchronnie »

:D :D
It is working now.
I changed some names, so i post the script:

Code: Select all

return {
    active = true,
    on = {
        devices = { 
            ['deur open'] = { 'at nighttime' },
            ['deur close'] = { 'at nighttime' },            
        },
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
    },
    
    execute = function(dz, door)
        _G.logMarker = _G.moduleLabel
        local light = dz.devices('deur')
        
        open = dz.devices('deur open')
        closed = dz.devices('deur close')
        
        dz.log('state of ' .. door.name .. ': ' .. door.state .. ' => ' .. (door.active and ' active' or 'not active') )
        
        if door.name == open.name then
            light.switchOn()
        elseif door.name == closed.name then
            light.switchOff().afterSec(10)
        end
    end
}
This are the results of the log file:
2020-01-05 22:25:28.191 Status: dzVents: Info: Handling events for: "deur open", value: "On"
2020-01-05 22:25:28.191 Status: dzVents: Info: ------ Start internal script: Deur open en dicht: Device: "deur open (RFLink Gateway)", Index: 273
2020-01-05 22:25:28.196 Status: dzVents: Debug: Deur open en dicht: Processing device-adapter for deur: Switch device adapter
2020-01-05 22:25:28.198 Status: dzVents: Debug: Deur open en dicht: Processing device-adapter for deur close: Switch device adapter
2020-01-05 22:25:28.198 Status: dzVents: Info: Deur open en dicht: state of deur open: On => active
2020-01-05 22:25:28.198 Status: dzVents: Debug: Deur open en dicht: Constructed timed-command: On
2020-01-05 22:25:28.198 Status: dzVents: Info: Deur open en dicht: ------ Finished Deur open en dicht
2020-01-05 22:25:28.200 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-01-05 22:25:30.707 (RFLink Gateway) Light/Switch (deur close)
2020-01-05 22:25:30.911 Status: dzVents: Info: Handling events for: "deur close", value: "On"
2020-01-05 22:25:30.911 Status: dzVents: Info: ------ Start internal script: Deur open en dicht: Device: "deur close (RFLink Gateway)", Index: 274
2020-01-05 22:25:30.913 Status: dzVents: Debug: Deur open en dicht: Processing device-adapter for deur: Switch device adapter
2020-01-05 22:25:30.915 Status: dzVents: Debug: Deur open en dicht: Processing device-adapter for deur open: Switch device adapter
2020-01-05 22:25:30.915 Status: dzVents: Info: Deur open en dicht: state of deur close: On => active
2020-01-05 22:25:30.916 Status: dzVents: Debug: Deur open en dicht: Constructed timed-command: Off
2020-01-05 22:25:30.916 Status: dzVents: Debug: Deur open en dicht: Constructed timed-command: Off AFTER 10 SECONDS
2020-01-05 22:25:30.916 Status: dzVents: Info: Deur open en dicht: ------ Finished Deur open en dicht
2020-01-05 22:25:30.918 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
Thanks a lot to you all.
I can now build futher with my home automation.
James83
Posts: 16
Joined: Thursday 28 November 2019 0:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Belgium
Contact:

Re: Doorswitch to turn on and off a light

Post by James83 »

Glad it's solved :D

Meanwhile did a quick test with and without the .name attribute.
Both output true if so
so, issue must have been in the name of the devices.

Jimmy
RPI4, Philips Hue, Tradfri, Sonoff, MQTT, Zigbee2Mqtt, RFXCom 433, Octoprint,...
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Doorswitch to turn on and off a light

Post by waaren »

James83 wrote: Sunday 05 January 2020 22:51 Meanwhile did a quick test with and without the .name attribute.
Both output true if so
👍 Thx for testing and the confirmation.
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 1 guest