Multiple service calls in switch template?

I have a template switch that works.

cameralight:
      value_template: "{{ is_state('light.kenneths_skrivebord_master', 'on') }}"
      turn_on:
        service: wled.preset
        target:
          entity_id: light.kenneths_skrivebord
        data:
          preset: 5
      turn_off:
        service: wled.preset
        target:
          entity_id: light.kenneths_skrivebord_segment_1
        data:
          preset: 1

It’s the same light in the two, but as preset 5 has multiple segments, the entity_id changes (not nice).
I would like it to turn off the light as well in the ‘turn_off’, in a next service call, is it possible to have a sequence there, or do I need to make a script for that?

turn_on & turn_off accept the Script Syntax, so, yes, you can have more than one action. E.g.,:

turn_off:
  - service: ...
  - service: ...
1 Like

Thanks @pnbruckner
Yes, I just found out :slight_smile:
The problem was actually in the syntax for the wled service, which doesn’t have great explanation :frowning:
But I think I need to do a script, because firing first the wled.preset command, and then the turn_off for the light goes too fast, so the wled light doesn’t ‘reconfigure’ in time for the turn off to hit it…
Or maybe I can add a delay, have to try…

The turn_off and turn_off actions are scripts. So, yes, you can just add a delay directly there. No need to create a separate script to call from the on/off actions.

turn_off:
  - service: ...
  - delay: 0.5
  - service: ...
1 Like

Ok, gotcha, and it works like a charm, thankyou!

1 Like