How to add Sunrise & Sunset Cards

Okay, understood.
This may need some thinking about.
There are others here who could do this quicker, but it is something I will want to solve anyway.
It doesn’t matter if it’s 1 hr, or 23 mins, one solution should fit all, so if you need an extra 10 mins to visit the little boys room first, that will be up to you.
Be patient, though if someone comes back early you will get a solution sooner.

THANKS :pray:

ah ok

Try this template, subtract (sunset-offset) if you want to have it before sunset.

{% set offset = "00:30:00" %}
{% set offset = as_timestamp(strptime(offset, "%H:%M:%S")) %}
{% set sunset = as_timestamp(states.sun.sun.attributes.next_setting) %}
{{ (sunset + offset) | timestamp_custom(' %I:%M %p') }}

Shouldn’t this be sunrise - offset ??? (sorry, you did say but it didn’t register on 1st pass)

Why %I %M %p when you formatted the other %H %M %S ??

cause that’s what he wants

%I %M %p is 12/hr clock with format HH:MM am/pm

Yeah, I saw : -

hence my edit : -

Yeah, I read and parsed this too - but this should work equally well with H M S in both locations
I didn’t know that you could do arithmetic with differing time formats is all
Learnt something new, but I always use H M S, don’t like this latin ‘sugar’
Cheers

Thanks, can you please list all of the configuration.yaml template setting ? since I am getting an error message trying your solution
Regards
David

Post your’s and I’ll help you fix it. Gotta learn to fish my friend :wink:

wow thats a great find…
traveling to the largest muslim country in the world myself shortly, this might be very practical to have at hand.
Though, I take it it calculates the prayer_times based on the HomeAssistant instance lat/long settings? Could this be made into a travel component somehow, following ones own gps coordinates?

I do have the utc-offset, but not sure if that is useful regarding the prayer-times, which probably will be not simply + or - the offset?

        value_template: >
          {% set state = states.device_tracker.me %}
          {% if state.attributes is defined and
                state.attributes.time_zone is defined and
                state.attributes.time_zone != 'unknown' %}
            {% set n = now() %}
            {{ (n.astimezone(state.attributes.last_seen.tzinfo).utcoffset() -
                n.utcoffset()).total_seconds()/3600 }}
          {% else %}
            unknown
          {% endif %}

it would have to be made into a custom component and it would require major changes.

1 Like

a I see, well maybe not remake the component, but calculate the outcome of the sensor to the time the device is in.
not familiair with these prayer standards myself, how would I be able to find the local method of calculating these times?

I’ve got this https://www.islamicfinder.org/world/indonesia/ but they dont list the method used
Maybe I should create a separate thread for this, sorry wont diverge further here, and go to Calculate islamic prayer time on device's location?

I don’t know, i didn’t make the component, I only know about it.

Perfect! Worked for me!

With a small “float-trick”, you can draw graphs also the (based on @DavidFW1960 solution):

sensor:
  - platform: template
    sensors:
      nextsunrise:
        entity_id: sun.sun
        friendly_name: 'Next Sunrise'
        icon_template: mdi:weather-sunset-up
        unit_of_measurement: ' '
        value_template: >
          {{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom('%H.%M') }}
      nextsunset:
        entity_id: sun.sun
        friendly_name: 'Next Sunset'
        icon_template: mdi:weather-sunset-down
        unit_of_measurement: ' '
        value_template: >
          {{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom('%H.%M') }}
2 Likes

There is a simpler way to add “Next Sunrise” and “Next Sunset” values in an entities card:

type: entities
entities:
  - entity: sun.sun
    name: Next Sunrise
    type: attribute
    attribute: next_rising
    format: time
  - entity: sun.sun
    name: Next Sunset
    type: attribute
    attribute: next_setting
    format: time

22 Likes

Beau,
Thank you for that very elegant solution.
One question: how do I get the mentioned time “below” the icon instead of next to it?

I have the problem that when I use the “Glance” card, which does put the label below the icon, not the time is shown, but the text “below horizon” or similar. I seem not to figure out how to keep the time instead…

SunSet-Entity

Sorry, no idea how to do that.

You have to make a template sensor to extract an attribute for glance cards.