MONITOR GAS LEAKS WITH HOMEASSISTANT
2023 October 06 | CommentsLast year I added a magnetic field sensor to my gas meter to monitor gas consumption. The sensor closes when it detects a change in the surrounding magnetic field, and the spinning disc in my gas meter is magnetic at the “0” position, so I know the amount of gas flowing through the meter more-or-less accurately by increasing a counter every time the sensor closes. The setup for that is very simple, first you add a helper to count the gas consumption. Navigate to Settings -> Devices -> Helpers and create a counter entity. The image below is how mine currently looks:
Then create an automation to increase that counter whenever the contact closes:
alias: Gas Meter Hall contact closes
description: ""
trigger:
- platform: state
entity_id:
- switch.gasmeter
from: "on"
to: "off"
for:
hours: 0
minutes: 0
seconds: 5
condition: []
action:
- service: counter.increment
data: {}
target:
entity_id: counter.gaszahler
mode: single
That’s the simple case to monitor your gas consumption. To check for gas LEAKS I added a second helper entity that holds the current value at 5 minute intervals:
Add an automation to populate that entity every 5 minutes and check if the value is larger than expected. If it is, I send a notification via Jabber:
alias: Check for gas leak
description: ""
trigger: # run every 5 minutes
- platform: time_pattern
minutes: /5
condition: []
action:
- choose:
- conditions:
- condition: template # check if the value has increased by more than 15 units
value_template: >-
{{ states('counter.gaszahler')|int -
states('counter.gaszahler_5min_ago')|int > 15 }}
sequence:
- service: notify.jabber # send notification via Jabber
data:
message: WARNING! Possible Gas Leak!
default: []
- service: counter.set_value # set the value of the "5 minute ago" helper to the current value
data:
value: "{{states('counter.gaszahler')|int}}"
target:
entity_id: counter.gaszahler_5min_ago
mode: single
The biggest issue for me here was getting the information out of my gas meter. I tried a Reed switch first, but the magnetic field of my gas meter was too weak to trigger it. I even considered Jomjol’s AI on the edge for this and it works well on my water meter, but I have no option to mount it in front of my gas meter. The sensor is use now is an “AZDelivery KY-024 hall sensor” that I hotglued to the gasmeter and connected to a spare ESP8266 NodeMCU which sends the sensor state to HomeAssistant via MQTT.
Let me know if you did something similar, I am eager to learn how you monitor your dumb devices for safety issues!
EOF
Category: blog
Tags: HomeAssistant Gas Safety ESP8266 MQTT
Comments
You can use a Mastodon account to comment on this article by replying to the associated Mastodon toot.