I’m already having a template sensor that is giving me half hourly values of PV power.
- name: Pv power forecast list
unique_id: 6bc0c511-9c6f-4778-b13e-a20e3646a7e5
state: >
{{ states("sensor.solcast_forecast_today")}}
availability: >-
{{ has_value("sensor.solcast_forecast_today") }}
attributes:
list: >
{{ (state_attr('sensor.solcast_forecast_today', 'detailedForecast')
|selectattr('period_start','gt',utcnow())
|map(attribute='pv_estimate')
|map('multiply',2000)
|map('int')
|list
+ state_attr('sensor.solcast_forecast_tomorrow', 'detailedForecast')
|selectattr('period_start','gt',utcnow())
|map(attribute='pv_estimate')
|map('multiply',2000)
|map('int')
|list)[:36]
}}
Which outputs a list [3463, 3307, 3726, 3896, 3744, 3640, 3536, 3372, 3036, 2840, 2671, 2374, 1547, 901, 415, 148, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
This list always changes, when sun is up, the list starts with values above 0, when sun is down,list starts with 0.
The output of my new template should have the postition in the list with the first value higher then AFTER all the zeros.
Example:
[4, 5, 6, 0, 0, 0, 0, 1, 2, 3]
→ wanted result 8
[0, 0, 0, 0, 1, 2, 3, 4, 5, 6]
→ wanted result 5
[1, 2, 3, 4, 5, 6, 0, 0, 0, 0]
→ wanted result full list length
I’ve tried different things but I cant get it right.