Need help with data_template in script

Hey, all
I trying to setup multi-switch for my purifier, but have problems.
why it not working, help ))

lr_mode_change:
  sequence:
    service: fan.set_speed
    data_template:
      entity_id: fan.livingroom_airpurifier 
      speed: >
        {% if is_state("sensor.xiaomi_lr_airpurifier_mode", "auto") %}
          favorite
        {% elif is_state("sensor.xiaomi_lr_airpurifier_mode", "favorite") %}
          silent
        {% else %}
          auto
        {% endif %}

what’s not working? Gotta give a little more detail :wink:

Nothing working
No error in log, no error in ha log

2019-12-07 22:31:12 INFO (MainThread) [homeassistant.helpers.script] Script lr_mode_change: Running script,
2019-12-07 22:31:12 INFO (MainThread) [homeassistant.helpers.script] Script lr_mode_change: Executing step call service

but no any effect

and are those speed names correct? They don’t look correct

Yep, correct
When I try make it with “data” without template - all working perfect
This is current speed and speed list for putifier:

speed: Auto
speed_list:
  - Auto
  - Silent
  - Favorite

These are ‘Proper’ not ‘lower’

1 Like

Yep, that’d be the problem.

        {% if is_state("sensor.xiaomi_lr_airpurifier_mode", "auto") %}
          Favorite
        {% elif is_state("sensor.xiaomi_lr_airpurifier_mode", "favorite") %}
          Silent
        {% else %}
          Auto
        {% endif %}

sorry? what’s do you mean?

Upper case for the first letter.

Proper
lower
UPPER

it does not matter in this case
when I try make

lr_mode_change:
  sequence:
    service: fan.set_speed
    data:
      entity_id: fan.livingroom_airpurifier 
      speed: auto

mode changes

P.S. I tried now with upper case and same result - no anything )

not sure how that works when the yaml is invalid. Edit: appears you edited it.

and what does sensor.xiaomi_lr_airpurifier_mode states look like?

Auto

in the states page please

Alright, then it appears you need the capitals in your template assuming no translation is occuring but the states page should show without translations.

        {% if is_state("sensor.xiaomi_lr_airpurifier_mode", "Auto") %}
          favorite
        {% elif is_state("sensor.xiaomi_lr_airpurifier_mode", "Favorite") %}
          silent
        {% else %}
          auto
        {% endif %}
1 Like

YEEEES!!! It worked!!
thank you so much!

1 Like