I have some multi-sensor psp01 from philio-tech. They have temperature, motion, and light sensors. I have created a scene to turn on the light if the light level is below a certain point. The problem seems to be that when the sensor is tripped the Vera begins to run the scene before it has updated the light level. Now I thought about putting a delay in the script to give it time, but who wants that sort of delay. It looks like the delay is about 40 msecs. Any ideas on how to compensate or delay for msecs?
Pertinent logs:
07 03/03/15 19:19:25.041 Event::Evaluate 40 Motion kitchen scene Kitchen light motion is true users:(null) allow:1 <0x2b63f680>
08 03/03/15 19:19:25.041 Scene::RunScene running 53 Kitchen light motion <0x2b63f680>
50 03/03/15 19:19:25.041 luup_log:0: Beginning scene 53 - Motion in Kitchen <0x2b63f680>
50 03/03/15 19:19:25.042 luup_log:0: Light level in kitchen 6 <0x2b63f680>
06 03/03/15 19:19:25.042 Device_Variable::m_szValue_set device: 87 service: urn:micasaverde-com:serviceId:SecuritySensor1 variable: e[35;1mArmedTrippede[0m was: 0 now: 1 #hooks: 0 upnp: 0 v:(nil)/NONE duplicate:0 <0x2b63f680>
06 03/03/15 19:19:25.043 Device_Variable::m_szValue_set device: 87 service: urn:micasaverde-com:serviceId:SecuritySensor1 variable: e[35;1mLastTripe[0m was: 1425386825 now: 1425428365 #hooks: 0 upnp: 0 v:0xf466e8/NONE duplicate:0 <0x2b63f680>
06 03/03/15 19:19:25.080 Device_Variable::m_szValue_set device: 87 service: urn:micasaverde-com:serviceId:LightSensor1 variable: e[35;1mCurrentLevele[0m was: 6 now: 3 #hooks: 0 upnp: 0 v:0xfe2188/NONE duplicate:0 <0x2b63f680>
If you only need a delay of a few milliseconds, you can use this Lua:
luup.sleep(50)
The argument (50) is the number of milliseconds to delay before executing the next Lua statement. It is not advisable to use luup.sleep(…) for long delays. Some activities are blocked during the delay so there can be side-effects. Very long delays will trigger a Vera restart.
I do this today in several rooms with PLEG and Fibaro motion/light/temperature sensors. When the light level falls below a setpoint stored in a MultiString the PLEG guess the lights. In my case I’m using it in reverse, if the ambient light level is greater than the setpoint the the lights are turned off and will not go back on until the setpoint is greater than the ambient.
Thank you for the code snippit, I will give it a try!
So I got the delay, but the Vera missed the new light level all together. I guess when using sleep nothing happens so the when the sensor sent the value for the light level the Vera was asleep so it didn’t update the light level. Any other ideas?
I would hate to use luup.delay because that would be a whole second delay and if I had the sensor update more frequently it still wouldn’t catch all the times.
So I got the delay, but the Vera missed the new light level all together. I guess when using sleep nothing happens so the when the sensor sent the value for the light level the Vera was asleep so it didn't update the light level. Any other ideas?
That doesn’t make sense. What did LuaUPnP.log show for the period?
That’s the thing, it didn’t show any update for the light level. It missed it completely. Later it picked it up on its 30 minute interval. I thought about using the feature on the sensor to only report when the light level is below “x”, but the problem with that is that the light will shutoff while someone is walking around because it won’t report back. Right now I’m using the delay function and put a second in there and that is working all the time, except for the fact that I’m half way across the room by the time the light turns on :).