Error invalid config for [automation]: Service does not match format <domain>.<name> for dictionary value @ data['action'][0]['service']. Got None. (See /config/configuration.yaml, line 9)

Hi,

First time posting. I get the error in the topic and I can’t figure out why

what i have in my action:

action:
  - service: >
      {% if is_state('input_select.select_state', 'Awake') %}
      light.turn_on
        target:
          entity_id: light.corridor
        data:
          brightness: 255
          hs_color:
            - 173.333
            - 3.529
      {%else%}
      light.turn_on
        target:
          entity_id: light.corridor
        data:
          brightness: 1
          hs_color:
            - 173.333
            - 3.529
      {%endif}

Any ideas why I get this?

Thanks!

I corrected the last {%endif**%**}

hours staring at it and not seeing it… I post it and…

but now I have an error that the template renders invalid service…

action:
  - condition: state
    entity_id: input_select.select_state
    state: Awake
  - service: light.turn_on
    target:
      entity_id: light.corridor
    data:
      brightness: 255
      hs_color:
        - 173.333
        - 3.529

Does your input_select.select_state have a “Not Awake” state? if so you can use that for the 2nd condiction in the automation. Just copy paste the above and change the condition state and brightness.

I dont think that formatting is allowed this way in automations: Conditions - Home Assistant

Hi,

Thanks for the suggestion!

The idea for the automation was that I wanted to have a different brightness depending on the input_select, as you have guessed I have an Awake and a Not_Awake selection.

I used to have two automations one for the condition if “Awake” and another for the condition if “Not_Awake”; however I wanted to try to condense them in one automation. As I wanted to have the lights turn off after X minutes in case of “Not_Awake” and X+y minutes in case of “Awake”, hence having just two automations (turn on and turn off).

The issue is that with the action as you suggest I think it stops with if the first condition is false and will not allow me to put / run a second condition for the state “Not_Awake”.

Yes, because you are attempting to template YAML statements and that’s simply invalid.

You can only template values for options. For example:

data:
  brightness: "{{ template can go here to compute a value for the brightness option }}"

You can’t use templates to decide if whole swaths of YAML statements should or should not be executed (like what you did in your posted example).

Based on what your example is attempting to do (setting the value of brightness depending on the input_select’s state), all you need to do is this:

action:
  - service: light.turn_on
    target:
      entity_id: light.corridor
    data:
      brightness: "{{ 255 if is_state('input_select.select_state', 'Awake') else 1 }}"
      hs_color:
        - 173.333
        - 3.529
1 Like

Just use the choose option for action. For option 1 use the awake state condition and option 2 the not_awake condition

The use of choose for this application is overkill because the only difference between the two service calls is the brightness value.

choose is preferred when there’s a significant difference between what each choice should do. Otherwise, like in this case, one simple template gets the job done.

Try state: awake

I did not mean to skip your solution. Was just typing this on my phone and missed your reply.
But yes, thats the cleaner solution.

@nickrout Thats the code from the OP. And that was not the problem.

It is a good policy to listen to @123 before you listen to me :slight_smile:

thanks everyone! all your answers were very enlightening and allowed me to understand a few key concepts that still eluded me (complete newbie here). I am marking @123 answer as solution because it uses my code, but @Dujith suggestion is something that is going to be very useful for everything that I want to do and that I did not understand how it could be used.