globals: - id: total_pulses type: int restore_value: false initial_value: '2497' binary_sensor: - platform: gpio id: internal_pulse_counter pin: GPIO32 internal: true filters: - delayed_off: 100ms ## This automation will be triggered when a button press ends, ## or in other words on the falling edge of the signal. on_release: then: - lambda: id(total_pulses) += 1; sensor: - platform: template name: "Gas used" device_class: energy unit_of_measurement: "m³" state_class: "total_increasing" icon: "mdi:fire" accuracy_decimals: 2 lambda: |- return id(total_pulses) * 0.01;