State sun.sun vs event sunrise/sunset

HI,

i have 2 identical automations differing only in the trigger section for the sun related events (and some state() style notational changes that are of no consequence here):

one on my Hassos Pi using state sun.sun:

  - alias: Sun based theme change
    id: 'Sun based theme change'
    initial_state: 'on'
    trigger:
      - platform: homeassistant
        event: start
      - platform: state
        entity_id: input_select.set_sunset_theme
      - platform: state
        entity_id: input_select.set_sunrise_theme
#      - platform: sun
#        event: sunrise
#      - platform: sun
#        event: sunset
      - platform: state
        entity_id: sun.sun
        to: above_horizon
      - platform: state
        entity_id: sun.sun
        to: below_horizon
    condition: []
    action:
      - service_template: frontend.set_theme
        data_template:
          name: >
            {{ states.sensor.sun_based_theme.state }}
      - condition: state
        entity_id: input_boolean.notify_notify
        state: 'on'
      - service: notify.notify
        data_template:
          message: >
            Hassos - It is {{ as_timestamp(now()) | timestamp_custom("%X") }}, 
            Sun is {{states.sun.sun.state}} and Frontend is set to 
             '{{ states.sensor.sun_based_theme.state }}'

and one on my Hassio P using event sunrise/sunset:

  - alias: Sun based theme change
    id: 'Sun based theme change'
    initial_state: 'on'
    trigger:
      - platform: homeassistant
        event: start
      - platform: state
        entity_id: input_select.set_sunset_theme
      - platform: state
        entity_id: input_select.set_sunrise_theme
      - platform: sun
        event: sunrise
      - platform: sun
        event: sunset
#      - platform: state
#        entity_id: sun.sun
#        to: above_horizon
#      - platform: state
#        entity_id: sun.sun
#        to: below_horizon
    condition: []
    action:
      - service_template: frontend.set_theme
        data_template:
          name: >
            {{ states('sensor.sun_based_theme') }}
      - condition: template
        value_template: >
          {{ is_state('input_boolean.notify_notify', 'on')}}
      - service: notify.notify
        data_template:
          message: >
            Hassio - It is {{ as_timestamp(now()) | timestamp_custom("%X") }}, 
            Sun is {{states('sun.sun')}} and Frontend is set to 
             '{{ states('sensor.sun_based_theme') }}'

The Hassos triggers correctly, while the Hassio triggers 2 shortly after another, and with the wrong outcome in the first call…

It should be doing it correctly though, because on the same Hassio, i have this autmation working just fine, proving it reads the components sun and its attributes alright. Events though Sunset and sunrise are not reliable for this?

automation:

  - alias: Send notification when sun changes state
    id: 'Send notification when sun changes state'
    trigger:
      platform: state
      entity_id: sun.sun
    condition:
      - condition: template
        value_template: >
          {{ trigger.to_state.state is in ['above_horizon', 'below_horizon'] and
             trigger.to_state.state != trigger.from_state.state }}
      - condition: template
        value_template: >
          {{ is_state('input_boolean.notify_notify', 'on')}}
    action:
      service: notify.notify
      data_template:
        message: >
         Sun state change - {{as_timestamp(now()) | timestamp_custom("%X") }} The Sun is 
         {{'up' if is_state('sun.sun','above_horizon') else 'down'}}

Is there an explanation for that?

1 Like