Service_templating: Can I do "if( 1 and 2 ) result, elif ..."?

Does anybody know how to make a service_template that acts like:

service_template: if( 1 AND 2 ) switch, elif(2 AND 3) switch

Here’s some dummy code for further illustration:

automation:
  - alias: 'Thermostat A/C state monitor'
    ....(lots of code)....
    action:
        service_template: >
           {% if {{is_state("switch.ac_power", "off")}} AND {{is_state("input_boolean.thermostat_control", "on")}} AND {{is_state("input_select.thermostat_ai_mode", "Avg all rooms")}} AND {{ float(states.sensor.indoor_temp.state) >= ( float(states.input_slider.thermostat.state) + float(1.0) ) }}%} switch.turn_on
           {% elif %} .....LOTS OF OTHER CONDTIONS.....
           {% endif %}
        entity_id: switch.ac_power

I’m no code ninja with Jinja2 :slight_smile:

Sure it is:

{% if is_state("switch.ac_power", "off") and is_state("input_boolean.thermostat_control", "on") and is_state("input_select.thermostat_ai_mode", "Avg all rooms") and  (states.sensor.indoor_temp.state | float >= states.input_slider.thermostat.state| float + 1)%} 
switch.turn_on
{% elif  .....LOTS OF OTHER CONDTIONS.....%}
switch.turn_off
{% endif %}
1 Like

Thanks! That did it