Automation for led to follow state of light

I’m trying to use an LED (light.led1) to follow the state of a certain switch (switch.relay3) .
I can do this using two automations. One triggered by the switch coming on and setting the led on.
And a second one doing the inverse.

I do feel like this should be possible using only one automation, but i have no idea how.
It should basically monitor the change in state of the relay and set the led accordinly.

This would probably need templates? Well i’m no good at that so any help to start would be greatly appreciated!

Something like this:

  - alias: switch to light
      platform: state
      entity_id: switch.relay3
      service_template: >
        {% if trigger.to_state.state == 'on' %}
        {% else %}
        {% endif %}
      entity_id: light.led1
1 Like

Could also do this for the service template:

service_template: "light.turn_{{ trigger.to_state.state }}"

i’ve used @VDRainer’s solution. Confirmed working!
I’ll try your option too @Tediore,

Thank’s for the help both!

1 Like