Result of this series as three minutes Youtube video: Data from home – Info Display
Details for the display: Controlling Samsung Signage QB13R-T based on Unifi Protect
Data from home – setup and preliminary results (Part 1)
Data from home – wireless water meter (Part 2)
Data from home – energy analyzer, requests against webUI (Part 3)
Data from home – district heating, computer vision (Part 4)
Data from home – alerting and water shutoff (Part 5)
I hope you enjoy!
Water alarms
Protecting my home from water leakage is one of the main ideas behind this story. This involves detecting water leaks and anomalies in water usage and reacting based on those. In this case reacting means switching on the D-Link DSP-W115 power socket that in turn controls the OUMAN M110C13 motorized main valve. Water leak detection is based on the Honeywell Lyric detectors which also control the same D-Link power socket. The glue between signals and controlling the socket is the IFTTT. I have also noted that there are now available consumer grade ready setups like Grohe Sense. I am still happy having accomplished this setup, during which I have learned a lot of new things!
The biggest achievements on my mind are the purpose built alarms in the Grafana. To me it seems that these alarms would be wise to be placed under its own dashboard called “alarms” and that the dashboard itself can be placed on its own folder called “alarms”. First and perhaps the easiest rule could be the current flow threshold.
# Query for current flow
A = rate(total_m3{job="pushgateway"}[60s])*1000*60
# Alarm definition for current flow, threshold 30 L / min
WHEN avg() OF query (A, 1m, now) IS ABOVE 30
To be a bit more granular I would want to have a more strict alarm rule for night time. I tried to create a rule that would count increase in meter reading from 10:00 PM to 06:00 AM and cut off the water immediately if the result is over 50 L. I didn’t come up with a solution but I came close. I know there is still some flaws, like not taking into count if it is summer or winter time in the manner of daylight saving. Still, here it is.
# Query for one hour usage
A = increase(total_m3{job="pushgateway"}[1h])*1000
B = increase(total_m3{job="pushgateway"}[1m])*1000
# Query for current hour
C = hour()
# Alarm definition for last hour usage between 10:00 PM to 06:00 AM, threshold 30 L / hour or 15 L / minute
WHEN max() OF query (A, 1m, now) IS ABOVE 30
OR max() OF query (B, 1m, now) IS ABOVE 15
AND last() OF query (C, 1m, now) IS OUTSIDE RANGE 3 TO 19
One more rule is for detecting if water flow is continuous in one hour values during last 24 hours. I will assume this means that there will be a problem ahead and for this alarm I am sending a notification as email for myself.
# Evaluation once per hour
# Query for one hour usage
A = increase(total_m3{job="pushgateway"}[1h])*1000
# Alarm definition for detecting continuous flow during last 24 hours
WHEN min() OF query (A, 24h, now) IS ABOVE 0
To help understanding what happened and why you can also create some supporting panels. Saving the dashboard with a default timeframe of “now/d-2h to now/d+6h-1d” will result showing you data from the previous night according to my definition of night time, 10:00 PM to 06:00 AM in this case.

water shutoff
The next thing is reacting to threshold violations. Maybe I will later come with something totally local, but for now I am using the IFTTT. So my alert notification is sent to IFTTT. The type for this notification channel is a webhook. IFTTT configuration is pretty straight forward so I am presenting here only the Grafana part.
# Notification channel
url = https://maker.ifttt.com/trigger/MYTRIGGER/with/key/MYKEY
Http method = POST
With this configuration activating an alert on a rule will trigger IFTTT to switch on the power socket. That in turn will initiate the motor to close the main valve.

I have also integrated some Honeywell Lyric leak detectors into the IFTTT and I trigger the same power socket with them as well. I have to admit being a fan the design of these detectors. They are powered by regular AA batteries, communicate over WLAN and still the battery life is really good. They send daily heartbeat including heat and humidity statistics and if they sense water they are awake really fast to report the leak. I also like the water sensing extension cord.

electricity alarms
I wanted to create alarms for electricity as well. This is to show off that I have enough information that allows detecting known patters. So I made a rule to alert me when our sauna gets turned on. This might be helpful if some of the children decide to turn on sauna by themselves. Our sauna heater is 8 kW and it gets really hot, so it is really dangerous if it gets turned on unintentionally.

# Query for load per phase
A = delta(kWl1{job="vmucpm"}[10s])
B = delta(kWl2{job="vmucpm"}[10s])
C = delta(kWl3{job="vmucpm"}[10s])
D = kWl1{job="vmucpm"}
E = kWl2{job="vmucpm"}
F = kWl3{job="vmucpm"}
# Alarm definition for detecting when sauna is turned on
WHEN max() OF query (A, 30s, now) IS ABOVE 2
AND max() OF query (B, 30s, now) IS ABOVE 2
AND max() OF query (C, 30s, now) IS ABOVE 2
# This is for avoiding new notifications while still heating after initial notificate
AND median() OF query (D, 20m, now) IS BELOW 20
AND median() OF query (E, 20m, now) IS BELOW 20
AND median() OF query (F, 20m, now) IS BELOW 20
In case sauna is turned on intentionally, it would be nice to get another notification when it’s ready (hot enough). Easiest way to detect this would of course be to monitor the temperature. Sauna is however hot (we like it around 80° C) and this makes battery based temperature sensor not suitable for this task. So, I am trying to detect the same from the electricity usage. I know, the thermostat in the heater is also pretty near the floor and same could have been applied to another temperature sensor. I think my approach is more appropriate in context of this blog series.
# Query for load per phase
A = delta(kWl1{job="vmucpm"}[10s])
B = delta(kWl2{job="vmucpm"}[10s])
C = delta(kWl3{job="vmucpm"}[10s])
D = kWl1{job="vmucpm"}
E = kWl2{job="vmucpm"}
F = kWl3{job="vmucpm"}
# Alarm definition for detecting when sauna is ready (hot enough)
WHEN max() OF query (A, 30s, now) IS BELOW -2
AND max() OF query (B, 30s, now) IS BELOW -2
AND max() OF query (C, 30s, now) IS BELOW -2
# This is for avoiding new notifications while still heating after initial notificate
AND median() OF query (D, 20m, now) IS ABOVE 1.8
AND median() OF query (E, 20m, now) IS ABOVE 1.8
AND median() OF query (F, 20m, now) IS ABOVE 1.8



I hope this information will be useful and entertaining for you as well. Again, feel free to leave me comments, questions or ideas. This content was brought to you “Just Because I Can”!