Dear community,
up to now I found all answers to my questions in this forum. Thanks very much for that great support from all of you guys.
Now it is the first time were I could not find a solution:
I want to have the sun-rise and sun-set time always for the current day only (that it can be displayed in a graph via apexcharts).
For this I created following template sensor:
- sensor:
- name: Zeit Sonnenuntergang
unique_id: TempSensTimSunSet
state: >
{%- set ts_sunset = as_timestamp(state_attr("sun.sun", "next_setting")) %}
{%- set ts_nextday = as_timestamp(as_datetime(states("sensor.date")) + timedelta(days=1)) %}
{%- if ts_sunset > ts_nextday %}
{%- set ts_sunset = as_timestamp(as_datetime(ts_sunset) - timedelta(days=1)) %}
{%- endif %}
{{ as_timestamp(as_datetime(ts_sunset))|timestamp_local() }}
device_class: "timestamp"
The calculation is working fine (I know at some time the values are a few seconds away from the real values after the sun-sensor updates, but no one sees that in the graph.)
In the template-section of developer-tools I see:
2022-07-12T21:16:30.897835+02:00
When I look to states of developer-tools I see:
2022-07-12T19:16:30+00:00
The two hours difference in the string is not nice, as I want to access the value also via JavaScript in Apexcharts by doing a string-operation.
I hope you can provide good hints for solving the topic.
Thanks!