afterMin interval cannot be greater than timer interval

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
tuxmartin
Posts: 11
Joined: Wednesday 06 September 2017 12:47
Target OS: Linux
Domoticz version:
Location: CZ
Contact:

afterMin interval cannot be greater than timer interval

Post by tuxmartin »

Hi, I have problem with afterMin/sec and timer.
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
}
If I have interval of afterSec (XXXXXXXXXXXX) lower than value of timer (YYYYYYYYYYYY), it works great:

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)
But if I change value of afterSec (XXXXXXXXXXXX) to 120s and keep timer interval "every 1 minutes", it stop working:

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
I need some condition like "if switch already turning on after 30s, do not turn on again".
How can I use timer "every 1 minutes" with switchOn().afterMin(2)?
SweetPants

Re: afterMin interval cannot be greater than timer interval

Post by SweetPants »

add checkFirst() to your switch command. It will check the state and if already on/off it does nothing.
tuxmartin
Posts: 11
Joined: Wednesday 06 September 2017 12:47
Target OS: Linux
Domoticz version:
Location: CZ
Contact:

Re: afterMin interval cannot be greater than timer interval

Post by tuxmartin »

SweetPants wrote: Saturday 30 December 2017 10:24 add checkFirst() to your switch command. It will check the state and if already on/off it does nothing.

It's not possible to use checkFirst() with afterSec():

Code: Select all

		TestRelay.switchOff().checkFirst().afterSec(30)
2017-12-31 22:04:30.884 dzVents: Info: TEST: ------ Start internal script: test: Device: "abc (front)", Index: 28
2017-12-31 22:04:30.884 dzVents: Info: TEST: event: EVENT_TYPE_DEVICE
2017-12-31 22:04:30.887 dzVents: Debug: TEST: Device-adapter found for TestRelay: Switch device adapter
2017-12-31 22:04:30.888 dzVents: Debug: TEST: Processing device-adapter for TestRelay: Switch device adapter
2017-12-31 22:04:30.889 dzVents: Debug: TEST: Constructed timed-command: Off
2017-12-31 22:04:30.890 Error: dzVents: Error: TEST: An error occured when calling event handler test
2017-12-31 22:04:30.890 Error: dzVents: Error: TEST: ...ticz/domoticz/scripts/dzVents/generated_scripts/test.lua:41: attempt to call field 'checkFirst' (a nil value)
2017-12-31 22:04:30.890 dzVents: Info: TEST: ------ Finished test

		TestRelay.switchOff().afterSec(30).checkFirst()
2017-12-31 22:05:07.452 dzVents: Info: Handling events for: "abc", value: "Off"
2017-12-31 22:05:07.452 dzVents: Info: TEST: ------ Start internal script: test: Device: "abc (front)", Index: 28
2017-12-31 22:05:07.452 dzVents: Info: TEST: event: EVENT_TYPE_DEVICE
2017-12-31 22:05:07.456 dzVents: Debug: TEST: Device-adapter found for TestRelay: Switch device adapter
2017-12-31 22:05:07.457 dzVents: Debug: TEST: Processing device-adapter for TestRelay: Switch device adapter
2017-12-31 22:05:07.457 dzVents: Debug: TEST: Constructed timed-command: Off
2017-12-31 22:05:07.457 dzVents: Debug: TEST: Constructed timed-command: Off AFTER 30
2017-12-31 22:05:07.458 Error: dzVents: Error: TEST: An error occured when calling event handler test
2017-12-31 22:05:07.458 Error: dzVents: Error: TEST: ...ticz/domoticz/scripts/dzVents/generated_scripts/test.lua:41: attempt to call field 'checkFirst' (a nil value)
2017-12-31 22:05:07.458 dzVents: Info: TEST: ------ Finished test
I add more logging to my script:

Code: Select all

