Lanbon L8 Enhanced State Persistence and Energy Monitoring#1025
Open
pgrutz wants to merge 5 commits into
Open
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.cppkwhas a float global for accurate kWh calculationpulseOffsetglobal for kWh persistence across rebootsenergy_save(),energy_restore()using NVSloop_5s()to use float kWh and hourly NVS saveget_sensors()to publishEnergy.Totalenergy_reset()methodgpio_save_output_state(),gpio_restore_output_state()for relay state persistenceset_backlight_level()andset_backlight_power()src/dev/esp32/lanbonl8.henergy_reset(),set_backlight_level(),set_backlight_power()declarations_save_counterprivate membersrc/sys/gpio/hasp_gpio.cppLANBONL8only)gpio_set_digital_value()calldispatch_normalized_group_values()on bootsrc/hasp/hasp_dispatch.cppcommands[]array from 29 to 32dispatch_energy_reset()command handlerenergy_resetcommand