Not so long ago, I received a gas bill from which I felt uncomfortable, and I decided to integrate a regular gas meter into my smart home based on the Raspberry Pi + Home Assistant in order to predict the cost of expenses and receive alerts as soon as the consumption exceeds expectations.
First of all, I climbed onto Habr, and to my surprise, among not a small number of articles on how to read meter readings, and even a couple of articles directly on taking readings from a gas meter, in none of them I did not find what I was looking for.
There is a rather interesting article from 2014 about optical reading from any meter using a smartphone , but there is not a word about Home Assistant at all, nor about its component for optical recognition of meters in particular.
There is an article from 2018 about a universal inexpensive device for optical reading from any meter , which I would be happy to buy at that time, but it still has not got into the free sale.
Reading these and other articles (for example, the 2018 article about Waterius , or the 2020 article Smart Khrushchev at maximum speed ), I realized that the counters are not divided into two generations (offline and online), but into three. In addition to the 3rd generation of meters, which is able to send meter readings where necessary, there is also a 2nd generation that does not know how to transmit data over the network itself, but is equipped with a pulse transmitter (optical or magnetic) that allows you to connect a module to the meter that reads these pulses and passes on.
Googling my gas meter (it turned out to be BK-G4), I happily discovered not only that a magnetic pulse generator is built into it (a magnet on the low-order drum), but even that there are already successful examples of its integration into Home Assistant .
() IN-Z61 (1640 , ), esp8266 (788 ), , , , , , , .
, , Home Assistant Xiaomi ( MCCGQ01LM), - 600 .
, , . , - AliExpress 20 .
Home Assistant configuration.yaml
counter:
gas_counter:
step: 10
automations.yaml
- id: '1606010744418'
alias: Gas count
description: ''
trigger:
- entity_id: binary_sensor.openclose_gas
platform: state
from: 'on'
to: 'off'
action:
- data:
entity_id:
- counter.gas_counter
service: counter.increment
configuration.yaml utility_meter: !include utility_meter.yaml
, utility_meter.yaml , (, , )
gas_monthly:
source: sensor.gas_counter_sensor
cycle: monthly
tariffs:
- single
gas_daily:
source: sensor.gas_counter_sensor
cycle: daily
tariffs:
- single
gas_hourly:
source: sensor.gas_counter_sensor
cycle: hourly
tariffs:
- single
,
- platform: template
sensors:
gas_counter_sensor:
friendly_name: " "
unit_of_measurement: '3'
value_template: "{{ (states('counter.gas_counter') | float) / 1000 }}"
icon_template: mdi:counter
- platform: template
sensors:
gas_last_month:
friendly_name: " ( )"
unit_of_measurement: 'β½'
value_template: "{{ ((state_attr('sensor.gas_monthly_single', 'last_period') | float) / 1000 * 6056.4) | round(2) }}"
icon_template: mdi:cash-100
- platform: template
sensors:
gas_this_month:
friendly_name: " ( )"
unit_of_measurement: 'β½'
value_template: "{{ ((states('sensor.gas_monthly_single') | float) / 1000 * 6056.4) | round(2) }}"
icon_template: mdi:cash-100
- platform: template
sensors:
gas_today:
friendly_name: " ()"
unit_of_measurement: 'β½'
value_template: "{{ ((states('sensor.gas_daily_single') | float) / 1000 * 6056.4) | round(2) }}"
icon_template: mdi:cash-100
- platform: template
sensors:
gas_yesterday:
friendly_name: " ()"
unit_of_measurement: 'β½'
value_template: "{{ ((state_attr('sensor.gas_daily_single', 'last_period') | float) / 1000 * 6056.4) | round(2) }}"
icon_template: mdi:cash-100
- platform: template
sensors:
gas_this_hour:
friendly_name: " ( )"
unit_of_measurement: 'β½'
value_template: "{{ ((states('sensor.gas_hourly_single') | float) / 1000 * 6056.4) | round(2) }}"
icon_template: mdi:cash-100
- platform: template
sensors:
gas_last_hour:
friendly_name: " ( )"
unit_of_measurement: 'β½'
value_template: "{{ ((state_attr('sensor.gas_hourly_single', 'last_period') | float) / 1000 * 6056.4) | round(2) }}"
icon_template: mdi:cash-100
- platform: template
sensors:
gas_hour_based_monthly_estimate:
friendly_name: " (->)"
unit_of_measurement: 'β½'
value_template: "{{ ((state_attr('sensor.gas_hourly_single', 'last_period') | float) / 1000 * 6056.4 * 24 * 30) | int }}"
icon_template: mdi:chart-line-variant
- platform: template
sensors:
gas_day_based_monthly_estimate:
friendly_name: " (->)"
unit_of_measurement: 'β½'
value_template: "{{ ((state_attr('sensor.gas_daily_single', 'last_period') | float) / 1000 * 6056.4 * 30) | int }}"
icon_template: mdi:chart-line-variant
SD Home Assistant , Home Assistant , , configuration.yaml
recorder:
exclude:
entities:
- binary_sensor.openclose_gas
Home Assistant
, Home Assistant , ( ) , .
( ) ( ) .