Show sunrise/sunset actual time in card?

When the sun integration sunrise and sunset times are shown in an entities card, it says things like “in 15 hours” or even just “tomorrow”. I know the sun will rise tomorrow, I would prefer to know at exactly what time.

The entity value is an exact time and I can see it by tapping the entity in the card, but I can’t see a way to change the default display format. I looked for another card type but a Entity card while it does show the time shows only one entity, in big font with the date as well, so not ideal and a Glance card shows the same data as an Entities card.

Is there a way to have this show the actual time so it can be seen at a glance?

Have a look at the Sun Card in HACS

image

5 Likes

Certain cards react like this as the device_class = timestamp
e.g. the single entity card does not where entites-card does
Depends on what you want to do with it, see above card as an alternative, else you can customize the sunrise/set sensor or create a template sensor yourselves based on them without timestamp

1 Like

I use templates to create next sunrise and next sunset sensors:

# Sun Integration Attributes
      - name: "Next Sunrise"
        unique_id: "next_sunrise"
        state: '{{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom(" %I:%M %p") | replace(" 0", "") }}'
        icon: mdi:weather-sunset-up

      - name: "Next Sunset"
        unique_id: "next_sunset"
        state: '{{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom(" %I:%M %p") | replace(" 0", "") }}'
        icon: mdi:weather-sunset-down

That gives me the ability to do something like this:
image

7 Likes

Thanks - that repository says it’s sunsetted (pun intended) and to use this one instead. Which I have done and it works.

2 Likes

@CaptTom, where did you define these sensors? I’m getting “Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None. (See /config/configuration.yaml, line 13).” error when I add these to a yaml file.

They were in configuration.yaml, but I broke my sensors out into two other files. So now my configuration.yaml has the following:

template:
  - binary_sensor: !include template_binary_sensors.yaml
  - sensor: !include template_sensors.yaml

Then, in template_sensors.yaml, I have the code you saw, above:

# Sun Integration Attributes
      - name: "Next Sunrise"
        unique_id: "next_sunrise"
        state: '{{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom(" %I:%M %p") | replace(" 0", "") }}'
        icon: mdi:weather-sunset-up

      - name: "Next Sunset"
        unique_id: "next_sunset"
        state: '{{ as_timestamp(states.sun.sun.attributes.next_setting) | timestamp_custom(" %I:%M %p") | replace(" 0", "") }}'
        icon: mdi:weather-sunset-down

You’d have to post that section (which includes line 13) to make sense of that error. But one thing to consider whenever you’re dealing with YAML is proper line indentation.

4 Likes

Thank you so much. I was missing the above. It’s working fine now.

thx, all done, no errors popping up, but also no change: still no actual times.
restarted, reloaded, etc. but no change.
did I forgot something?

I have the same issue, I reload, I have even restarted all of HA, but without any success. I try to add the sensors to a picture element but the sensors doesnt show in the list.
No errors in logs etc so I figure I am missing something
Have you gotten it to work ?

I think there is a bit simpler solution. When you add or edit the etities list panel for dashboard, click the “Show code editor” (I’m not sure with the exact translation) at the bottom left.
01. editor
for each entity then add formatting configuration variable (“format”) as follows

type: entities
entities:
  - entity: sensor.sun_next_dawn
    format: time
  - entity: sensor.sun_next_rising
    format: time
  - entity: sensor.sun_next_noon
    format: time
  - entity: sensor.sun_next_dusk
    format: time
  - entity: sensor.sun_next_setting
    format: time
  - entity: sensor.sun_next_midnight
    format: time

And if I understood well, that’s it!
For all possibilities see documentation Entities card - Home Assistant .
Hope it helped.

9 Likes

Where did you get the tide time and wind stats from?

The tides come from a custom component, NOAA Tides:

The wind speed comes from the National Weather Service integration. Both are US-specific, as far as I know. I think you can also get the wind speed at a specific weather buoy from the NOAA Tides component.

THIS.
This is the real solution. Displaying the time as time really shouldn’t require setting up template sensors or custom cards. As mentioned, the value is there, you just need to override the “let me guess what format is best suited for this entity” magic. Thank you so much for this!

Thanks for this, I thought there must be a solution like this and yu fixed it :smiley: 20s job

cool thanks :smiley: 20s job and running

Excellent, and thanks for the link to the docs

Bonjour et Grand Merci :slight_smile:
Dans ma naîveté de Néo HASS-guy, je pensais que Sun me donnerait SunRise et SunSet fingers in the nose. J’admirais AT : et OFFSET : 00:25:00 qui me dispensaient de savants calculs dans ces langues étrangères.
Quelle déception : Yaml me dit qu’il attend une Array et pas 00:25:00.
Vous indiquez une voie de sortie qui me réouvre l’horizon : Merci
Un de mes maitres en informatique avait cette affirmation totalement vérifiable : “Il n’y a pas à tortiller du cul pour chier droit” Et Paf !!!
Dans un nouvel environnement, le “chier droit” est absolument à redécouvrir.
Votre solution (dont je vous remercie encore) ne me serait pas venue à l’esprit sans un peu de bouscul(ation / age / …)
Mais je suis sûr qu’un jour viendra où cela m’apparaitra tout-à-fait naturel (un jour viendra, un jour d’épaules nues …/…)
Mais cet accouchement n’est pas sans douleur
PS : Je n’ai pas trouvé Sun Card dans HASS, où faut-il chercher pour trouver les Cartes Add-Ons ?