Choosing scene based on input-select value

I want to choose the scene based on the value in the input select. (in the example, i want to turn off the light on a button press if it is at 50% but on if it is at a different level), it looks like templates is the way to do this? I tried something like this:

action:
   data_template:
     entity_id: >-
     {% if is_state("input_select.dolys","50") %}
     - service: light.turn_off
        entity_id: light.do_ltak

     {% else %}
      - service: light.turn_on
        entity_id: light.do_ltak

     {% endif %}

But this doesn’t quite seem to work out. Is this the best way to do this? Am i doing something weird here?

If you want to specify a service using a template, you use service_template, not data_template:

action:
  entity_id: light.do_ltak
  service_template: >
    {% if is_state("input_select.dolys","50") %}
      light.turn_off
    {% else %}
      light.turn_on
    {% endif %}
1 Like

Thanks, can i move the entity inside the if, to trigger scenes and other things as well? For instance:

action:
  service_template: >
    {% if is_state("input_select.dolys","50") %}
      light.turn_off
    {% else %}
     light.turn_on          
     entity_id: light.do_ltak
     scene.turn_on
     entity_id: scene.do_vanlig
     input_select.select_option
     data:
        entity_id: input_select.dolys
        option: 50
     
    {% endif %}

No. Templates exist in a single item, not the other way around (i.e., items do not exist in templates.) But in your case, you might do this:

action:
  entity_id: light.do_ltak
  service_template: >
    {% if is_state("input_select.dolys","50") %}
      light.turn_off
    {% else %}
      scene.turn_on
    {% endif %}
  data_template:
    entity_id: >
      {% if is_state("input_select.dolys","50") %}
        light.do_ltak
      {% else %}
        scene.do_vanlig
      {% endif %}

You should probably read up on templates, including following some of the links on that page (especially about Automation Templating.)