Hello all,
I cannot manage to get the total_daily_energy
to be accurate. I tried method right
, left
and trapezoid
, it is never accurate, it shows a number of cubic meters wildly different from what the pulse_meter
total is showing. Most of the time it’s significantly more.
Alternatively, I would like to use the pulse_meter
total, but the energy dashboard does not let me select it, even though device_class: gas
and unit_of_measurement: "m³"
.
Here is the yaml:
# ESP-32 Dev Kit C V4 - https://docs.platformio.org/en/latest/boards/espressif32/az-delivery-devkit-v4.html
# Board guide: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-devkitc.html
# pinout https://docs.espressif.com/projects/esp-idf/en/latest/esp32/_images/esp32-devkitC-v4-pinout.png
# 520kB Memory
# 4MB Flash
esphome:
name: gasmeter
friendly_name: Gasmeter
on_boot:
- pulse_meter.set_total_pulses:
id: gasmeter_pulse_meter
value: !lambda "return id(pulse_meter_total_value);"
# - pulse_counter.set_total_pulses:
# id: gasmeter_pulse_counter
# value: !lambda "return id(pulse_counter_total_value);"
esp32:
board: az-delivery-devkit-v4
framework:
type: esp-idf
# CUT (wifi, API, etc.)
globals:
- type: int
id: pulse_meter_total_value
restore_value: yes
external_components:
- source: github://syssi/esphome-total-count@main
# https://github.com/esphome/esphome/pull/6126
# catching interrupts
- source: github://pr#6126
components: [ pulse_meter ]
sensor:
- platform: pulse_meter
name: "gasmeter pulse_meter"
id: gasmeter_pulse_meter
pin:
number: GPIO27
inverted: true
# If PULLUP, connect second cable to GND on ESP board. If PULLDOWN, take the 3.3V pin.
mode: INPUT_PULLUP
unit_of_measurement: "L/min"
# device_class: gas
state_class: measurement
accuracy_decimals: 0 # no point for higher accuracy since 1 impulse = 0,01 m³
# Honeywell BK-G6 MT: spikes seen, need to be filtered out.
# Qmax = 10 m³/h
# 1 imp = 0,01m³
# Max Rate = 10 m³/h / 3600s / 0,01m³ = 0,27/s = max 1 impulse every 3,6s
# Min interval = 3600ms
# Empirical: ~6s
internal_filter_mode: PULSE
internal_filter: 200ms
timeout: 20s
filters:
- multiply: 10 # 1 impulse = 10 L on Honeywell BK-G6 MT
# - filter_out: NaN
icon: 'mdi:fire'
total:
name: "gasmeter pulse_meter total"
id: "gasmeter_pulse_meter_total"
unit_of_measurement: "m³"
device_class: gas
state_class: total_increasing
accuracy_decimals: 2
filters:
- debounce: 200ms
- multiply: 0.01
- lambda: |-
id(pulse_meter_total_value) = id(gasmeter_pulse_meter_total).raw_state;
return x;
# adding total_daily_tracker for when Home Assistant is offline, as a reference
# NOTE: not accurate, tested with method = left, right and trapezoid.
- platform: total_daily_energy
name: 'Pulse Meter Total Daily Gas Consumption'
id: sensor_total_daily_gas
power_id: gasmeter_pulse_meter
unit_of_measurement: 'm³'
filters:
# - multiply: 0.01
state_class: total_increasing
device_class: gas
accuracy_decimals: 2 # no point for higher accuracy since 1 impulse = 0,01 m³
method: left
# Enable time component to reset energy at midnight
# Required for total_daily_energy
time:
- platform: homeassistant
id: homeassistant_time