#Time & Duration display for Weather
1 messages · Page 1 of 1 (latest)
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 %}
Thanks for your help. If possible I'd like to keep the entity styling and have it show like this? The first code block is more than fine, but not sure how to keep the same styling.
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.
Right, ok. I'll look into that. Thanks.
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?
See if this works......Why do things have to be so difficult on this discord thing?
I’ll have a look, thank you.
This does work, however you need to install Mushroom from HACS for it to work.
I think OP's goal was to use a stock HA card without having to rely on something custom. The templates that you and I used both do the same thing, but having it configured as a templated entity will let them to show the state in the Entities card.
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 %}
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