I can think of 2 cases where I want to record binary data:
- Duty-Cycle of the boiler
- Presence of the members of the familly at home
As said in a previous post about Z-Wave, the status of the switch on the actuator is available and will be dumped every 5 minutes in a JSON file.
This is a little bit more tricky. One of the best way to know if someone (and who) is home might be to check if the mobile phones are around. I looked into possible solutions but every phone has its peculiarities:
ping doesn't respond on iOS but does on Android. iOS has Bonjour/mDNS activated by default but Android hasn't, etc...
Then, I discovered that my ISP's Box has an JSON API listing all the deviced connected with a flag called "active" bearing the values true or false. Unfortunately, this flag is not very reliable but combined with another one called "lastConnection" (returning a date), it seems possible to check if a given mobile was around in the last 10 minutes. The value 10 minutes comes from iOS which can be silent for up to 10 minutes. By running a check every 5 minutes, I can check if a phone is back home with a 5-minute resolution or has left home with a 10-minute resolution.
One day, I might investigate the bluetooth tag/tiles on keyfobs but in the meantime, mobiles detection rules!
Filtering is done by the MAC address so an associative array MAC address => owner is all what is needed.
In this case, we are not talking about a rate (something per second) nor a gauge (temperature, humidity, ...) but I still believe that RRD can be used here:
At the end of the 5-minute period, we have a binary value (on/off, in/out, ...). Once consolidated (30 min ou 1 day), the only relevant information is either the total time for each state or simply the percentage.
So if "always on for a given period" is represented 100%, then the easiest way to store the information is to use the value 30000 as base.
rrdtool update presence1.rrd 1407153600:30000 # if on/present rrdtool update presence1.rrd 1407153600:0 # if off/away
Remember that RRD will (for non gauge) always store a rate, hence will divide that value by the base period (called step).
Here 30000 / 300s = 100.
When consolidating to 30-minute periods, 6 values will be taken for the average calculation. If the heating is on for half an hour, then average will be 100. If it is on for only 15 minutes, the average will be 50 and so on. These values look like nice percentages :-)
The same apply to the daily value. We end-up with the duty cycle of the heating or the percentage of presence at home day by day. Useful? No idea but that's not the point here!
RRD creation parameters
rrdtool create presenceX.rrd --step 300 \ DS:personX:ABSOLUTE:600:0:30000 \ RRA:AVERAGE:0.9:1:24 \ RRA:AVERAGE:0.9:6:35064 \ RRA:AVERAGE:0.9:288:1826 rrdtool create heating.rrd --step 300 \ DS:heating:ABSOLUTE:600:0:30000 \ RRA:AVERAGE:0.9:1:24 \ RRA:AVERAGE:0.9:6:35064 \ RRA:AVERAGE:0.9:288:1826