#Time & Duration display for Weather

1 messages · Page 1 of 1 (latest)

south dove
#

Hello,

How would I show time & duration to the sunset and sunrise sensors on my dashboard?
Example:
Sunrise: 06:00 / In 6 Hours

glossy loom
#

Ultimately, it really depends on how you want to see it. Using a Markdown card, this is how you can achieve your example. yaml type: markdown content: | Sunrise: {{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom(" %I:%M") }} / In {{ time_until(as_datetime(states('sensor.sun_next_rising'))) }} Then, you could apply some logic to determine if you should be seeing the sun rise or sun set?```yaml
type: markdown
content: |
{% if as_timestamp(states('sensor.sun_next_rising')) < as_timestamp(states('sensor.sun_next_setting')) %}
Sunrise: {{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom(" %H:%M") }} / In {{
time_until(as_datetime(states('sensor.sun_next_rising'))) }}
{% else %}
Sunset: {{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom(" %H:%M") }} / In {{
time_until(as_datetime(states('sensor.sun_next_setting'))) }}
{% endif %}

#

You could apply some HTML and emojis, if you want: ```yaml

  • type: markdown
    content: |
    <center>{% if as_timestamp(states('sensor.sun_next_rising')) < as_timestamp(states('sensor.sun_next_setting')) %}
    🌇 <b><font color="yellow"> Sunrise:</font></b> {{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom(" %H:%M") }} / In {{
    time_until(as_datetime(states('sensor.sun_next_rising'))) }}
    {% else %}
    🌆 <b><font color="orange">Sunset:</font></b> {{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom(" %H:%M") }} / In {{
    time_until(as_datetime(states('sensor.sun_next_setting'))) }}
    {% endif %}
south dove
glossy loom
# south dove Thanks for your help. If possible I'd like to keep the entity styling and have i...

For something like that, I'd say your best bet is to make a templated entity. The templating docs have recently been updated; there's a bunch to read over to understand it all. I'd suggest reviewing the Tutorial: Show the average home temperature on your dashboard. You'll use the templates that I mentioned above (instead of its example of working with temperatures.)
Once you have the new entity configured, you'll use that entity instead of the sensor.sun_next_rising.

south dove
#

Right, ok. I'll look into that. Thanks.

mighty sapphire
#

I have a card that would work but I can't figure out how to post the YAML? It's dynamic and the color of the card changes based on the time of day. Unbelievable.....When I edit this post there is no way to attach a file?

south dove
#

Paste it in a code block?

#

Or as a file. Or note pasting website

mighty sapphire
south dove
#

I’ll have a look, thank you.

south dove
glossy loom
#

Looking at your template, you might consider wrapping the time with a time_until() function to give it a more readable state. ```yaml
secondary: |
{% if is_state('sun.sun', 'above_horizon') %}
Sunset in {{ time_until(as_datetime(state_attr('sun.sun', 'next_setting'))) }}.
{% else %}
Sunrise in {{ time_until(as_datetime(state_attr('sun.sun', 'next_rising'))) }}.
{% endif %}

south dove
#

I did use d_sellers1’s idea for the “stock” appearance.

However I fully appreciate Nobody’s work and did give it a try. I also included the fact that the mushroom card would be needed if anyone else reading this thread would liked to of used it