Skip to content

Lanbon L8 Enhanced State Persistence and Energy Monitoring#1025

Open
pgrutz wants to merge 5 commits into
HASwitchPlate:masterfrom
pgrutz:master
Open

Lanbon L8 Enhanced State Persistence and Energy Monitoring#1025
pgrutz wants to merge 5 commits into
HASwitchPlate:masterfrom
pgrutz:master

Conversation

@pgrutz
Copy link
Copy Markdown

@pgrutz pgrutz commented Jun 5, 2026

The Lanbon L8 running stock OpenHasp firmware loses all state on reboot — relay outputs default to off, backlight resets to default brightness, and energy accumulation starts from zero. This pull request addresses all three issues for the Lanbon L8 hardware specifically, with all changes wrapped in #if defined(LANBONL8) to avoid impacting other hardware builds.
Additionally, the HLW8012 energy monitoring chip present in the Lanbon L8 was only partially implemented — instantaneous wattage was published but cumulative energy (kWh) was not. This PR completes the implementation using float arithmetic to avoid integer truncation at low wattages, persists the accumulated pulse count to NVS hourly so kWh survives reboots, and adds an energy_reset MQTT command to allow resetting the counter from Home Assistant or any MQTT client.

Changes

src/dev/esp32/lanbonl8.cpp

  • Added kwh as a float global for accurate kWh calculation
  • Added pulseOffset global for kWh persistence across reboots
  • Added energy_save(), energy_restore() using NVS
  • Updated loop_5s() to use float kWh and hourly NVS save
  • Updated get_sensors() to publish Energy.Total
  • Added energy_reset() method
  • Added gpio_save_output_state(), gpio_restore_output_state() for relay state persistence
  • Added backlight save/restore via NVS overriding set_backlight_level() and set_backlight_power()

src/dev/esp32/lanbonl8.h

  • Added energy_reset(), set_backlight_level(), set_backlight_power() declarations
  • Added _save_counter private member

src/sys/gpio/hasp_gpio.cpp

  • Added relay state save on change (LANBONL8 only)
  • Added relay state restore on boot with gpio_set_digital_value() call
  • Added UI sync via dispatch_normalized_group_values() on boot

src/hasp/hasp_dispatch.cpp

  • Bumped commands[] array from 29 to 32
  • Added dispatch_energy_reset() command handler
  • Registered energy_reset command

pgrutz added 5 commits June 3, 2026 11:07
…h to survive reboot.

Updated python tools to work with v3.12
Summary: Lanbon L8 Enhanced State Persistence and Energy Monitoring
The Lanbon L8 running stock OpenHasp firmware loses all state on reboot — relay outputs default to off, backlight resets to default brightness, and energy accumulation starts from zero. This pull request addresses all three issues for the Lanbon L8 hardware specifically, with all changes wrapped in #if defined(LANBONL8) to avoid impacting other hardware builds.
Additionally, the HLW8012 energy monitoring chip present in the Lanbon L8 was only partially implemented — instantaneous wattage was published but cumulative energy (kWh) was not. This PR completes the implementation using float arithmetic to avoid integer truncation at low wattages, persists the accumulated pulse count to NVS hourly so kWh survives reboots, and adds an energy_reset MQTT command to allow resetting the counter from Home Assistant or any MQTT client.
Finally, two Python 3.12 compatibility fixes are included for the build toolchain scripts, which fail on modern Python installations due to the removal of pkg_resources from the standard library.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant