@Troon : Two additional question:
1.) I recieve the data from the API in UTC and depending on the summer/winter time we have +1 or +2 in austria… how can I take this into account?
2.) I just found out that the sensor value does not get updated each hour. It just gets updated at startup of HA. How can I change this?
You just need to set time_now such that it gives you the string value you need for comparing against the list. Have a look at the many options available for manipulating time here: Templating - Home Assistant . Perhaps utcnow() will help.
What is only getting updated at restart? You have a 1h10s scan_interval on the rest sensor in your original post.
Ad1: Is there a way to manipulate the attribute list date and add there the hours by 1h (or 2h)? Otherwise I will have to do the proposed solution by you.
Ad2: Yes you are right, the values get updated each 1h10s (due to API limitation)
via the rest API. What I would like to have is that the values in the attribute list get updated each 1h10s, but the value of the sensor should get checked and (if needed) updated each minute. (In the Image you can see that I last restarted at 12:28 and since then each 3610s the values get updated, even there are new values in the attribute list for each full hour.) I hope I could explain it clear enough ^^
Not easily. Much easier to adjust the comparison time.
In that case, you may be better off with a separate template sensor reading the value from the rest sensor. Something like this (basically the same template but reading the attribute rather than the response; need to do the timezone adjustment here too):
template:
- sensor:
- name: Solar Forecast East current
state: >
{% set time_now = now().strftime('%Y-%m-%d %H:%M:%S') %}
{% set tkey = state_attr('sensor.solar_forecast_east_watt', 'watts')
|sort|select('le', time_now)|list|last %}
{{ state_attr('sensor.solar_forecast_east_watt', 'watts')[tkey] }}
Thank you for your help. there was an error because the template sensor uses state instead of value_template. Aft the change it seems to work ( I will have to wait until tomorrow when there is light again - at the moment the value is always 0
just for other people who might be interested here are the example sensors:
I see you have things solved. FYI, you would add the flag --null-input to the JQ command which is the cause of the first line missing. In JQ PLayground:
What does the States page show? This might just be due to the history having two different units for the same sensor — try restricting the graph to just the period after when you changed the sensor definition and reloaded. If that is the case, it’ll fix itself once the old definition has “scrolled left” enough in time.