WLED Automation Action Template Error

The automation action below works for the “turn_on” service but gives following error for the “turn_off” service, how do I specify extra data for the “turn_on” service but not the “turn_off” service?

Error when the “turn_off” service is called.

Stopped because an error was encountered at April 4, 2022, 10:40:43 AM (runtime: 1.23 seconds)

extra keys not allowed @ data[‘effect’]

action:
  - service_template: |
      {% if is_state('media_player.living_room','playing') %}
        light.turn_on
      {% else %}
        light.turn_off
      {% endif %}
    target:
      entity_id: light.wled_soundreactive
    data:
      effect: ' ♫ Gravfreq@Rate of fall,Sensivity;,!;!'

I would typically approach this using a choose action with two options. The first has the following condition, {{ is_state('media_player.living_room','playing') }} and then performs the turn_on with effect.

The second option would have an opposite condition, eg {{ not is_state('media_player.living_room','playing') }} (or equivalent) and then performs the turn_off with no extra data.

Not sure I understand what you mean, if I use a condition, won’t it stop if the first condition is not met?

When using a choose action, you place your conditions in each “choose option”. These will not appear until you select the choose action in the automations GUI editor. Leave the primary ‘condition block’ of the automation blank for now.

Once you have your two “choose options”, yes, the automation will select the first “branch” that meets the condition specified.

I bet once you see it in the GUI you’ll have a better understanding as your automations can branch off different scenarios.

Wasn’t aware this was an option, didn’t see any reference of it in the docs, either way I have no idea where to start or how to apply it to my automation.

And the learning never stops, thanks alot, I think I got it with the following which works.

action:
  - choose:
      - conditions:
          - condition: state
            entity_id: media_player.living_room
            state: playing
        sequence:
          - service: light.turn_on
            data:
              effect: ''' ♫ Gravfreq@Rate of fall,Sensivity;,!;!'''
            target:
              entity_id: light.wled_soundreactive
      - conditions:
          - condition: state
            entity_id: media_player.living_room
            state: paused
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.wled_soundreactive
    default: []

Turn On Service
image

Turn Off Service
image

1 Like

Glad you got it working, looks great!