Hi!
I read my gas meter with a D1_Mini. The current meter reading should always be output.
When the D1_Mini is rebooted, all data is lost and it starts again at 0.
I could save to the D1’s flash (esp8266_restore_from_flash), but that’s not a good idea because of the limited write cycles.
It makes sense to store the data in HA in a variable and have the D1 read it out with an on_boot action.
What would be the simplest solution to realize this? I can’t find anything suitable for the helpers. At most the counter.
Here is the config of my D1:
esphome:
name: esp_ecounter
platform: ESP8266
board: d1_mini
logger:
api:
ota:
wifi:
captive_portal:
globals:
- id: total_pulses
type: int
binary_sensor:
- platform: gpio
name: "Live-Impuls"
id: internal_pulse_counter
pin:
number: D7
mode:
input: true
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"
accuracy_decimals: 2
lambda: |-
return id(total_pulses) * 0.01;
The global variable “total-pulses” should be saved. Would be great if I could sync values via Home Assistant API, but if I understand correctly I can only import data from HA to ESP via this.