I want to set the charge level on my solar battery depending on the Solcast forecast. If Solcast predicts X kWh then set it to 80% if it predicts Y kWH then set it to 70%. I want to put this in an automation.
What is the best way to do this. Do I use a Template that has the IF states or a script?
I am not looking for the code, I want to work that out. I just want to know the best direction.
“Best” is a pretty vague term… Are you looking for “Most Concise”, “Easiest to Read”, “Even a 7 year old could follow the logic”, or maybe “Shortest”. It is a lot easier to give applicable suggestions if you share a more specific description of your goals and methods #8, #9
From the minimal information you have given, you can likely accomplish setting the level using either templates or Choose actions.
I didn’t want to Google the answer and go down the wrong route. The plan is, at 9pm at night look at the Solcast forecast for the next day. If the forecast is like the below, set the battery charge level accordingly.
0-5 kWh - charge level 100%
6-10 kWh - charge level 80%
10+ - charge level 50%
The numbers are examples. I am still working on the real numbers.
Thanks very much. This is what I ended up using. I still need to tweak the right numbers, but the logic is working great.
alias: Nightly Battery Charge Level
trigger:
- platform: time
at: "20:30:00"
condition: []
action:
- service: number.set_value
data:
value: >
{% set x = states('sensor.solcast_forecast_tomorrow') | int(0) %} {{
100 if 0 <= x <= 6 else 90 if 7 == x == 7 else 80 if 8 == x == 8 else
75 if 9 == x == 9 else 70 if 10 == x == 10 else 60 if 11 == x == 11
else 40 if 12 == x == 12 else 40 if 13 == x == 13 else 20 }}
target:
entity_id: number.lux_ac_battery_charge_level
- service: notify.notify
data:
message: >-
The battery charge level has been set to {{
states("number.lux_ac_battery_charge_level") }}
title: Nightly Battery Charge Level
mode: single
I am just learning and found this interesting.
I understand your logic two posts earlier (set the battery level to 100 if Forecast Value “x” is between 0 & 5…).
I can’t fully follow what you are doing in this example though.
Get the forecast value
It looks like you are mapping values or relationships? Forecast values to desired battery %, I think.
Set the charge to 100 if forecast value is less than 6, else get the value of the variables “levels” that corresponds to the forecast number. But what does the “20” do?