How to add Sunrise & Sunset Cards

Hi All,

I am pretty new to Home Assistant, I have it running on an old Dell laptop with Linux Mint. I managed to get my lights connected to my Wink Hub 2 working and now I would like to experiment further. I have been trying to create a horizontal stack card showing sunrise time and sunset time. I am really struggling to understand how to do this. I tried watching youtube videos but they all seem to use the older lovelace UI and make entries in the configuration.yaml

I am using the latest version and can add the horizontal stack card right from the interface but I do not know how to ad the code to get it working

Any help would be greatly appreciated

Lovelace is the current interface. If you select to edit the UI you can then use that menu again to access and edit the raw yaml behind the interface.

Thank you but how do I add new sensors such as sunrise & sunset?

Here is an example from another thread:

1 Like

First you need a template sensor:

sensor:
  - platform: template
    sensors:
      nextsunrise:
        entity_id: sun.sun
        friendly_name: 'Next Sunrise'
        value_template: >
          {{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom(' %I:%M %p') | replace(" 0", "") }}
        icon_template: mdi:weather-sunset-up
      nextsunset:
        entity_id: sun.sun
        friendly_name: 'Next Sunset'
        value_template: >
          {{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom(' %I:%M %p') | replace(" 0", "") }}
        icon_template: mdi:weather-sunset-down

then in Lovelace:

      - type: vertical-stack
        cards:
          - type: entities
            title: Season, Sun & Moon Phase
            show_header_toggle: false
            entities:
              - sensor.nextsunrise
              - sensor.nextsunset

I have a vertical stack but you get the idea?

looks like this:
image

27 Likes

That is exactly what I wanted. I copied the 1st block of text in to my configuration.yaml but got the following error when I checked it.

image

I put it in the section where I have other sensors

Your spacing is off. Post your yaml if you can’t figure it out. The error is telling you where to look, the spacing it wants starts at line 54 and screws up at 57. So you have to determine if the spacing is correct at 54 or 57

yeah when I pasted the yaml it got mangled… I edited…

so your original post is now correct?

yes fingers crossed…

OK the config worked,

For the 2nd block of text do I create a manual card?

paste it in using raw mode

Perfect,

It worked ! I added an entity card with both sunrise & sunset. Is that correct?

Thank you David and to everyone else that helped

1 Like

Hi

Followed your steps, and got this error in raw mode:

No card type found
[
{
“type”: “vertical-stack”,
“cards”: [
{
“type”: “entities”,
“title”: “Season, Sun & Moon Phase”,
“show_header_toggle”: false,
“entities”: [
“sensor.nextsunrise”,
“sensor.nextsunset”
]
}
]
}
]

I got rid of the error msg. But the sensor.nextsunrise and sensor.nextsunset, the hassio cant find, how do i set up those?

Thanks for your answer, I also used it :slight_smile:
Can you please explain how can I set a sensor that will get the value of the sunset with offset ?
Regards
David

you mean get the sunset and then subtract 30 mins from that ???
Why would you need that ?

Yes exactly.
Pray time depend on the sunset with some offset :slight_smile:
Regards
David

So i might be making an assumption here, but did you know about islamic_prayer_times component?

No. I am a Jewish :slight_smile:
I am familiar with the Jewish Calendar


but it does not help me in my case
Regards
David