function turnOff(domoticz)
    local TestRelay = domoticz.devices('TestRelay')
    domoticz.log("1 turnOff function, " .. "TestRelay status " .. tostring(TestRelay.state))
    TestRelay.switchOff().afterSec(180) -- XXXXXXXXXXXX
    domoticz.log("2 turnOff function, " .. "TestRelay status " .. tostring(TestRelay.state))
end

function turnOn(domoticz)
    local TestRelay = domoticz.devices('TestRelay')
    domoticz.log("1 turnOn function, " .. "TestRelay status " .. tostring(TestRelay.state))
    TestRelay.switchOn().afterSec(180) -- XXXXXXXXXXXX
    domoticz.log("2 turnOn function, " .. "TestRelay status " .. tostring(TestRelay.state))
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
}
And there is output:

Code: Select all

2017-12-31 22:07:11.537 EventSystem: Write file: /home/domoticz/domoticz/scripts/dzVents/generated_scripts/test.lua
2017-12-31 22:07:12.711 MQTT: Topic: domoticz/in, Message: { "idx" : 27, "nvalue" : 0, "svalue" : "16" }
2017-12-31 22:07:16.168 User: martin initiated a switch command (28/abc/On)
2017-12-31 22:07:16.503 dzVents: Info: Handling events for: "abc", value: "On"
2017-12-31 22:07:16.504 dzVents: Info: TEST: ------ Start internal script: test: Device: "abc (front)", Index: 28
2017-12-31 22:07:16.504 dzVents: Info: TEST: event: EVENT_TYPE_DEVICE
2017-12-31 22:07:16.507 dzVents: Debug: TEST: Device-adapter found for TestRelay: Switch device adapter
2017-12-31 22:07:16.508 dzVents: Debug: TEST: Processing device-adapter for TestRelay: Switch device adapter
2017-12-31 22:07:16.509 dzVents: Info: TEST: turning on...
2017-12-31 22:07:16.509 dzVents: Info: TEST: 1 turnOn function, TestRelay status Off
2017-12-31 22:07:16.509 dzVents: Debug: TEST: Constructed timed-command: On
2017-12-31 22:07:16.510 dzVents: Debug: TEST: Constructed timed-command: On AFTER 180
2017-12-31 22:07:16.510 dzVents: Info: TEST: 2 turnOn function, TestRelay status Off
2017-12-31 22:07:16.510 dzVents: Info: TEST: ------ Finished test
2017-12-31 22:07:16.513 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-12-31 22:07:16.547 (front) Light/Switch (abc)
2017-12-31 22:07:30.847 (front) Light/Switch (TestRelay)
2017-12-31 22:07:55.050 dzVents: WU Script Parsed Temp=11.8 Humidity=54 Pressure=1
2017-12-31 22:07:55.070 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/lua/script_device_DHT22.lua
2017-12-31 22:08:00.713 dzVents: Info: TEST: ------ Start internal script: test:, trigger: every 1 minutes
2017-12-31 22:08:00.713 dzVents: Info: TEST: event: EVENT_TYPE_TIMER
2017-12-31 22:08:00.780 dzVents: Debug: TEST: Device-adapter found for TestRelay: Switch device adapter
2017-12-31 22:08:00.795 dzVents: Debug: TEST: Processing device-adapter for TestRelay: Switch device adapter
2017-12-31 22:08:00.797 dzVents: Debug: TEST: Device-adapter found for abc: Switch device adapter
2017-12-31 22:08:00.798 dzVents: Debug: TEST: Processing device-adapter for abc: Switch device adapter
2017-12-31 22:08:00.798 dzVents: Info: TEST: turning on...
2017-12-31 22:08:00.798 dzVents: Info: TEST: 1 turnOn function, TestRelay status Off
2017-12-31 22:08:00.798 dzVents: Debug: TEST: Constructed timed-command: On
2017-12-31 22:08:00.798 dzVents: Debug: TEST: Constructed timed-command: On AFTER 180
2017-12-31 22:08:00.798 dzVents: Info: TEST: 2 turnOn function, TestRelay status Off
2017-12-31 22:08:00.799 dzVents: Info: TEST: ------ Finished test
2017-12-31 22:08:00.801 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-12-31 22:08:12.851 MQTT: Topic: domoticz/in, Message: { "idx" : 27, "nvalue" : 0, "svalue" : "16" }
2017-12-31 22:08:55.855 dzVents: WU Script Parsed Temp=11.8 Humidity=54 Pressure=1
2017-12-31 22:08:55.879 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/lua/script_device_DHT22.lua
2017-12-31 22:09:00.522 dzVents: Info: TEST: ------ Start internal script: test:, trigger: every 1 minutes
2017-12-31 22:09:00.522 dzVents: Info: TEST: event: EVENT_TYPE_TIMER
2017-12-31 22:09:00.556 dzVents: Debug: TEST: Device-adapter found for TestRelay: Switch device adapter
2017-12-31 22:09:00.570 dzVents: Debug: TEST: Processing device-adapter for TestRelay: Switch device adapter
2017-12-31 22:09:00.572 dzVents: Debug: TEST: Device-adapter found for abc: Switch device adapter
2017-12-31 22:09:00.573 dzVents: Debug: TEST: Processing device-adapter for abc: Switch device adapter
2017-12-31 22:09:00.573 dzVents: Info: TEST: turning on...
2017-12-31 22:09:00.573 dzVents: Info: TEST: 1 turnOn function, TestRelay status Off
2017-12-31 22:09:00.573 dzVents: Debug: TEST: Constructed timed-command: On
2017-12-31 22:09:00.574 dzVents: Debug: TEST: Constructed timed-command: On AFTER 180
2017-12-31 22:09:00.574 dzVents: Info: TEST: 2 turnOn function, TestRelay status Off
2017-12-31 22:09:00.574 dzVents: Info: TEST: ------ Finished test
2017-12-31 22:09:00.575 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-12-31 22:09:12.992 MQTT: Topic: domoticz/in, Message: { "idx" : 27, "nvalue" : 0, "svalue" : "15" }
2017-12-31 22:09:56.664 dzVents: WU Script Parsed Temp=11.8 Humidity=54 Pressure=1
2017-12-31 22:09:56.690 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/lua/script_device_DHT22.lua
2017-12-31 22:10:00.221 dzVents: Info: TEST: ------ Start internal script: test:, trigger: every 1 minutes
2017-12-31 22:10:00.221 dzVents: Info: TEST: event: EVENT_TYPE_TIMER
2017-12-31 22:10:00.255 dzVents: Debug: TEST: Device-adapter found for TestRelay: Switch device adapter
2017-12-31 22:10:00.270 dzVents: Debug: TEST: Processing device-adapter for TestRelay: Switch device adapter
2017-12-31 22:10:00.271 dzVents: Debug: TEST: Device-adapter found for abc: Switch device adapter
2017-12-31 22:10:00.272 dzVents: Debug: TEST: Processing device-adapter for abc: Switch device adapter
2017-12-31 22:10:00.272 dzVents: Info: TEST: turning on...
2017-12-31 22:10:00.272 dzVents: Info: TEST: 1 turnOn function, TestRelay status Off
2017-12-31 22:10:00.272 dzVents: Debug: TEST: Constructed timed-command: On
2017-12-31 22:10:00.273 dzVents: Debug: TEST: Constructed timed-command: On AFTER 180
2017-12-31 22:10:00.273 dzVents: Info: TEST: 2 turnOn function, TestRelay status Off
2017-12-31 22:10:00.273 dzVents: Info: TEST: ------ Finished test
2017-12-31 22:10:00.275 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-12-31 22:10:13.135 MQTT: Topic: domoticz/in, Message: { "idx" : 27, "nvalue" : 0, "svalue" : "17" }
2017-12-31 22:10:57.462 dzVents: WU Script Parsed Temp=11.8 Humidity=54 Pressure=1
2017-12-31 22:10:57.486 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/lua/script_device_DHT22.lua
2017-12-31 22:11:00.426 dzVents: Info: TEST: ------ Start internal script: test:, trigger: every 1 minutes
2017-12-31 22:11:00.426 dzVents: Info: TEST: event: EVENT_TYPE_TIMER
2017-12-31 22:11:00.461 dzVents: Debug: TEST: Device-adapter found for TestRelay: Switch device adapter
2017-12-31 22:11:00.475 dzVents: Debug: TEST: Processing device-adapter for TestRelay: Switch device adapter
2017-12-31 22:11:00.477 dzVents: Debug: TEST: Device-adapter found for abc: Switch device adapter
2017-12-31 22:11:00.478 dzVents: Debug: TEST: Processing device-adapter for abc: Switch device adapter
2017-12-31 22:11:00.478 dzVents: Info: TEST: turning on...
2017-12-31 22:11:00.478 dzVents: Info: TEST: 1 turnOn function, TestRelay status Off
2017-12-31 22:11:00.479 dzVents: Debug: TEST: Constructed timed-command: On
2017-12-31 22:11:00.479 dzVents: Debug: TEST: Constructed timed-command: On AFTER 180
2017-12-31 22:11:00.479 dzVents: Info: TEST: 2 turnOn function, TestRelay status Off
2017-12-31 22:11:00.479 dzVents: Info: TEST: ------ Finished test
2017-12-31 22:11:00.481 EventSystem: Script event triggered: /home/domoticz/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-12-31 22:11:13.272 MQTT: Topic: domoticz/in, Message: { "idx" : 27, "nvalue" : 0, "svalue" : "18" }
After call switchOn().afterSec(180) switch is still off (it sounds logic) log: "2 turnOn function, TestRelay status Off".
But how can I test if switch will be enabled?

