I would like to manually reset the kwh history of a device.
Hy application is as follows, I have a shelly devices in my home all working on Home assistant as well as a solar solution.
I would like to have an automation that when the grid supply goes down my devices are only allowed to consume a set amount of energy, thus saving battery.
I am able to get the unts to switch off when the kwh usage reaches a set point but this is not ideal when power outages can happen at any time of the day.
So either i need to trigger a kwh "timmer’’ that counts down or reset the history when the power goes down.
I know this is a strange ask but I do stay in South Africa where power is a privilage .
All of this assumes you have a binary sensor that can track if grid power is available and that you have a battery SoC sensor.
Use a Utility meter with two tariffs and no reset cycle. One tariff for grid energy and one for battery energy:
utility_meter:
energy_use:
source: sensor.energy # replace with your energy consumption sensor
name: Energy Use
tariffs:
- grid
- battery
Switch the tariffs with this automation:
automation:
trigger:
- platform: state
entity_id: binary_sensor.grid_power # replace with your grid up/down sensor, likewise with the entity in the actions template below
not_to:
- unavailable
- unknown
action:
- service: select.select_option
target:
entity_id: select.energy_use
data:
option: >
{{ 'grid' if is_state('binary_sensor.grid_power', 'on') else 'battery' }}
This will create two sensors, sensor.energy_use_grid and sensor.energy_use_battery. The battery energy sensor will only accumulate while the grid power is off.
You have a few options on how to reset this battery energy sensor:
You could add a daily cycle to the utility meter. This will reset the sensors at midnight. Not so good if your outage continues past this time.
You could reset the sensors using the utility_meter.reset service when the power comes back on, but your battery may be discharged and another outage may occur soon after.
The best option would be to trigger an automation when your battery SoC reaches 90-100% charge and use the utility_meter.reset service in the actions to reset the sensors.
Or if you do not have a battery SoC sensor you could trigger an automation when the battery has been on charge long enough to recharge sufficiently. e.g.
trigger:
- platform: state
entity_id: binary_sensor.grid_power
to: 'on'
for:
hours: 4
action:
- service: utility_meter.reset
target:
entity_id: utility_meter.energy_use
Thought this time would need adjustment for how long the battery was used. The for: time does accept templates.