Combine sunset and sunrise

Please help, why does this not work??

- alias: 'lamp tuinhuis automatisch aan uit
  trigger:
   - platform: sun
     event: sunset
     offset: '00:30:00'
   - platform: sun
     event: sunrise
     offset: '-05:00:00'
   action:
   - service: "switch.turn_{{'on' if trigger.event == 'sunset' else 'off'}}"
     target:
       entity_id:
       - switch.voorkant_tuinhuis

Could you please format you pasted code correctly, see: https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

And what do you mean “it doesn’t work”?

what exactly are you expecting it to do and what is or isn’t it doing?

Does it not trigger at all? Or do the actions not run as expected after it triggers?

Thank you :+1:

Hi Finity,

When i switch the light manualy to “on” it will switch off by the automation if a press “run.”
Turn the light on with automation doesn’t work.

You are missing a quote at the end of your alias, unless that is a copy/paste error.

I’m not sure if the sun integration provides a trigger event that you can use in the template. especially if an offset is used.

try with a trigger id instead:

- alias: 'lamp tuinhuis automatisch aan uit'
  trigger:
    - platform: sun
      event: sunset
      offset: '00:30:00'
      id: sunset
    - platform: sun
      event: sunrise
      offset: '-05:00:00'
  action:
    - service: "switch.turn_{{'on' if trigger.id == 'sunset' else 'off'}}"
      target:
        entity_id:
        - switch.voorkant_tuinhuis

be aware that you won’t be able to test this by running the automation manually since the trigger data won’t be present because the automation didn’t actually get triggered by the trigger. You will need to wait until the triggers actually occur to properly test it.