Sunset not working

Can anyone help with this? The off works but sunset doesn’t.

  • alias: Turn on Xmas tree
    trigger:
    platform: sun
    event: sunset
    action:
    service: switch.turn_on
    entity_id: switch.power

  • alias: ‘Turn Off Christmas Tree’
    trigger:
    platform: time
    at: ‘22:30:00’
    action:
    service: switch.turn_off
    entity_id: switch.power

1 Like
##########################################################
## Sunset Automation
##########################################################
- alias: Sunset Automation
  initial_state: True

  trigger:
    - platform: sun
      event: sunset
      offset: "-00:10:00"

  action:
    - service: lock.lock
      entity_id: group.all_locks

    - service: homeassistant.turn_on
      entity_id: 
        - group.indoor_night_lights
        - group.outdoor_night_lights
        - group.outdoor_dusk_lights
     
    - service: fan.turn_off
      entity_id:
        - fan.lower_patio_fan_level

    - service: script.outdoor_holiday_on

Do you have the sun component loaded?

And is your timezone set correctly?

My Sun component looks fine and is accurate. I haven’t set timezone as I believe HA has picked it up accurately from Lat/Long.

image

yes, that was what i experienced also then changed to this:

  - platform: state
    entity_id: sun.sun
    to: above_horizon
  - platform: state
    entity_id: sun.sun
    to: below_horizon

which always works as expected

in:

  - 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_system', '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') }}'

Firstly I really appreciate all the help, the community here is very active and helpful which is a massive positive. But I’m beginning to think that my trial from Smartthings to HA is a non-starter. Everything is so much more involved a simple use of sunset being so overly complex, this is kinda the last straw…

Please give my example a shot and just change the “actions”

It works and I suspect you have some sort of weird typo or special character inserted somehow. YAML is not so forgiving so also having a good editor that validates helps. Microsoft Code editor works really well with the YAML plugin. Prior to this I used textpad and life was miserable.

I know HA has a steep learning curve; I came from Wink; but it is well worth it as once you get the basics sorted it has so much power and potential. Also the community is excellent to help out as we’ve all been in your shoes at some point trying to get doing.

Look at the top of the web-page. What do you see? This:
code%20to%20be%20formatted

Look at your first post. Did you format your code so others could properly debug it?

You may be giving up on Home Assistant because of something trivial, like bad indenting.

Sun-based automation examples.

Whatever you choose to do next, good luck!

Personally, I think you should reconsider. HA does have a steep learning curve with yaml but the benefits of HA outweigh the benefits of a company driven hub in my opinion.

HA pros:

  • Works without internet
  • Will be faster becuase logic is local vrs cloud based
  • Will never be discontinued and you won’t be forced to purchase a new hub

HA cons:

  • Steep learning curve for yaml

Anyways you should be able to copy and paste this yaml and it will work:

- alias: Turn on Xmas tree
  trigger:
    - platform: sun
      event: sunset
  action:
    - service: switch.turn_on
      entity_id: switch.power

- alias: Turn Off Christmas Tree
  trigger:
    - platform: time
      at: '22:30:00'
  action:
    - service: switch.turn_off
      entity_id: switch.power

it should, but it doesn’t always at least that what I was experiencing also, and why I changed to ‘state’, see my example few posts above. Any ideas why that would be?

It should always work with sunset or sunrise. I’d look to conditions if it’s not triggering.

no conditions in my automation… and others have reported issues with the same component not triggering.
Anyways, I will test again, to see what happens.

It’s possible, I can’t say for sure because I use a different sundown method.

o what’s that then? another component?

No, appdaemon. I’m not sure if it uses python, sun.sun component, or the module that sun.sun is based off of.

I see, well, nt to worry, I will try the sun trigger once more, now that I am 100% certain all else is correct, I can give it an extra shot

question though:

since I want it to trigger on both sunset and sunrise, can I use

trigger:
  platform: sun

without further events? according to https://www.home-assistant.io/docs/automation/trigger/#sun-trigger these are the only events happening, and all other changes are state.attributes https://www.home-assistant.io/components/sun/#implementation-details

Hmm, i’m not sure. It depends on if the sun trigger platform requires event to be populated.

guess not:

20

:wink:

well, back again.
It simply doesn’t work with sunset or sunrise.I can see it is triggered, but the automation doesn’t change the theme, based on this sensor:

  - platform: template
    sensors:
      sun_based_theme:
        friendly_name: Sun based theme
        value_template: >
          {% if is_state('sun.sun','above_horizon') %}
           {{states('input_select.set_sunrise_theme')}}
          {% else %}
            {{states('input_select.set_sunset_theme')}}
          {% endif %}
        icon_template: >
          {% if is_state('sun.sun', 'above_horizon') %}
            mdi:weather-sunny
          {% else %}
            mdi:weather-night
          {% endif %}

could this be a timing issue? If I use above_horizon and below_horizon, it immediately works