Page 2 of 2

Re: Doorswitch to turn on and off a light

Posted: Sunday 05 January 2020 19:18
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 ?

Re: Doorswitch to turn on and off a light

Posted: Sunday 05 January 2020 20:11
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

Re: Doorswitch to turn on and off a light

Posted: Sunday 05 January 2020 21:31
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)

Re: Doorswitch to turn on and off a light

Posted: Sunday 05 January 2020 22:27
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.

Re: Doorswitch to turn on and off a light

Posted: Sunday 05 January 2020 22:51
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

Re: Doorswitch to turn on and off a light

Posted: Monday 06 January 2020 3:13
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.