Automation with multiple triggers at the same time

Hello,

I am trying to set some automation that will trigger when 2 drop-down inputs are changed. But i am having no luck as i dont know much about this :sweat:

So far i added in configuration.yaml the definition for the dropdown selection:

input_select:
  air_purifier:
    name: Air Purifier
    options:
    - Birou
    - Living
    - Dormitor
    icon: mdi:fan
  purifier_mode:
    name: Mode
    options:
    - Favorite
    - Auto
    - Silent
    - Idle
    icon: mdi:fan
  fan_speed:
    name: Fan speed
    options:
    - 1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    - 10
    - 11
    - 12
    - 13
    - 14
    - 15
    - 16
    icon: mdi:fan

I made a card showing the selections. Now i actually want to change the mode of a purifier by selecting options from the dropdown list. For example: select Living, Auto and the purifier should go in auto mode.
The service to control the purifier is:
fan.set_speed with the entities: fan.air_purifier_birou ; fan.air_purifier_living and fan.air_purifier_bedroom.

Now i get to the part where i am lostā€¦ i have added the following in automations.yaml

- alias: Air Purifiers Selector
  trigger: 
  - platform: state
    entity_id: input_select.air_purifier
  - platform: state
    entity_id: input_select.purifier_mode
  action:
  - service: fan.set_speed
    data_template:
      entity_id: >    
        {% if is_state("input_select.air_purifier", "Birou") %}
         fan.air_purifier_birou.purifier_mode
        {% else %}
        {% endif %}

Oviously it doesnt do anything ā€¦

Can someone please help ?

Thank you

