On FOR 10

Post Reply
DosN
Posts: 21
Joined: Monday 29 January 2018 8:58
Target OS: Raspberry Pi
Domoticz version:
Contact:

On FOR 10

Post by DosN » Friday 07 December 2018 8:50

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: 326
Joined: Friday 26 September 2014 9:33
Target OS: Windows
Domoticz version:
Location: Heerlen, The Netherlands
Contact:

Re: On FOR 10

Post by Brutus » Saturday 08 December 2018 17:24

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 18:12, edited 1 time in total.
1x Intel NUC D54250WYK (Windows 7 x64)
1x Aeon Labs USB Z-Stick S2
1x P1 Smart Meter USB
19x Fibaro Modules

SweetPants
Posts: 2409
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10278
Location: The Netherlands
Contact:

Re: On FOR 10

Post by SweetPants » Saturday 08 December 2018 18:03

Brutus wrote:
Saturday 08 December 2018 17: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():
Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

DosN
Posts: 21
Joined: Monday 29 January 2018 8:58
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: On FOR 10

Post by DosN » Sunday 09 December 2018 1:40

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: 141
Joined: Friday 02 January 2015 10:22
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: On FOR 10

Post by tozzke » Sunday 09 December 2018 2:39

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

User avatar
mrf68
Posts: 277
Joined: Monday 23 February 2015 13:45
Target OS: Windows
Domoticz version: 3.4834
Location: Netherlands
Contact:

Re: On FOR 10

Post by mrf68 » Sunday 09 December 2018 9:46

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: 21
Joined: Monday 29 January 2018 8:58
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: On FOR 10

Post by DosN » Sunday 09 December 2018 13:46

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: 141
Joined: Friday 02 January 2015 10:22
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: On FOR 10

Post by tozzke » Sunday 09 December 2018 14: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

DosN
Posts: 21
Joined: Monday 29 January 2018 8:58
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: On FOR 10

Post by DosN » Sunday 09 December 2018 23:33

im running Version: 4.10038

and it looks like it still works
thx

Nautilus
Posts: 792
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi
Domoticz version: beta
Location: Finland
Contact:

Re: On FOR 10

Post by Nautilus » Monday 10 December 2018 1:00

tozzke wrote:
Sunday 09 December 2018 14: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: 124
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 » Monday 10 December 2018 12:17

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 β, Ubuntu 18.04 on Intel NUC i3, 8Gb ram, 70Gb drive, RFXtrx433, z-wave and a bit of Broadlink/Android

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests