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

2 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

6 Likes

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

1 Like

@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.

2 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.

2 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.