Template Service_template problem - syntacs - starting to go nuts

Hello all

once again I turn to the community for help.

When trying to template I receive an error and I can’t seem to get this fixed.

Error:

Error while executing automation automation.boolean_licht_woonkamer_b. Invalid data for call_service at pos 1: Service ->light.turn_on does not match format <domain>.<name>

> - alias: Boolean - Licht Woonkamer (B)
>   trigger:
>   - platform: state
>     entity_id: input_boolean.input_light_livingroom
>   action:
>     service_template: >
>       {%- if states('input_boolean.input_light_livingroom') == 'on' -%}
>         light.turn_on
>       {%- else -%}
>         light.turn_off
>       {%- endif %}
>     data_template:
>       entity_id: light.hue_woonkamer

`
Please help it seems as it shoukd work but it won’t.
thanx

not sure why it doesn’t work. But you can make this more robust and simplify the action.

 - alias: Boolean - Licht Woonkamer (B)
   trigger:
     - platform: state
       entity_id: input_boolean.input_light_livingroom
   action:
     - service_template: "light.turn_{{ trigger.to_state.state }}"
       data:
         entity_id: light.hue_woonkamer

things to note:

  • You don’t need a data_template for your data section because you aren’t using a template.
  • to_state.state or from_state.state will always be 'on' or 'off' for an input boolean. You can use that to set the state of the light.
  • When you use the trigger object, you don’t need to hardcode the name or entity, because that is passed into the trigger state object.
1 Like

This worked like a charm for the automation!
thank you so very much.

- alias: Licht - Woonkamer - Boolean (A)
  trigger:
  - platform: state
    entity_id: light.hue_woonkamer
  action:
    service_template: input_boolean.turn_{{ trigger.to_state.state }}
    data:
      entity_id:
        - input_boolean.light_lux_livingroom

- alias: Licht - Woonkamer - Boolean (B)
  trigger:
  - platform: state
    entity_id: input_boolean.light_lux_livingroom
  action:
    service_template: light.turn_{{ trigger.to_state.state }}
    data:
      entity_id:
        - light.hue_woonkamer

But I might have run into a new problem… All my automations fire twice. So in my logbook I always have to entries when ever an automation fires. After some invetisgation this might be beacause we didn’t specify a from and to state? Do you have a better clue? Thanks for all your help petro!

So you can add a condtion to make sure it only fires when the state change is different

- alias: Licht - Woonkamer - Boolean (A)
  trigger:
  - platform: state
    entity_id: light.hue_woonkamer
  condition:
  - condition: template
    value_template: "{{ trigger.from_state.state != trigger.to_state.state }}"
  action:
    service_template: input_boolean.turn_{{ trigger.to_state.state }}
    data:
      entity_id:
        - input_boolean.light_lux_livingroom

Thanks again for your great input!
Your solutions is an overal great one, I will implement this in my automations!

But actually the problem was coincidental with a bugg. (solved in 86.1)

So main problem was solved with update but your solution still is great for stopping automations from constant firing.