Code: Select all

function turnOn(domoticz)
    local TestRelay = domoticz.devices('TestRelay')
    domoticz.log("1 turnOn function, " .. "TestRelay status " .. tostring(TestRelay.state))
    TestRelay.switchOn().afterSec(180) -- XXXXXXXXXXXX
    domoticz.log("2 turnOn function, " .. "TestRelay status " .. tostring(TestRelay.state))
end

2017-12-31 22:09:00.573 dzVents: Info: TEST: 1 turnOn function, TestRelay status Off
2017-12-31 22:09:00.573 dzVents: Debug: TEST: Constructed timed-command: On
2017-12-31 22:09:00.574 dzVents: Debug: TEST: Constructed timed-command: On AFTER 180
2017-12-31 22:09:00.574 dzVents: Info: TEST: 2 turnOn function, TestRelay status Off
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: afterMin interval cannot be greater than timer interval

Post by dannybloe »

Well, I haven't exactly examined all your logs but I can say a few things. First of all, checkFirst() only checks the current state so that indeed doesn't help you here. Secondly, there is currently no way to know if there are queued commands in Domoticz' scheduler. So you need to do something extra here to make sure you only send the on-command once. What I normally do in situations like this is create a persistent variable in my script that is basically a flag telling me that the command has been issued.

Code: Select all

return  {
	on = { ..},
	data = {
		onIssued = { initial = false },
		offIssued = { initial = false }
	},
	execute = function(domoticz, item)
		
		...
		if (abc.state == 'On' and domoticz.data.onIssued == false) then
		    domoticz.log('turning on...')
		    domoticz.data.onIssued = true
		    turnOn(domoticz)
		elseif (domoticz.data.offIssued == false) then
		    domoticz.log('turning off...')
		    domoticz.data.offIssued = true
		    turnOff(domoticz)
		end
		
	end
	
}
Just to give you an idea.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
tuxmartin
Posts: 11
Joined: Wednesday 06 September 2017 12:47
Target OS: Linux
Domoticz version:
Location: CZ
Contact:

Re: afterMin interval cannot be greater than timer interval

Post by tuxmartin »

Thank you. It works.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests