Skip to content

Instantly share code, notes, and snippets.

@djmaze
Created November 28, 2022 22:47
Show Gist options
  • Save djmaze/852c27c37f4f223f346782635b93b1ae to your computer and use it in GitHub Desktop.
Save djmaze/852c27c37f4f223f346782635b93b1ae to your computer and use it in GitHub Desktop.
ESPHome-Config, um einen Gaszähler per Reed-Kontakt auszulesen
globals:
- id: total_pulses
type: int
restore_value: true
initial_value: '0' # startet mit 0
- id: imp_ratio
type: float
restore_value: false
initial_value: '0.01' # vom Gaszaehler
- id: Zustandszahl
type: float
restore_value: false
initial_value: '0.9643' # aus der Gasrechnung
- id: Brennwert
type: float
restore_value: false
initial_value: '10.276' # aus der Gasrechnung
- id: initial_consumption
type: float
restore_value: false
initial_value: '19967086' # hier kann der Gaszählerstand initialisiert werden (Faktor 1000 um einen genaueren Wert zu erzeugen)
- id: initial_energy_consumption
type: float
restore_value: false
initial_value: id(initial_consumption) * id(Brennwert) * id(Zustandszahl) / 1000.0
binary_sensor:
- platform: gpio
id: internal_pulse_counter
pin:
number: GPIO5 # Pin, an dem der Reed-Kontakt hängt
mode: INPUT_PULLUP
name: "Live-Impuls"
filters:
- delayed_on: 100ms
on_press:
then:
- lambda: id(total_pulses) += 1;
#- light.turn_on:
# id: led # optional: für eine LED, die den Gaszählerpuls visualisiert
#on_release:
# then:
# - light.turn_off: status # optional: für eine LED, die den Gaszählerpuls visualisiert
## Optional: Diese LED soll blinken, sobald ein Signal vom Gaszähler erkannt wird
#output:
#- platform: gpio
#pin: GPIO0
#id: 'led'
sensor:
- platform: template
name: "Gasverbrauch"
device_class: gas
update_interval : 10s
unit_of_measurement: "m³"
state_class: total_increasing
icon: "mdi:fire"
accuracy_decimals: 2
lambda: return (id(initial_consumption)/1000.0) + (id(total_pulses) * id(imp_ratio));
- platform: template
name: 'Gasverbrauch Energy'
device_class: energy
state_class: total_increasing
update_interval : 10s
icon: 'mdi:fire'
accuracy_decimals: 1
unit_of_measurement: "kWh"
lambda: return id(initial_energy_consumption) + (id(total_pulses) * id(imp_ratio) * id(Brennwert) * id(Zustandszahl));
- platform: template
name: 'Pulse Counter total'
update_interval : 10s
icon: "mdi:counter"
accuracy_decimals: 0
unit_of_measurement: "pulses"
lambda: return id(total_pulses);
@wobi07
Copy link

wobi07 commented Jul 21, 2025

Bei mir hat es bis vorige Woche super funktioniert!
Ohne irgendwelche Probleme oder Korrekturen!

Aber seit dem Update ESP 2025.6.3 auf 2025.7.0 erhalte ich keine Werte mehr.
Auch die nachfolgenden Updates auf das Momentane 2025.7.2 haben nicht geholfen und ich bin absolut ratlos.

Meine Vermutung ist das es an den zufielen Nachkommastellen liegt die übermittelt werden bzw. das die Rund auf 2 Stellen nicht mehr funktioniert.

Wie kann der Fehler behoben werden?
Oder bin ich der einzige den es nur betrifft?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment