I want to know the Solar Forecast between midnight and midday adding up the hourly values from the Solcast Forecast which are in the entity sensor.solcast_pv_forecast_forecast_today state attributes e.g.
detailedHourly:
- period_start: '2023-10-26T00:00:00+01:00'
pv_estimate: 0
pv_estimate10: 0
pv_estimate90: 0
- period_start: '2023-10-26T01:00:00+01:00'
pv_estimate: 0
pv_estimate10: 0
pv_estimate90: 0
I can pick out individual values for example the 12th hour thus:
{{ "%.3f"|format(state_attr('sensor.solcast_pv_forecast_forecast_today','detailedHourly')[12]['pv_estimate']|float)}}
However when I try to sum these up in a for loop, the values don’t add. My initial attempt using “+=” convention was completely rejected in the template editor
{%- set forecast_to_12_today = 0|float %}
{%- for values in [0,1,2,3,4,5,6,7,8,9,10,11] %}
{%- set forecast_to_12_today += "%.3f"|format(state_attr('sensor.solcast_pv_forecast_forecast_today','detailedHourly')[values|int]['pv_estimate'])|float %}
{{ forecast_to_12_today}}
{%- endfor %}
and even when I went to brute force the value resets each loop instead of incrementing.
{%- set forecast_to_12_today = 0|float %}
{%- for values in [0,1,2,3,4,5,6,7,8,9,10,11] %}
{%- set forecast_to_12_today = forecast_to_12_today + "%.3f"|format(state_attr('sensor.solcast_pv_forecast_forecast_today','detailedHourly')[values|int]['pv_estimate'])|float %}
{{ forecast_to_12_today}}
{%- endfor %}
Any help appreciated. TIA.