Hi waaren, thnx for the great script! Running into a few problems though.
I did some tweaking to make it work (dimTo doesn't work with the Ikea lights so i used a dummy selector switch).
This is my script thus far.
Code: Select all
local doorbell = 'Voordeur - Bel'
local doorsensor = 'Voordeur - Sensor'
return
{
on =
{
devices =
{
[doorbell] = { 'at nighttime' },
[doorsensor] = { 'at nighttime' },
},
timer =
{
'at sunset',
'at sunrise',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when tested and OK
},
data =
{
doorbellPressedAt = { initial = 0 },
doorsensorOpenedAt = { initial = 0 },
hallwayLightManual = { initial = false },
},
execute = function(dz, item)
_G.logMarker = _G.moduleLabel -- set logmarker to scrptname
outdoorLight = dz.devices(113)
hallwayLight = dz.groups(5)
doorsensor = dz.devices(doorsensor)
doorbell = dz.devices(doorbell)
if _G.logLevel == dz.LOG_DEBUG then
if item.isDevice then
dz.log(item.name .. ' is ' .. ( item.active and ' active.' or ' not active.' ) ,dz.LOG_DEBUG )
end
dz.log(outdoorLight.name .. ' state is ' .. outdoorLight.state,dz.LOG_DEBUG )
dz.log(hallwayLight.name .. ' state is ' .. hallwayLight.state,dz.LOG_DEBUG )
dz.log(doorsensor.name .. ' state is ' .. doorsensor.state,dz.LOG_DEBUG )
dz.log(doorbell.name .. ' state is ' .. doorbell.state,dz.LOG_DEBUG )
dz.log('------ content of dz.data before script logic ----- ',dz.LOG_DEBUG)
dz.utils.dumpTable(dz.data)
end
if item.isTimer then
if dz.time.matchesRule('at sunrise') then
outdoorLight.switchSelector(0)
else
outdoorLight.switchSelector(10)
end
-- when the doorbell is pressed at Nightime.
elseif item == doorbell and item.state == 'Click' or 'Long Click' or 'Double Click' then
-- clear any previous scheduled commands ( in case doorbell was pressed multiple times )
outdoorLight.cancelQueuedCommands() -- no dimTo(20)
hallwayLight.cancelQueuedCommands() -- no switchOff()
-- Outdoor_Light set to 100% and Hallway_Light set to On
outdoorLight.switchSelector(20)
-- If Door_Sensor stays 'closed' for 1 minute then reset Outdoor_Light to 20%.
outdoorLight.switchSelector(10).afterSec(60)
-- reset state of doorbell
item.switchOff().afterSec(60).silent() -- to prevent a retrigger of the script
-- only when not already on
dz.data.hallwayLightManual = hallwayLight.active
if not hallwayLight.active then
hallwayLight.switchOn()
hallwayLight.switchOff().afterSec(60)
end
dz.data.doorbellPressedAt = dz.time.dDate
dz.data.doorsensorOpenedAt = 0
--If Door_Sensor is 'open' then leave Hallway_Light On and Outdoor_Light to 100%.
elseif item == doorsensor and item.active and dz.data.doorbellPressedAt >= ( dz.time.dDate - 60 ) then -- doorbell was pressed within last minute
outdoorLight.cancelQueuedCommands() -- no dimTo(20)
hallwayLight.cancelQueuedCommands() -- no switchOff()
dz.data.doorsensorOpenedAt = dz.time.dDate
-- When Door_Sensor is 'closed' again turn Off Hallway_Light after 30 seconds and set Outdoor_Light to 20% after 1 minute.
elseif item == doorsensor and not(item.active) and dz.data.doorsensorOpenedAt ~= 0 then -- doorsensor was open after doorbell was pressed
if outdoorLight.level ~= 20 then outdoorLight.switchSelector(10).afterSec(60) end
if not dz.data.hallwayLightManual then -- if manual switched then leave it on
hallwayLight.switchOff().checkFirst().afterSec(30)
end
dz.data.doorsensorOpenedAt = 0
end
if _G.logLevel == dz.LOG_DEBUG then
dz.log('------ content of dz.data after script logic ----- ',dz.LOG_DEBUG)
dz.utils.dumpTable(dz.data)
end
end
}
The script is partially working (ringing the doorbell without opening the door).
The following part does not:
When someone rings the doorbell and I open the door within 60 seconds, the Outdoor_Light is still set to switchSelector(10) and Hallway_Light is still set to off after 60 seconds instead of stay both on until I close the door.
Log:
Code: Select all
2020-01-08 20:11:01.772 Status: dzVents: Info: Handling events for: "Voordeur - Bel", value: "Click"
2020-01-08 20:11:01.773 Status: dzVents: Info: ------ Start internal script: Deurbel: Device: "Voordeur - Bel (Zigbee2MQTT)", Index: 112
2020-01-08 20:11:01.783 Status: dzVents: Debug: Deurbel: Processing device-adapter for Voordeur - Lamp - Selector: Switch device adapter
2020-01-08 20:11:01.789 Status: dzVents: Debug: Deurbel: Processing device-adapter for Hal - Verlichting: Group device adapter
2020-01-08 20:11:01.796 Status: dzVents: Debug: Deurbel: Processing device-adapter for Voordeur - Sensor: Switch device adapter
2020-01-08 20:11:01.797 Status: dzVents: Debug: Deurbel: Voordeur - Bel is not active.
2020-01-08 20:11:01.798 Status: dzVents: Debug: Deurbel: Voordeur - Lamp - Selector state is 20%
2020-01-08 20:11:01.798 Status: dzVents: Debug: Deurbel: Hal - Verlichting state is Off
2020-01-08 20:11:01.798 Status: dzVents: Debug: Deurbel: Voordeur - Sensor state is Closed
2020-01-08 20:11:01.799 Status: dzVents: Debug: Deurbel: Voordeur - Bel state is Click
2020-01-08 20:11:01.799 Status: dzVents: Debug: Deurbel: ------ content of dz.data before script logic -----
2020-01-08 20:11:01.799 Status: dzVents: > hallwayLightManual: false
2020-01-08 20:11:01.800 Status: dzVents: > doorsensorOpenedAt: 0
2020-01-08 20:11:01.800 Status: dzVents: > doorbellPressedAt: 1578510361
2020-01-08 20:11:01.800 Status: dzVents: > initialize()
2020-01-08 20:11:01.801 Status: dzVents: Debug: Deurbel: Constructed timed-command: Set Level 20
2020-01-08 20:11:01.802 Status: dzVents: Debug: Deurbel: Constructed timed-command: Set Level 10
2020-01-08 20:11:01.803 Status: dzVents: Debug: Deurbel: Constructed timed-command: Set Level 10 AFTER 60 SECONDS
2020-01-08 20:11:01.803 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off
2020-01-08 20:11:01.804 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off AFTER 60 SECONDS
2020-01-08 20:11:01.805 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off AFTER 60 SECONDS NOTRIGGER
2020-01-08 20:11:01.806 Status: dzVents: Debug: Deurbel: Constructed timed-command: On
2020-01-08 20:11:01.807 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off
2020-01-08 20:11:01.808 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off AFTER 60 SECONDS
2020-01-08 20:11:01.809 Status: dzVents: Debug: Deurbel: ------ content of dz.data after script logic -----
2020-01-08 20:11:01.809 Status: dzVents: > hallwayLightManual: false
2020-01-08 20:11:01.809 Status: dzVents: > doorsensorOpenedAt: 0
2020-01-08 20:11:01.810 Status: dzVents: > doorbellPressedAt: 1578510661
2020-01-08 20:11:01.810 Status: dzVents: > initialize()
2020-01-08 20:11:01.814 Status: dzVents: Info: Deurbel: ------ Finished Deurbel
2020-01-08 20:11:01.846 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-01-08 20:11:02.353 Status: User: Admin initiated a switch command (98/Voordeur - Lamp/Set Level)
2020-01-08 20:12:02.373 Status: User: Admin initiated a switch command (98/Voordeur - Lamp/Set Level)
2020-01-08 20:12:11.513 Status: dzVents: Info: ------ Start internal script: Deurbel: Device: "Voordeur - Sensor (Zigbee2MQTT)", Index: 109
2020-01-08 20:12:11.523 Status: dzVents: Debug: Deurbel: Processing device-adapter for Voordeur - Lamp - Selector: Switch device adapter
2020-01-08 20:12:11.529 Status: dzVents: Debug: Deurbel: Processing device-adapter for Hal - Verlichting: Group device adapter
2020-01-08 20:12:11.537 Status: dzVents: Debug: Deurbel: Processing device-adapter for Voordeur - Bel: Switch device adapter
2020-01-08 20:12:11.538 Status: dzVents: Debug: Deurbel: Voordeur - Sensor is not active.
2020-01-08 20:12:11.538 Status: dzVents: Debug: Deurbel: Voordeur - Lamp - Selector state is 20%
2020-01-08 20:12:11.538 Status: dzVents: Debug: Deurbel: Hal - Verlichting state is Off
2020-01-08 20:12:11.539 Status: dzVents: Debug: Deurbel: Voordeur - Sensor state is Closed
2020-01-08 20:12:11.539 Status: dzVents: Debug: Deurbel: Voordeur - Bel state is Off
2020-01-08 20:12:11.539 Status: dzVents: Debug: Deurbel: ------ content of dz.data before script logic -----
2020-01-08 20:12:11.539 Status: dzVents: > initialize()
2020-01-08 20:12:11.540 Status: dzVents: > doorbellPressedAt: 1578510661
2020-01-08 20:12:11.540 Status: dzVents: > doorsensorOpenedAt: 0
2020-01-08 20:12:11.540 Status: dzVents: > hallwayLightManual: false
2020-01-08 20:12:11.541 Status: dzVents: Debug: Deurbel: Constructed timed-command: Set Level 20
2020-01-08 20:12:11.542 Status: dzVents: Debug: Deurbel: Constructed timed-command: Set Level 10
2020-01-08 20:12:11.546 Status: dzVents: Debug: Deurbel: Constructed timed-command: Set Level 10 AFTER 60 SECONDS
2020-01-08 20:12:11.547 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off
2020-01-08 20:12:11.548 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off AFTER 60 SECONDS
2020-01-08 20:12:11.549 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off AFTER 60 SECONDS NOTRIGGER
2020-01-08 20:12:11.550 Status: dzVents: Debug: Deurbel: Constructed timed-command: On
2020-01-08 20:12:11.551 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off
2020-01-08 20:12:11.552 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off AFTER 60 SECONDS
2020-01-08 20:12:11.552 Status: dzVents: Debug: Deurbel: ------ content of dz.data after script logic -----
2020-01-08 20:12:11.552 Status: dzVents: > initialize()
2020-01-08 20:12:11.553 Status: dzVents: > doorbellPressedAt: 1578510731
2020-01-08 20:12:11.553 Status: dzVents: > doorsensorOpenedAt: 0
2020-01-08 20:12:11.553 Status: dzVents: > hallwayLightManual: false
2020-01-08 20:12:11.557 Status: dzVents: Info: Deurbel: ------ Finished Deurbel
2020-01-08 20:12:11.576 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-01-08 20:12:12.081 Status: User: Admin initiated a switch command (98/Voordeur - Lamp/Set Level)
2020-01-08 20:13:12.108 Status: User: Admin initiated a switch command (98/Voordeur - Lamp/Set Level)
Also when I open the door without the doorbell beeing pressed, both the lights go on after closing the door.
Code: Select all
2020-01-08 20:18:48.919 Status: dzVents: Debug: Deurbel: Processing device-adapter for Voordeur - Bel: Switch device adapter
2020-01-08 20:18:48.920 Status: dzVents: Debug: Deurbel: Voordeur - Sensor is not active.
2020-01-08 20:18:48.921 Status: dzVents: Debug: Deurbel: Voordeur - Lamp - Selector state is 20%
2020-01-08 20:18:48.921 Status: dzVents: Debug: Deurbel: Hal - Verlichting state is Off
2020-01-08 20:18:48.921 Status: dzVents: Debug: Deurbel: Voordeur - Sensor state is Closed
2020-01-08 20:18:48.922 Status: dzVents: Debug: Deurbel: Voordeur - Bel state is Off
2020-01-08 20:18:48.922 Status: dzVents: Debug: Deurbel: ------ content of dz.data before script logic -----
2020-01-08 20:18:48.922 Status: dzVents: > doorsensorOpenedAt: 0
2020-01-08 20:18:48.922 Status: dzVents: > initialize()
2020-01-08 20:18:48.923 Status: dzVents: > doorbellPressedAt: 1578510731
2020-01-08 20:18:48.923 Status: dzVents: > hallwayLightManual: false
2020-01-08 20:18:48.924 Status: dzVents: Debug: Deurbel: Constructed timed-command: Set Level 20
2020-01-08 20:18:48.925 Status: dzVents: Debug: Deurbel: Constructed timed-command: Set Level 10
2020-01-08 20:18:48.930 Status: dzVents: Debug: Deurbel: Constructed timed-command: Set Level 10 AFTER 60 SECONDS
2020-01-08 20:18:48.930 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off
2020-01-08 20:18:48.931 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off AFTER 60 SECONDS
2020-01-08 20:18:48.932 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off AFTER 60 SECONDS NOTRIGGER
2020-01-08 20:18:48.933 Status: dzVents: Debug: Deurbel: Constructed timed-command: On
2020-01-08 20:18:48.934 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off
2020-01-08 20:18:48.935 Status: dzVents: Debug: Deurbel: Constructed timed-command: Off AFTER 60 SECONDS
2020-01-08 20:18:48.935 Status: dzVents: Debug: Deurbel: ------ content of dz.data after script logic -----
2020-01-08 20:18:48.936 Status: dzVents: > doorsensorOpenedAt: 0
2020-01-08 20:18:48.936 Status: dzVents: > initialize()
2020-01-08 20:18:48.936 Status: dzVents: > doorbellPressedAt: 1578511128
2020-01-08 20:18:48.937 Status: dzVents: > hallwayLightManual: false
2020-01-08 20:18:48.944 Status: dzVents: Info: Deurbel: ------ Finished Deurbel
2020-01-08 20:18:48.963 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua