Hi All,
I am trying to save some photovoltaic production forecast from one day to another.
To achieve this I have created template sensors that store once a day existing forecast sensors in template sensors.
No problem with “Forecast.solar” forecast sensors (save_energy_estimate_fcstsolar), those are replicated exactly the same… but with “Solarcast” (save_solcast_forecast_tomorrow) it seems that the way their forecast are built is causing some troubles while replicating its attributes:
Information are correct but the formatting is incorrect and I have hard time to use ‘period_start’ data series of the template, whereas I can with the original.
I tried and it actually return same-o-same, which I believe makes sense as it is already a list… instead of json. to_json was failing because of the datetime object which it can’t interpret, as far as I can understand.
Very frustating as the data are here just strangely reported.
probably a bug. Though I don’t know exactly what I am doing stealling code from here and there, I tried to rebuild a json exactly the same but by calculating the value of datetime…
So here is the code if it helps anyone:
- unique_id: save_solcast_forecast_tmr
name: "save solcast forecast tmr"
state: "{{ now() }}"
attributes:
forecast: >-
{% set d = states.sensor.solcast_forecast_tomorrow.attributes %}
{% set ns = namespace(m=[]) %}
{% for attr in d['forecast'] %}
{% set p = (attr.period_start).strftime("%Y-%m-%dT%H:%M:%S%z") %}
{% set e = attr.pv_estimate %}
{% set ns.m = ns.m + [{'period_start': p, 'pv_estimate': e }] %}
{% endfor %}
{{ ns.m }}
back to square one, whereas I think I should not had to do all that and there is a bug or missing piece in HA templating for datetime values…
I didn’t and I’ve decided to delete my post because I don’t actually want to get involved in this topic. I was only reacting to the comment that the ability to handle time is in some way deficient.