Hi,
i have an ESPHome for my Gas State Number.
The Problem: After i had it offline for an hour, i had a different state than before. But how does it work?
I had “total_increasing” as state_class, so i was thinking he can only count up and not down.
The state before was 717303, but after the restart/offline time, it drops to 5000 or something, cause he had it in his restore or so?
Is there any way, that the ESPHome gets the old state and only can count up and not down?
Thats the code
esphome:
name: gas
# d1 mini pro but only with 4MB -> d1_mini
esp8266:
board: d1_mini
restore_from_flash: no
globals:
- id: total_pulses
type: int
initial_value: '717310' # hier kann der Gaszählerstand initialisiert werden
restore_value: no
binary_sensor:
- platform: gpio
id: internal_pulse_counter
pin:
number: D1
mode: INPUT_PULLUP
name: "Live-Impuls"
filters:
- delayed_on: 10ms
on_press:
then:
- lambda: id(total_pulses) += 1;
sensor:
- platform: template
name: "Gasverbrauch"
device_class: gas
unit_of_measurement: "m³"
state_class: "total_increasing"
icon: "mdi:fire"
update_interval : 10s
accuracy_decimals: 2
lambda: |-
return id(total_pulses) * 0.01;
switch:
- platform: factory_reset
name: Restart with Factory Default Settings
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Gas Fallback Hotspot"
password: "XXXXXXXXXXXX"
captive_portal: