Page 1 of 1

on for, on for makes it ON forever, BUG?

Posted: Wednesday 27 September 2017 8:08
by ensingg
Hi,

I am using a magnetic switch on a garden gate to switch on a lamp.
When the switch changes I sent an On FOR 10 to the lamp.
But now it seems that when the gate changes 2 times within the 10 minutes, the lamp keeps ON forever.

Is this a bug?
What can I do to workaround?

Re: on for, on for makes it ON forever, BUG?

Posted: Wednesday 27 September 2017 8:41
by Nautilus
The "On FOR" basically sets the switch to "On" status and then returns to original status after the given time period. If the switch is already on when "On FOR" command is given (as it is the case for the second trigger) then it will not turn off at all. You need to use two commands in your script, a plain "On" command followed by a "Off AFTER" command (which is is seconds I think, so use "Off AFTER 600"). Hope this helps... :)

Re: on for, on for makes it ON forever, BUG?

Posted: Wednesday 27 September 2017 8:56
by ensingg
Can I do this in one command-array :

commandArray[#commandArray + 1] = {['Device_1']='On'} ...
commandArray[#commandArray + 1] = {['Device_1']=Off Ater'} ...

Re: on for, on for makes it ON forever, BUG?

Posted: Wednesday 27 September 2017 9:01
by emme
are you sure the contact is well positioned? could it be that it 'flaps' (sorry, cannot figure out another word to explain it better :P) so it keeps change state on/off?

the complete script test the state change or the value in a specific moment?

try dzVents:

Code: Select all

return {
	on = {
		devices = { 'myGardenDoor'},
	},

	execute = function(domoticz, device)
		if (device.state == 'On') then
			domoticz.devices('myGardenLamp').switchOn().for_min(10)
			domoticz.notify('Garden info - The light is on',domoticz.LOG_FORCE)
		end
	end
}
then check the log to see if it fires continuosly
ciao
M

Re: on for, on for makes it ON forever, BUG?

Posted: Wednesday 27 September 2017 9:18
by Nautilus
ensingg wrote: Wednesday 27 September 2017 8:56 Can I do this in one command-array :

commandArray[#commandArray + 1] = {['Device_1']='On'} ...
commandArray[#commandArray + 1] = {['Device_1']=Off Ater'} ...
Correct, this kind of syntax should work in Lua (well, the amount of seconds is missing of course but I guess that was on purpose). You can of course use dzVents or Blockly as well, choose the one you like best...:) However, I disagree with emme of the reason behind this, I think it is quite clear that the nature of "On FOR" results to this when the switch re-triggers in a situation when it is already on...:)

But as emme suggests, one option is to check the witch state before giving the command so that "On FOR" would be triggered only when the switch is Off. However, this can result to the light turning of when you are still doing something in the yard as the timer does not reset to 10 minutes when you go through the gate if the light is already on. So I'd just stick with the "On" + "Off AFTER" option.