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.