Aeon Labs MultiSensor (left) and Fibaro Motion Sensor (right) |
The approach I’ve gone for is to use a python implementation of the Phi Accural Failure Detector to better interpret the signals from the motion sensors. These detectors are more commonly used to decide the health of hosts in a distributed system, such as in Apache Cassandra. These detectors record the intervals observed between heartbeats (pings in the distributed system case), and use this distribution to decide if the target is alive at a given time.
I’m using the detector to determine if a room is occupied (as opposed to a host being alive), but unfortunately the Z Wave motion sensors don’t send heartbeats periodically for me to feed to the detector. Instead, the sensors send edge-triggered events when they believe the room’s occupancy state has changed, based on their own internal algorithm, which I’m reasonably sure is just a simple timeout.
The initial approach to this was to synthesize heartbeats to the detector periodically, when the sensor says that the room is occupied. The detector is then periodically used to decide whether to turn the lights on. The implementation of this can be seen in this changeset. As the logic for the home automation system runs on App Engine, there is relatively little control over the exact timing of this periodic cron job. It was very possible that the sensor would detect motion (and the system would heartbeat the detector), then a few seconds later the cron job would run, see the sensor says that the room is occupied, and heartbeat the detector again. Similarly, the cron job could run, heartbeat the detector, then moments later the sensor could timeout (and the previously synthesized heartbeat could be considered wrong).
As the detector is based on recording heartbeat inter-arrival times, this approach doesn’t work particularly well - the recorded inter-arrival times would be too artificial (based on the cron job timing) and occasionally completely misleading; either too short (at the beginning of the period) or completely wrong (at the end of the period).
The improved approach is based on knowing the internal timeouts the sensors use, which luckily the Z Wave sensors expose as a configuration value. Now, the system only synthesizes events and feed them to the detector when the sensors “stops” detecting motion - and can therefore avoid the synthesized events being outright wrong (by making the last event happen timeout seconds in the past) and avoid the event inter-arrival times being too artificial (by spacing them timeout seconds apart). While this approach makes the detector useless while the sensor is “on”, they are not needed at this point - we know the room is occupied!
UI tile showing lighting controls for a room |
"I'm sorry, Tom. I'm afraid I can't let you do that". - HAL
ReplyDeleteHi there,
ReplyDeleteThank you sharing such a useful information.
We are leading motion sensors, smart lights, home automation products manufacturers in Vadodara
Visit our website for more information - PIR Motion Sensor
Very good & informative content on topic
ReplyDeleteThanks for sharing such a useful tips.
Visit our website for Software development company in Vadodara
Thank you for sharing such a useful information.
ReplyDeleteiMagic Baroda
Apple Showroom in Vadodara