Page 1 of 1
On FOR 10
Posted: Friday 07 December 2018 7:50
by DosN
I want to switch ON a light when a sensor is seeing a Motion
The light should be ON for lets say 10min
commandArray['MyOtherDeviceName4']='On FOR 10' -- minutes
this is working fine
But when this sensor is triggered again within these 10min, it should be ON for 10min again
When i start this instruction again it will not restart over ?
Re: On FOR 10
Posted: Saturday 08 December 2018 16:24
by Brutus
That's because the command to set the light off after 10 min is already been out there and can't be deleted with LUA
Re: On FOR 10
Posted: Saturday 08 December 2018 17:03
by SweetPants
Brutus wrote: ↑Saturday 08 December 2018 16:24
That's because the command to set the light off after 10 min is already been out there and can't be deleted.
I think you can in dz_Ventz using cancelQueuedCommands():
Re: On FOR 10
Posted: Sunday 09 December 2018 0:40
by DosN
i tested it again
when i use: commandArray['MyOtherDeviceName4']='On FOR 10' -- minutes
once is works fine
But when i used the command again withing this time( within those 10min) , it looks like the light is not going off at all
Re: On FOR 10
Posted: Sunday 09 December 2018 1:39
by tozzke
That's because you're just telling it to be on for 10 minutes, not for it to turn off after those 10 minutes

Perhaps depending on the version of Domoticz you're running, the 'on for x minutes' (or off for that matter) turns the light after the x minutes to the state it was at the moment of triggering. So if the light was off, it'll turn on and after x minutes it'll turn off again. Unless it's triggered again within those x minutes..... then the state will turn "back" to on after those x minutes because the light was on on the moment of the trigger.
Check the log of the light.. I'll bet it'll show 'On' twice

Re: On FOR 10
Posted: Sunday 09 December 2018 8:46
by mrf68
just let the script turn the light on. Then create a second script that checks the time difference between the last update of the motion sensor and the current time. If that difference is > 10 minutes AND the light is On then turn the light Off.
Re: On FOR 10
Posted: Sunday 09 December 2018 12:46
by DosN
Yes i can make a LUA script , but it is so must easier if i could used ON FOR 10min again
check motion sensor and switch on light (in a DEVICE LUA script)
check the time the light is on (in a a Time LUCA script)
Re: On FOR 10
Posted: Sunday 09 December 2018 13:08
by tozzke
You could also use this:
Code: Select all
commandArray[1]={['MyOtherDeviceName4']='On'}
commandArray[2]={['MyOtherDeviceName4']='Off AFTER 600'}
In the older versions of Domoticz, a retrigger within those 600 seconds will result in a reset of the 600 second timer. The newer versions however, don't as far as I know
Re: On FOR 10
Posted: Sunday 09 December 2018 22:33
by DosN
im running Version: 4.10038
and it looks like it still works
thx
Re: On FOR 10
Posted: Monday 10 December 2018 0:00
by Nautilus
tozzke wrote: ↑Sunday 09 December 2018 13:08
You could also use this:
Code: Select all
commandArray[1]={['MyOtherDeviceName4']='On'}
commandArray[2]={['MyOtherDeviceName4']='Off AFTER 600'}
In the older versions of Domoticz, a retrigger within those 600 seconds will result in a reset of the 600 second timer. The newer versions however, don't as far as I know
When did this change (in case you know)? I have a few lua scripts that rely on this to work the "old" way. Do you know what would be the correct way to do it now?
Re: On FOR 10
Posted: Monday 10 December 2018 11:17
by alanlsmith
As a different approach, have a device script to switch the light on every time that the sensor is triggered and then a time script to turn the light off when the sensor hasn't been triggered again after a given time. That way the 'time to off' is effectively reset each time the sensor is triggered.
script_device_sensor.lua
Code: Select all
commandArray = {}
local sensor = 'My_PIR'
local light = 'My_Light
if(devicechanged[sensor] == 'On') then
commandArray[#commandArray+1] = {[light] = 'On'}
end
return commandArray
.
script_time_check_sensor.lua
Code: Select all
time = os.date("*t")
function timedifference (s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
commandArray = {}
local sensor = 'My_PIR'
local light = 'My_Light'
local lasttrigger = myFunc.timedifference(otherdevices_lastupdate[sensor])
duration = 600 --10 minutes
if(otherdevices[sensor] == 'On') then
if(lasttrigger > duration) then
commandArray[#commandArray+1] = {[light] = 'Off'}
end
end
return commandArray