We have moved at community.getvera.com

Author Topic: motion trigger event once a day  (Read 2516 times)

Offline daiz

  • Sr. Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
motion trigger event once a day
« on: August 23, 2011, 09:56:03 am »
Hi all

i'm trying to come up with a scene, where a shade will be fully opened if motion is detected in the room, BUT it must be once/day, after motion is detected and shade is opened, further motion detection will not re-activate this scene.

all help is appreciated.

thanks

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: motion trigger event once a day
« Reply #1 on: August 23, 2011, 10:31:20 am »
Hi daiz,

Put this code in the scene that opens the shade and replace <shade_device_number> with the actual shade device number. This will allow this scene to run only once in 24 hours.

Code: [Select]
local DEVICE_NO = <shade_device_number>
local CUSTOM_SID = "urn:micasaverde-com:serviceId:CustomService1"

local lastRun = tonumber (luup.variable_get (CUSTOM_SID, "LastRun", DEVICE_NO)) or 0
local currTime = os.time()
if (os.difftime (currTime, lastRun) < 86400) then
return false
end

luup.variable_set (CUSTOM_SID, "LastRun", currTime, DEVICE_NO)
return true

Offline daiz

  • Sr. Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
Re: motion trigger event once a day
« Reply #2 on: August 24, 2011, 07:55:24 am »
hi

thanks for that, but it didn't work, still the scene was triggered again (2nd time) when motion was detected.

let me provide more details, might be irrelevant, but

i have 3 scenesfor this shade to open when motion is detected and then other scenes will drop a % depending on sunset time.

this will not work if say i leave the office for lunch and come back at noon where it will be half open and as i walk in it will fully open again.

thanks


Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: motion trigger event once a day
« Reply #3 on: August 24, 2011, 08:21:38 am »
If you put this code in all the scenes that open the shades, it should work. The LastRun variable is assigned to the shades device, which means that you can put this code any number of scenes, and it will allow only on of the scenes to run, and only once, in an interval of 24 hours.

Offline daiz

  • Sr. Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
Re: motion trigger event once a day
« Reply #4 on: August 25, 2011, 06:57:40 am »
is there anything to repalce other than <shade_device_number> ?

i tried it several time in one scene, the one that opens the shade 100% if motion is detected.

should i change anythign in the secene commands or the event ?

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: motion trigger event once a day
« Reply #5 on: August 25, 2011, 09:06:14 am »
is there anything to repalce other than <shade_device_number> ?
No. And for the code to work correctly you must put it in all the scenes that close or open the shades.

Offline daiz

  • Sr. Newbie
  • *
  • Posts: 22
  • Karma: +0/-0
Re: motion trigger event once a day
« Reply #6 on: August 29, 2011, 04:58:02 am »
tried that too, code is in all scenes for this device, didn't work, the scene works every time movement is detected.

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: motion trigger event once a day
« Reply #7 on: August 30, 2011, 07:48:40 am »
I think I know why it doesn't work.

Please replace this line:
local lastRun = tonumber (luup.variable_get (CUSTOM_SID, "LastRun", DEVICE_NO))
with this:
local lastRun = tonumber (luup.variable_get (CUSTOM_SID, "LastRun", DEVICE_NO, 10))

and let me know if it now works.