On FOR 10

Moderator: leecollings

Post Reply
DosN
Posts: 49
Joined: Monday 29 January 2018 7:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

On FOR 10

Post 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 ?
User avatar
Brutus
Posts: 249
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Netherlands
Contact:

Re: On FOR 10

Post 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
Last edited by Brutus on Saturday 08 December 2018 17:12, edited 1 time in total.
1x Intel NUC8i5BEK (Windows 10 x64) Domoticz on Virtualbox with DietPi.
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
28x Fibaro Modules
SMA Solar System
Daikin Airco / Heating
Denon DHT-S716H & DSW-1H
SweetPants

Re: On FOR 10

Post 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():
DosN
Posts: 49
Joined: Monday 29 January 2018 7:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: On FOR 10

Post 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
tozzke
Posts: 135
Joined: Friday 02 January 2015 9:22
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: On FOR 10

Post 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 :)
mrf68

Re: On FOR 10

Post 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.
DosN
Posts: 49
Joined: Monday 29 January 2018 7:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: On FOR 10

Post 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)
tozzke
Posts: 135
Joined: Friday 02 January 2015 9:22
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: On FOR 10

Post 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
DosN
Posts: 49
Joined: Monday 29 January 2018 7:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: On FOR 10

Post by DosN »

im running Version: 4.10038

and it looks like it still works
thx
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: On FOR 10

Post 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?
alanlsmith
Posts: 132
Joined: Monday 07 August 2017 17:17
Target OS: Linux
Domoticz version: Latest β
Location: Near London (Saaarf!)
Contact:

Re: On FOR 10

Post 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
Domoticz Latest β, RPi 4B with 110Gb SSD for Domoticz, RPi 4B with 110Gb SSD for Node-Red & a RPi 2B for logging / IP addressing. RFXCOM, PiZiGate, Z-Wave, Harmony, Hue lamps and a bit of Broadlink.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest