Setting overnight battery usage start time - Updated
Following on from the Setting overnight battery charge level article, this post explains how I use Home Assistant to configure the time the battery will start to discharge overnight. This is an updated post. The original is here. The issue with the original code was, it didn’t take in to account any forecast greater than 19 kWh. If the Solcast forecast was above that the default time would revert to 6am.
Background
Over the winter I wanted the battery to be as charged as possible when the day gets started. I would set the discharge time to 6am. In the summer I should be able to use the battery earlier as it should soon get topped up. This automation checks the current battery charge level at 23:30 and then depending on the remaining battery level and the Solcast forecast will set the battery discharge time.
I am not convinced this is worth doing as the Agile Octopus tariff is cheap during these hours, but I the geek in me says, why pay when you don’t have to?
alias: Solar - Set Overnight Battery Usage v3
description: Solar - Set Overnight Battery Usage v3
trigger:
- platform: time
at: "23:30:00"
condition: []
action:
- choose:
- conditions:
- condition: numeric_state
entity_id: sensor.lux_battery
above: 40
sequence:
- service: number.set_value
data:
value: >
{% set x = states('sensor.solcast_forecast_tomorrow') | int(0)%}
{% if x >= 20 %}
{{ 0 }}
{% elif x >= 17 <= 19 %}
{{ 2 }}
{% elif x >= 14 <= 16 %}
{{ 4 }}
{% else %}
{{ 6 }}
{% endif %}
target:
entity_id: number.lux_force_charge_end1
- service: notify.notify
data:
message: |
The battery will be used after {{
states("number.lux_force_charge_end1") }} o'clock
Forecast is {{ states("sensor.solcast_forecast_tomorrow") }} kWh
title: Set Overnight Battery Usage (Forecast)
default:
- service: number.set_value
data:
value: 6
target:
entity_id: number.lux_force_charge_end1
- service: notify.notify
data:
message: |
The battery will be used after {{
states("number.lux_force_charge_end1") }} o'clock
Forecast is {{ states("sensor.solcast_forecast_tomorrow") }} kWh
title: Set Overnight Battery Usage (Default)
mode: single
This isn’t very scientific, but this is what I have come up with. It takes tomorrow’s Solcast forecast value and makes it an integer and assigns it to X. This is scheduled at 11.30pm. If the battery has more than 40% battery remaining then it will check the forecast and set the battery start time accordingly. If the battery has less than 40% then the battery discharge time will be set to 6am.
Forecast - Battery charge over 40%
Greater equal to 20 kWH - Midnight
Greater equal to 17 kWh and less than or equal to 19 kWh - 2am
Greater equal to 14 kWh and less than or equal to 16 kWh - 4am
Any other value - 6am
The title of the message sent will either have (Default) or (Forecast) on the end. This helps with debugging which condition triggered.