Lua PIR problem - Switching off too early

Moderator: leecollings

Post Reply
Lorccan
Posts: 32
Joined: Wednesday 21 December 2016 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Lua PIR problem - Switching off too early

Post by Lorccan »

Hi

I have a PIR PIRCeiling and a script script_device_PIRCeiling.lua that should be updating a user variable TIMERCeiling to the value of a var ceilingTimer each time it switches to 'On'. If the switch Ceiling is not already 'On', it should switch it on.

Code: Select all

commandArray={}
ceilingTimer=6
if (deviceChanged['PIRCeiling']=='On' then
	if (other devices['Ceiling']=='Off') then
		commandArray['Ceiling']='On'
	end
	commandArray['Variable:TIMERCeiling']=tostring(ceilingTimer)
end
return commandArray
A timer script script_time_Ceiling.lua should check the value of the user variable TIMERCeiling each time it fires and if it equals 1 should switch-off Ceiling. Otherwise, it should decrement TIMERCeiling by 1.

Code: Select all

commandArray={}
if (uservariables['TIMERCeiling']==1) then
	if (otherdevices['Ceiling']=='On') then
                commandArray['Ceiling']='Off'
        end
else
        commandArray['Variable:TIMERCeiling']=tostring(uservariables['TIMERCeiling']-1)
end
return commandArray
So, the theory is that each time there's a movement, TIMERCeiling is reset to 6 and if no movement is detected for 5-6 minutes Ceiling should be switched off.

The problem is that although the switch on happens correctly (but with a few seconds delay - any ideas about that would be welcome), even though there's significant movement that seems to be triggering the PIR, the timer is switching off the light before people leave the room. Any ideas please? (I'm hoping there's something really stupid that I am missing here, so please be brutal! :) )
User avatar
lonebaggie
Posts: 86
Joined: Tuesday 31 January 2017 13:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: England
Contact:

Re: Lua PIR problem - Switching off too early

Post by lonebaggie »

For whatever reason your time script is being called more than once a minute why not use

commandArray["Ceiling"]='On" For 6

in your main script and drop the the second script all together
User avatar
Mooseknuckle
Posts: 43
Joined: Sunday 08 March 2015 9:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua PIR problem - Switching off too early

Post by Mooseknuckle »

This is what I do with my kitchen light:
Script_device_whatever

Code: Select all

if devicechanged['Motion kitchen'] == 'On' and otherdevices['is dark'] == 'On' and otherdevices['kitchen lights'] == 'Off' then
      commandArray['kitchen lights']= 'On'
      print('Movement in kitchen, lights go on')
Script_time_whatever

Code: Select all

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
time = os.date("*t")
commandArray = {}
if otherdevices['kitchen lights'] == 'On' then
 if timedifference(otherdevices_lastupdate['Motion kitchen']) > 300 then
     commandArray['Milight keuken']='Off'
     print('No motion for 5 minutes, kitchen lights go off')
 end
end
return commandArray
The lights now go out after 5 minutes and not when the pir stops detecting movement after 2 minutes (in my case). Maybe this will help :)
RPI 3, Philips Hue,Toon Thermostat, Harmony Smart Control, Yeelights
Mysensors wifi gateway + sensors, RFXtrx433E, Kaku stuff, Xiaomi gateway + sensors
Domoticz controlled DIY ambilight, Selectplus chime, Mi-light led controller
Lorccan
Posts: 32
Joined: Wednesday 21 December 2016 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua PIR problem - Switching off too early

Post by Lorccan »

Sorry for the delay in responding. I have reached the conclusion that the problem I am having is nothing to do with the scripts, but with the PIRs I have tried to detect continuous movement.

The first one, Philips Hue Motion detector, was too 'clever' and seemed to cache the last movement (last updated) data at the sensor instead of sending an update, so this could not be used in a script.

I then tried another from Friedland (DC44) which has its own problem: it goes to sleep for two minutes each time it detects movement and the sleep time is extended for another two minutes when further movement is detected (so far as I can tell without updating the date/time of the last movement), so it's pretty useless for my purposes.

May I ask which PIR you are using with your script please?
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Lua PIR problem - Switching off too early

Post by Egregius »

Don't they both remain 'On' during that time? At least a Fibaro does that...
Lorccan
Posts: 32
Joined: Wednesday 21 December 2016 10:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua PIR problem - Switching off too early

Post by Lorccan »

Well that's another strange thing: the Friedland one (which I am concentrating on) never seems to go 'On' so far as domoticz is concerned - it's just updating the 'Last Seen', but it doesn't do that when it's sleeping.

I am not keen to start using Fibaro as I don't have z-wave and don't really want to add it. Do you know of any other straightforward PIRs that simply report movement when they see it? (I have both RFXTRX433e & RFLink if that makes any difference.)
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Lua PIR problem - Switching off too early

Post by freijn »

use an ESP8826 Arduino with a Pir connected. THen you can decide everything yourself :-)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest