Re: Doorswitch to turn on and off a light
Posted: Sunday 05 January 2020 19:18
Can you share that complete part of the log where you see the the door opening and closing ?
Open source Home Automation System
https://forum.domoticz.com/
Can you share that complete part of the log where you see the the door opening and closing ?
Code: Select all
if door == open then
...
elseif door == closed then
...
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)James83 wrote: Sunday 05 January 2020 20:11 Maybe try to change:withCode: Select all
if door == open then ... elseif door == closed then ...Code: Select all
if door.name == open.name then ... elseif door.name == closed.name then ...
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
}
Thanks a lot to you all.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
James83 wrote: Sunday 05 January 2020 22:51 Meanwhile did a quick test with and without the .name attribute.
Both output true if so