Open AitorDB opened 3 years ago
I really like your sun-card.
Here is some code I found/wrote some time ago with the help of the community. Maybe it could help you:
# Sunrise/set
time_to_sun_rise_set:
friendly_name: Sunrise/set remaining time phrase
value_template: >-
{% set rise_set = state_attr('sun.sun', 'next_rising')
if is_state('sun.sun', 'below_horizon')
else state_attr('sun.sun', 'next_setting')
%}
{% set rise_set_time = as_timestamp(rise_set) - now().timestamp()
if rise_set != None
else None
%}
{%- macro get_time_string(tstring, number) %}
{%- if number > 0 %}
{%- set ret = '{} {} ' if number == 1 else '{} {}s ' %}
{{- ret.format(number, tstring) }}
{%- else %}
{{- '' }}
{%- endif %}
{%- endmacro %}
{%- macro get_phrase(time) %}
{%- if time != None %}
{%- set minutes = get_time_string('minute', ((time % 3600) / 60) | int ) %}
{%- set hours = get_time_string('hour', ((time % 86400) / 3600) | int ) %}
{%- set days = get_time_string('day', (time / 86400) | int ) %}
{%- set ret = days + hours + minutes %}
{{- ret.strip() }}
{%- endif %}
{%- endmacro %}
{{ get_phrase(rise_set_time) }}
Thank you so much! Sadly the code in this card it's a bit different to what you would usually do with yaml, but good to see other solutions the community is using!
Currently on progress here https://github.com/AitorDB/home-assistant-sun-card/pull/36
Add to the card 2 new elements to display the total hours of sun in the day and the remaining hours. More context: https://www.reddit.com/r/homeassistant/comments/ne2mx4/sun_card_for_home_assistant/gyh7yrs