Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent values after reboot for sensor_total_energy and sensor_total_daily_energy #527

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions components/pulse_meter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ sensor:
- light.turn_off:
id: led_red
filters:
# multiply value = (60 / imp value) * 1000
# - multiply: 60
- lambda: return x * ((60.0 / id(select_pulse_rate).state) * 1000.0);
# multiply value = 1 / imp value
# - multiply: 0.001
- lambda: |-
id(persist_sensor_total_energy) = id(sensor_total_energy).raw_state; # write sensor_total_energy to flash
return x * (1.0 / id(select_pulse_rate).state);

total:
id: sensor_total_energy
Expand All @@ -89,6 +91,7 @@ sensor:
state_class: total_increasing
device_class: energy
accuracy_decimals: 3
restore: True
filters:
# Multiplication factor from W to kW is 0.001
- multiply: 0.001
- multiply: 0.001
15 changes: 14 additions & 1 deletion home-assistant-glow/esp32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ esphome:
project:
name: "klaasnicolaas.home-assistant-glow"
version: "${project_version}"
on_boot:
then:
- pulse_meter.set_total_pulses:
id: sensor_energy_pulse_meter
value: !lambda "return id(persist_sensor_total_energy);"

dashboard_import:
package_import_url: github://klaasnicolaas/home-assistant-glow/home-assistant-glow/esp32.yaml@main
Expand Down Expand Up @@ -60,4 +65,12 @@ wifi:
captive_portal:

# To have a "next url" for improv serial
web_server:
web_server:

preferences:
flash_write_interval: 5min

globals:
id: persist_sensor_total_energy
type: float
restore_value: True