How to use a Trigger ID?
Posted: Monday 23 September 2019 13:38
Hi all,
I'm new to dzvents and scripting in general. In other words, I'm a real NOOB in scripting
. But I like to learn to create scripts in dzvents, because is has some real potential
. I received some scripts from colleagues and try to recreate a script based on their examples. I'm trying to write a script to turn on the stairs lights when motion is detected and turn them off after a short period. I would like to use multiple triggers in the script and based on the trigger execute a command. In the example I've received, he uses the command 'if (trigger.id == IDSM) then' (this works on his Domoticz
). However, it doesn't work in my script. Can somebody help me with this?
The code I made so far (not finished yet)
My log is showing the following:
2019-09-23 13:22:52.995 Status: dzVents: Info: Handling events for: "Trap sensor - Burglar", value: "On"
2019-09-23 13:22:52.995 Status: dzVents: Info: ------ Start internal script: Lights stairs: Device: "Trap sensor - Burglar (zwave)", Index: 67
2019-09-23 13:22:52.998 Status: dzVents: Info: ------ Finished Lights stairs
I'm running the latest version of domoticz:
Version: 4.11333
Build Hash: b2a5d9097
Compile Date: 2019-09-20 16:31:36
dzVents Version: 2.4.29
Python Version: 3.4.2 (default, Aug 18 2019, 00:35:45) [GCC 4.9.2]
Thanks in advance!
I'm new to dzvents and scripting in general. In other words, I'm a real NOOB in scripting
The code I made so far (not finished yet)
Code: Select all
--[[
SCRIPT DESCRIPTION:
This script turns the stairs lights on or off when there is motion and it's dark.
The lights will be turned off automatically after a period off time.
DEVICES USED:
Idx 67 = Trap sensor - Burglar
Idx 75 = Trapverlichting - Switch
Idx 22 = Daglicht
]]--
--SET USER INPUT VARIABLES:
IDSM = 67
IDSS = 75
IDDL = 22
SECSTOFF = 60 --turn off the stairs lights switch after xx seconds.
return {
active = true,
on = {
devices = {
IDSM,
IDSS,
},
},
execute = function(domoticz, triggeredItem, info)
--SET VARIABLES:
local STAIRSMOTION = domoticz.devices(IDSM)
local STAIRSSWITCH = domoticz.devices(IDSS)
local DAYLIGHTSWITCH = domoticz.devices(IDDL)
-- EXECUTE SCRIPT
if (trigger.id == IDSM) then
domoticz.log('Stairs: There is motion in the dark, let me turn on the lights for you')
STAIRSSWITCH.switchOn()
end
end
}
2019-09-23 13:22:52.995 Status: dzVents: Info: Handling events for: "Trap sensor - Burglar", value: "On"
2019-09-23 13:22:52.995 Status: dzVents: Info: ------ Start internal script: Lights stairs: Device: "Trap sensor - Burglar (zwave)", Index: 67
2019-09-23 13:22:52.998 Status: dzVents: Info: ------ Finished Lights stairs
I'm running the latest version of domoticz:
Version: 4.11333
Build Hash: b2a5d9097
Compile Date: 2019-09-20 16:31:36
dzVents Version: 2.4.29
Python Version: 3.4.2 (default, Aug 18 2019, 00:35:45) [GCC 4.9.2]
Thanks in advance!