{% if is_states("inā€¦

It is not that.
Going to developer tools:

this works.

So i guess my service call is wrong. But how to make it right?!

I guess i neet to somehow replace the Service data with the value from purifier_modeā€¦ but howā€¦

that doesnā€™t look rightā€¦
You also donā€™t provide a fan speed

I donā€™t think thatā€™s correctā€¦

there is no ā€œsā€ added.

But to the OP the problem might be that you donā€™t have an ā€œelseā€ value specified.

And you donā€™t have a speed to tell it what to set it to.

data_template:
  entity_id: >    
    {% if is_state("input_select.air_purifier", "Birou") %}
     fan.air_purifier_birou
    {% else %}
      # something here
    {% endif %}
  speed: >
    # probably a template here to use the state of the input select to determine the speed.

Youā€™ll have to come up with a template for that too probably.

No itā€™s not correct. Not sure what I was thinking.

Yes the ā€œspeedā€ i need to provide is actually a mode, defined in purifier_mode input select. I provided a pic of a service call that works. But how to translate that to the automations ?

  action:
  - service: fan.set_speed
    data_template:
      entity_id: >    
        {% if is_state("input_select.air_purifier", "Birou") %}
          fan.air_purifier_birou.purifier
        {% elif is_state("input_select.air_purifier", "Living") %}
          fan.air_purifier_birou.living
        {% else%}
          fan.air_purifier_birou.dormitor
        {% endif %}
      speed: >
        {% if is_state("input_select.fan_speed", "1") %}
          1
        {% elif is_state("input_select.fan_speed", "2") %}
          2
        {% elif is_state("input_select.fan_speed", "3") %}
          3
        {% elif is_state("input_select.fan_speed", "4") %}
          4
        {% elif is_state("input_select.fan_speed", "5") %}
          5
## you get the idea. All the way up to 15
        {% else%}
          16
        {% endif %}
## the do the same for..
      purifier_mode: >
        {% if is_state("input_select.purifier_mode", "Favorite") %}
          Favorite
        {% elif is_state("input_select.purifier_mode", "Auto") %}
          Auto
        {% elif is_state("input_select.purifier_mode", "Silent") %}
          Silent
        {% else%}
          Idle
        {% endif %}

So your default mode if something goes wrong will be:

  - service: fan.set_speed
    entity_id: fan.air_purifier_birou.dormitor
    speed: 16
    purifier_mode: Idle

If you want different defaults in the case of some unexpected error, change the else values. But make sure all the other values for the option are covered in the if or elif statements.

Yay thank you ! :smiley: I made good progess:


- id: '1588341438457'
  alias: xxx
  description: ''
  trigger:
  - entity_id: input_select.air_purifier
    platform: state
  - entity_id: input_select.purifier_mode
    platform: state
  condition: []
  action:
  - service: fan.set_speed
    data_template:
      entity_id: >    
        {% if is_state("input_select.air_purifier", "Bedroom") %}
          fan.air_purifier_bedroom
        {% elif is_state("input_select.air_purifier", "Living") %}
          fan.air_purifier_living
        {% else%}
          fan.air_purifier_birou
        {% endif %}
      speed: >
        {% if is_state("input_select.purifier_mode", "Auto") %}
          Auto
        {% elif is_state("input_select.purifier_mode", "Silent") %}
          Silent
        {% else %}
          Favorite
        {% endif %} 
  - service: xiaomi_miio.fan_set_favorite_level
    data_template: 
      entity_id: >    
        {% if is_state("input_select.air_purifier", "Bedroom") %}
          fan.air_purifier_bedroom
        {% elif is_state("input_select.air_purifier", "Living") %}
          fan.air_purifier_living
        {% else%}
          fan.air_purifier_birou
        {% endif %}    
      level: >
        {% if is_state("input_select.fan_speed", "1") %}
          1
        {% elif is_state("input_select.fan_speed", "2") %}
          2
        {% elif is_state("input_select.fan_speed", "3") %}
          3
        {% elif is_state("input_select.fan_speed", "4") %}
          4
        {% elif is_state("input_select.fan_speed", "5") %}
          5
        {% elif is_state("input_select.fan_speed", "16") %}
          16
        {% elif is_state("input_select.fan_speed", "7") %}
          7
        {% elif is_state("input_select.fan_speed", "8") %}
          8
        {% elif is_state("input_select.fan_speed", "9") %}
          9
        {% elif is_state("input_select.fan_speed", "10") %}
          10
        {% elif is_state("input_select.fan_speed", "11") %}
          11
        {% elif is_state("input_select.fan_speed", "12") %}
          12
        {% elif is_state("input_select.fan_speed", "13") %}
          13
        {% elif is_state("input_select.fan_speed", "14") %}
          14
        {% elif is_state("input_select.fan_speed", "15") %}   
          15
        {% else%}
          6
        {% endif %}        

First Service (changing mode Auto/Fav/Silent) works very well.
However, changing the fan speed reguired another service, which i have added but it does not work. Log shows nothing but it does not do anything.
Any ideeas ? I think it has something to do with the fact that i am calling 2 servicesā€¦

You could simplify those templates quite a bit:

  entity_id: "fan.air_purifier_{{ states('input_select.air_purifier').lower() }}"

As long as the entity IDs all start with fan.air_purifier_ and the input select options match the end of the entity IDs (as youā€™re already doing) itā€™ll work.

  speed: "{{ states('input_select.fan_speed') }}"

As long as the input_select speeds match actual fan speeds that can be set youā€™ll be good here too.

1 Like

Nice one :smiley:

now my code looks like this:


- id: '1588341438457'
  alias: xxx
  description: ''
  trigger:
  - entity_id: input_select.air_purifier
    platform: state
  - entity_id: input_select.purifier_mode
    platform: state
  condition: []
  action:
  - service: fan.set_speed
    data_template:
      entity_id: "fan.air_purifier_{{ states('input_select.air_purifier').lower() }}"
      speed: >
        {% if is_state("input_select.purifier_mode", "Auto") %}
          Auto
        {% elif is_state("input_select.purifier_mode", "Silent") %}
          Silent
        {% else %}
          Favorite
        {% endif %} 
  - service: xiaomi_miio.fan_set_favorite_level
    data_template: 
      entity_id: "fan.air_purifier_{{ states('input_select.air_purifier').lower() }}"
      level: "{{ states('input_select.fan_speed') }}"       
          
          

The service: fan.set_speed works but service: xiaomi_miio.fan_set_favorite_level doesn not work.
One has a red line in front, one a blackā€¦ What to change :sweat:

using the build in service call works with xiaomi_miio.fan_set_favorite_level
image

Aha I found why it was not working. i forgot to set trigger for second service also.

Clean and working code now :slight_smile:


- id: '1588341438457'
  alias: xxx
  description: ''
  trigger:
  - entity_id: input_select.air_purifier
    platform: state
  - entity_id: input_select.purifier_mode
    platform: state
  - entity_id: input_select.fan_speed
    platform: state    
  condition: []
  action:
  - service: fan.set_speed
    data_template:
      entity_id: "fan.air_purifier_{{ states('input_select.air_purifier').lower() }}"
      speed: >
        {% if is_state("input_select.purifier_mode", "Auto") %}
          Auto
        {% elif is_state("input_select.purifier_mode", "Silent") %}
          Silent
        {% else %}
          Favorite
        {% endif %} 
  - service: xiaomi_miio.fan_set_favorite_level
    data_template: 
      entity_id: "fan.air_purifier_{{ states('input_select.air_purifier').lower() }}"
      level: "{{ states('input_select.fan_speed') }}"       

Thank you for all the help :smiley: Learned something new today.

You can simplify it further:

  action:
  - service: fan.set_speed
    data_template:
      entity_id: "fan.air_purifier_{{ states('input_select.air_purifier').lower() }}"
      speed: "{{ states('input_select.purifier_mode') }}"
  - service: xiaomi_miio.fan_set_favorite_level
    data_template: 
      entity_id: "fan.air_purifier_{{ states('input_select.air_purifier').lower() }}"
      level: "{{ states('input_select.fan_speed') }}" 

Pretty soon i will have 1 line of code for my 2 pages :rofl: :rofl: awsome

Nowā€¦ to take it to the next level :smiley: Is it possible to have some Accept/Reject buttons on the card and that the changes are applied only if i hit Accept ?

card looks basic now:
image

you can use this:

but itā€™s only for the toggles as far as I know. I donā€™t think it will work for the input select.

Not a surprise that itā€™s hard to keep track of. Thatā€™s the one place where consistency is truly lacking and it makes it way harder.

TBH, I always need to look it up myself and did this time too just to make sure before i postedā€¦ :wink: