Read sunset offset at a given time?

Thanks :sunrise: Although the normal sun.sun has next_setting, so as_timestamp(states.sun.sun.attributes.next_setting) works as well. That’s how i ended up with the next_setting initially. I thought i can access the “Next setting in x hours” info that’s on the (normal) sun popup, but couldn’t get it to work. Your solution is more precise :slight_smile:

I don’t know what you’re trying to do with the information, but just be aware that the next_setting attribute changes at sunset. So for most of the day it indicates when the sun will set today. But at sunset it changes to tomorrow’s sunset. In some use cases that may be fine, but in many it’s not, which is the whole reason I came up with my custom sun component. It provides a sunset attribute which stays constant the whole day and indicates today’s sunset, even if it has already occurred.

1 Like

Man, that’s what i like so much about home automation in general, you realize there is so much more under every stone you turn. For me, i was simply thinking about an automation to hide the offset at sunset since i deemed the information useless after the sun has set. Of course it makes sense for different applications than my narrow use case. I’m using it simply to show on a card how much sunlight i have left to go on a run/ride. :+1:

I’m trying to do something similar but much less complicated.

I’m simply want to change the offset if it’s a sunny day or not.
I’ve already made a helper binary sensor that determines if it’s sunny or not.
I’m just not sure how to change the offset using that binary.
This is my automation so far, it always erases my logic for the offset so I think I need to do this another way. I’m not sure.

alias: Daily Lights
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: {{ '-1:00:00' if is_state('binary_sensor.is_sunny', 'off') else '+0:00:00' }}
    id: sunset
  - platform: sun
    event: sunrise
    offset: "-03:00:00"
    id: sunrise
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - sunrise
        sequence:
          - service: script.all_off
            metadata: {}
            data: {}
      - conditions:
          - condition: trigger
            id:
              - sunset
        sequence:
          - service: script.all_on
            metadata: {}
            data: {}
mode: single