There is my test script:
Code: Select all
function turnOff(domoticz)
local TestRelay = domoticz.devices('TestRelay')
TestRelay.switchOff().afterSec(30) -- XXXXXXXXXXXX
end
function turnOn(domoticz)
local TestRelay = domoticz.devices('TestRelay')
TestRelay.switchOn().afterSec(30) -- XXXXXXXXXXXX
end
return {
active = true, -- set to false to disable this script
logging = {
level = domoticz.LOG_DEBUG,
marker = "TEST"
},
on = {
devices = {
'abc' -- idx 28
},
timer = {
'every 1 minutes' -- YYYYYYYYYYYY
}
},
execute = function(domoticz, device, triggerInfo)
if (triggerInfo.type == domoticz.EVENT_TYPE_TIMER) then -- Timer triggered use
domoticz.log("event: EVENT_TYPE_TIMER")
elseif(triggerInfo.type == domoticz.EVENT_TYPE_DEVICE) then -- Device triggered use
domoticz.log("event: EVENT_TYPE_DEVICE")
end
local TestRelay = domoticz.devices('TestRelay')
local abc = domoticz.devices('abc')
if (abc.state == 'On') then
domoticz.log('turning on...')
turnOn(domoticz)
else
domoticz.log('turning off...')
turnOff(domoticz)
end
end
}
Code: Select all
2017-12-29 22:54:36.741 EventSystem: Write file: /home/domoticz/domoticz/scripts/dzVents/generated_scripts/test.lua
2017-12-29 22:54:44.469 User: martin initiated a switch command (28/abc/On)
2017-12-29 22:54:44.807 dzVents: Info: Handling events for: "abc", value: "On"
2017-12-29 22:54:44.807 dzVents: Info: TEST: ------ Start internal script: test: Device: "abc (front)", Index: 28
2017-12-29 22:54:44.808 dzVents: Info: TEST: event: EVENT_TYPE_DEVICE
2017-12-29 22:54:44.811 dzVents: Debug: TEST: Device-adapter found for TestRelay: Switch device adapter
2017-12-29 22:54:44.812 dzVents: Debug: TEST: Processing device-adapter for TestRelay: Switch device adapter
2017-12-29 22:54:44.813 dzVents: Info: TEST: turning on...
2017-12-29 22:54:44.813 dzVents: Debug: TEST: Constructed timed-command: On
2017-12-29 22:54:44.813 dzVents: Debug: TEST: Constructed timed-command: On AFTER 30
2017-12-29 22:54:44.814 dzVents: Info: TEST: ------ Finished test
2017-12-29 22:54:44.817 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-12-29 22:54:44.850 (front) Light/Switch (abc)
2017-12-29 22:55:00.232 dzVents: Info: TEST: ------ Start internal script: test:, trigger: every 1 minutes
2017-12-29 22:55:00.232 dzVents: Info: TEST: event: EVENT_TYPE_TIMER
2017-12-29 22:55:00.297 dzVents: Debug: TEST: Device-adapter found for TestRelay: Switch device adapter
2017-12-29 22:55:00.326 dzVents: Debug: TEST: Processing device-adapter for TestRelay: Switch device adapter
2017-12-29 22:55:00.329 dzVents: Debug: TEST: Device-adapter found for abc: Switch device adapter
2017-12-29 22:55:00.330 dzVents: Debug: TEST: Processing device-adapter for abc: Switch device adapter
2017-12-29 22:55:00.331 dzVents: Info: TEST: turning on...
2017-12-29 22:55:00.331 dzVents: Debug: TEST: Constructed timed-command: On
2017-12-29 22:55:00.331 dzVents: Debug: TEST: Constructed timed-command: On AFTER 30
2017-12-29 22:55:00.332 dzVents: Info: TEST: ------ Finished test
2017-12-29 22:55:00.335 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-12-29 22:55:30.745 (front) Light/Switch (TestRelay)
2017-12-29 22:55:31.162 User: Admin initiated a switch command (24/TestRelay/On)
2017-12-29 22:55:31.478 (front) Light/Switch (TestRelay)
Code: Select all
2017-12-29 22:51:40.367 User: Admin initiated a switch command (28/abc/On)
2017-12-29 22:51:40.700 dzVents: Info: Handling events for: "abc", value: "On"
2017-12-29 22:51:40.701 dzVents: Info: TEST: ------ Start internal script: test: Device: "abc (front)", Index: 28
2017-12-29 22:51:40.701 dzVents: Info: TEST: event: EVENT_TYPE_DEVICE
2017-12-29 22:51:40.704 dzVents: Debug: TEST: Device-adapter found for TestRelay: Switch device adapter
2017-12-29 22:51:40.705 dzVents: Debug: TEST: Processing device-adapter for TestRelay: Switch device adapter
2017-12-29 22:51:40.706 dzVents: Info: TEST: turning on...
2017-12-29 22:51:40.706 dzVents: Debug: TEST: Constructed timed-command: On
2017-12-29 22:51:40.706 dzVents: Debug: TEST: Constructed timed-command: On AFTER 120
2017-12-29 22:51:40.707 dzVents: Info: TEST: ------ Finished test
2017-12-29 22:51:40.710 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-12-29 22:51:40.744 (front) Light/Switch (abc)
2017-12-29 22:52:00.653 dzVents: Info: TEST: ------ Start internal script: test:, trigger: every 1 minutes
2017-12-29 22:52:00.654 dzVents: Info: TEST: event: EVENT_TYPE_TIMER
2017-12-29 22:52:00.720 dzVents: Debug: TEST: Device-adapter found for TestRelay: Switch device adapter
2017-12-29 22:52:00.749 dzVents: Debug: TEST: Processing device-adapter for TestRelay: Switch device adapter
2017-12-29 22:52:00.753 dzVents: Debug: TEST: Device-adapter found for abc: Switch device adapter
2017-12-29 22:52:00.754 dzVents: Debug: TEST: Processing device-adapter for abc: Switch device adapter
2017-12-29 22:52:00.754 dzVents: Info: TEST: turning on...
2017-12-29 22:52:00.754 dzVents: Debug: TEST: Constructed timed-command: On
2017-12-29 22:52:00.755 dzVents: Debug: TEST: Constructed timed-command: On AFTER 120
2017-12-29 22:52:00.755 dzVents: Info: TEST: ------ Finished test
2017-12-29 22:52:00.758 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-12-29 22:52:43.209 MQTT: Topic: domoticz/in, Message: { "idx" : 27, "nvalue" : 0, "svalue" : "19" }
2017-12-29 22:53:00.515 dzVents: Info: TEST: ------ Start internal script: test:, trigger: every 1 minutes
2017-12-29 22:53:00.515 dzVents: Info: TEST: event: EVENT_TYPE_TIMER
2017-12-29 22:53:00.580 dzVents: Debug: TEST: Device-adapter found for TestRelay: Switch device adapter
2017-12-29 22:53:00.613 dzVents: Debug: TEST: Processing device-adapter for TestRelay: Switch device adapter
2017-12-29 22:53:00.617 dzVents: Debug: TEST: Device-adapter found for abc: Switch device adapter
2017-12-29 22:53:00.618 dzVents: Debug: TEST: Processing device-adapter for abc: Switch device adapter
2017-12-29 22:53:00.618 dzVents: Info: TEST: turning on...
2017-12-29 22:53:00.618 dzVents: Debug: TEST: Constructed timed-command: On
2017-12-29 22:53:00.619 dzVents: Debug: TEST: Constructed timed-command: On AFTER 120
2017-12-29 22:53:00.619 dzVents: Info: TEST: ------ Finished test
2017-12-29 22:53:00.622 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-12-29 22:53:43.352 MQTT: Topic: domoticz/in, Message: { "idx" : 27, "nvalue" : 0, "svalue" : "19" }
2017-12-29 22:54:00.375 dzVents: Info: TEST: ------ Start internal script: test:, trigger: every 1 minutes
2017-12-29 22:54:00.375 dzVents: Info: TEST: event: EVENT_TYPE_TIMER
2017-12-29 22:54:00.441 dzVents: Debug: TEST: Device-adapter found for TestRelay: Switch device adapter
2017-12-29 22:54:00.469 dzVents: Debug: TEST: Processing device-adapter for TestRelay: Switch device adapter
2017-12-29 22:54:00.472 dzVents: Debug: TEST: Device-adapter found for abc: Switch device adapter
2017-12-29 22:54:00.473 dzVents: Debug: TEST: Processing device-adapter for abc: Switch device adapter
2017-12-29 22:54:00.474 dzVents: Info: TEST: turning on...
2017-12-29 22:54:00.474 dzVents: Debug: TEST: Constructed timed-command: On
2017-12-29 22:54:00.474 dzVents: Debug: TEST: Constructed timed-command: On AFTER 120
2017-12-29 22:54:00.475 dzVents: Info: TEST: ------ Finished test
How can I use timer "every 1 minutes" with switchOn().afterMin(2)?