How to combine multiple automations into a single automation/blueprint?

I want to create a single automation/blueprint that contains 18 automations.
Below are the codes of two automations:

alias: 2F Main Bedroom Light ON via Single Press
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_a0a00a0a00
    to: button_1_single
action:
  - type: toggle
    device_id: 0000a0a0a0000a0a000aaa00000a00a
    entity_id: switch.sonoff_a00a0a0aa0_0
    domain: switch
mode: single

&

alias: 2F Main Bedroom Light Extra ON via Double Press
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_a0a0000a00
    to: button_1_double
action:
  - type: toggle
    device_id: 0000a0a0a0000a0a00a0aaa00000a00a
    entity_id: switch.sonoff_000a0a0aa0_0
    domain: switch
mode: single

I have 90 such automation that I want to integrate into a single automation/blueprint.
Can someone please tell me how I can make this possible?

The two automations you posted can be easily combined into one because they both do exactly the same thing (toggle a switch) when the sensor changes to either button_1_single or button_1_double.

alias: example
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_a0a0000a00
    to:
      - button_1_single
      - button_1_double
action:
  - type: toggle
    device_id: 0000a0a0a0000a0a0000aaa00000a00a
    entity_id: switch.sonoff_00000a0aa0_0
    domain: switch
mode: single

What do the other 88 automations do?

My bad. I tried to mask the entity id & device id; and in doing so I messed up. These two section of codes are two different automations i.e. they control two different switches. So I need a way to integrate 18 automations into a single blueprint/automation. Actually I was trying to make a blueprint for my Sonoff R5 Scene Controller. It has 6 buttons & each button support single tap, double tap & hold. So in total it can perform 18 independent automation. Sorry for my typo of 90 instead of 18. So can you please tell me how I can do the above?

Post two or three correct examples.

You can use trigger id and the choose action

1 Like

Below are the three different automations that control three different switches by using three different remote press types.
The 1st automation is triggered when I press the Button 1 of my R5 once; this toggles the Light 1.

alias: 2F Main Bedroom Light ON via Single Press
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_2f_main_bedroom_r5
    to: button_1_single
action:
  - type: toggle
    device_id: 1685a5h0k7843a1b734bff38094d13g
    entity_id: switch.sonoff_2f_main_bedroom_light
    domain: switch
mode: single

The below automation is triggered when I double press the Button 1 on my R5; which toggles the Light 2.

alias: 2F Main Bedroom Light Extra ON via Double Press
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_2f_main_bedroom_r5
    to: button_1_double
action:
  - type: toggle
    device_id: 7536f6a6n9467g7v54v0bng65070c23v
    entity_id: switch.sonoff_2f_main_bedroom_light_extra
    domain: switch
mode: single

The below automation is triggered when I long press/hold the Button 1 of my R5; which toggles the Fan.

alias: 2F Main Bedroom Fan ON via Hold
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_2f_main_bedroom_r5
    to: button_1_hold
action:
  - type: toggle
    device_id: 6589a3f6a6965f4c0912ghr43875d13d
    entity_id: switch.sonoff_2f_main_bedroom_fan
    domain: switch
mode: single

I want to know is there any way to integrate these three automations into a single automation/blueprint?

Can you please elaborate? I am total noob when it comes to automations. Based on the above automations (codes), can you please give me an example on how to use trigger id & the choose action?

alias: example 
trigger:
  - id: 'sonoff_2f_main_bedroom_light'
    platform: state
    entity_id: sensor.sonoff_2f_main_bedroom_r5
    to: button_1_single
  - id: 'sonoff_2f_main_bedroom_light_extra'
    platform: state
    entity_id: sensor.sonoff_2f_main_bedroom_r5
    to: button_1_double
  - id: 'sonoff_2f_main_bedroom_fan'
    platform: state
    entity_id: sensor.sonoff_2f_main_bedroom_r5
    to: button_1_hold
action:
  - service: switch.toggle
    target:
      entity_id: 'switch.{{ trigger.id }}'
mode: single

Another way to do the same thing:

alias: example 
trigger:
  - platform: state
    entity_id: sensor.sonoff_2f_main_bedroom_r5
    to:
      - button_1_single
      - button_1_double
      - button_1_hold
action:
  - variables:
      switches:
        button_1_single: sonoff_2f_main_bedroom_light
        button_1_double: sonoff_2f_main_bedroom_light_extra
        button_1_hold: sonoff_2f_main_bedroom_fan
  - service: switch.toggle
    target:
      entity_id: 'switch.{{ switches.get(trigger.to_state.state) }}'
mode: single

EDIT

Correction. Second example. Replaced trigger.id with trigger.to_state.state

The 1st automation code that you have posted is working. But the 2nd one is not working properly i.e. nothing happens when I single or double press the Button 1 on my R5. But the hold/long press is workin i.e it toggles the fan. BTW can you please tell me how I can control AC (Temperature Control) & RGBW LED (Shelly RGBW2 Controller) in this senario? I mean Suppose I want to include 3 automations in a single automation; the 1st one being a switch toggle, the 2nd one being Increase AC Temperature & the 3rd one being Changing the color of the RGBW controller to Cyan?

That’s due to my mistake. I have corrected the second example (replaced trigger.id with trigger.to_state.state).

When there are different service calls involved, it’s not always possible to use a service template so you must use choose.

Post the automations you currently have to control the switch, climate, and light entities.

Oh, thanks for the correction. I will try the 2nd automation soon. BTW the 2nd automation looks much tidier than the 1st one.
Below are the three different automations;

  1. In this automation Single Pressing the Button 2 on my R5 Toggles the Light
alias: 2F Main Bedroom Light ON via Single Press
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_2f_main_bedroom_r5
    to: button_2_single
action:
  - type: toggle
    device_id: 1685a5h0k7843a1b734bff38094d13g
    entity_id: switch.sonoff_2f_main_bedroom_light
    domain: switch
mode: single
  1. In this automation Double Pressing the Button 2 on my R5 does three things i.e. Turns ON the AC Switch, then Waits for 30 Seconds (It takes approximately 25s for my Samsung AC to connect to my WiFi) & then it Sets the AC Temperature to 26 in Cool Mode.
alias: 2F Main Bedroom AC On via Double Press
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_2f_main_bedroom_r5
    to: button_2_double
action:
  - type: turn_on
    device_id: a1f654f872498a00q3h84085f4454cbh
    entity_id: switch.main_bedroom_ac
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - service: climate.set_temperature
    data:
      temperature: 26
      hvac_mode: cool
    target:
      entity_id: climate.computer_room_ac
mode: single
  1. In this automation Long Pressing/Holding the Button 2 on my R5 Turns ON & Sets the RGBW LED Controller (Shelly RGBW2) to Cyan Color at 20% Brightness.
alias: 2F Main Bedroom LED On Cyan via Double
trigger:
  - platform: state
    entity_id:
      - sensor.sonoff_2f_main_bedroom_r5
    to: button_2_hold
action:
  - service: light.turn_on
    data:
      rgbw_color:
        - 0
        - 255
        - 255
        - 0
      brightness_pct: 20
    target:
      device_id: 33v54g00v2f75961356389546lo3v745
mode: single

My 2 cents; I use trigger_ID’s combined with Choose/Condition to combine mutliple automations into one.

alias: SmartAlarm Auto Arm/Disarm
description: ""
trigger:
  - platform: numeric_state
    entity_id: proximity.proximity
    above: 201
    id: Arm_above_201
  - platform: numeric_state
    entity_id: proximity.proximity
    id: Disarm_below_199
    below: 199
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Arm_above_201
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.smartalarm
      - conditions:
          - condition: trigger
            id: Disrm_below_199
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id: switch.smartalarm
mode: single

This automation will turn on the alarm system when all phones are more then 201 mtrs from the house AND turn it off again once closer than 199 mtr from the house :wink:

So I use

trigger:
  id: Arm_above_200  #(or id: Disarm_below_199)

To choose with action to use:

action:
  - choose:
     - conditions:
          - condition: trigger
            id: Arm_above_200 #(or id: Disrm_below_199)

Here’s how to consolidate the three automations.

alias: example 
trigger:
  - platform: state
    entity_id: sensor.sonoff_2f_main_bedroom_r5
    to:
      - button_1_single
      - button_1_double
      - button_1_hold
action:
  - choose:
      - conditions: "{{ trigger.to_state.state == 'button_1_single' }}"
        sequence:
          - service: switch.toggle
            target:
              entity_id: switch.sonoff_2f_main_bedroom_light
      - conditions: "{{ trigger.to_state.state == 'button_1_double' }}"
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.main_bedroom_ac
          - delay:
              seconds: 30
          - service: climate.set_temperature
            data:
              temperature: 26
              hvac_mode: cool
            target:
              entity_id: climate.computer_room_ac
      - conditions: "{{ trigger.to_state.state == 'button_1_hold' }}"
        sequence:
          - service: light.turn_on
            data:
              rgbw_color:
                - 0
                - 255
                - 255
                - 0
              brightness_pct: 20
            target:
              device_id: 33v54g00v2f75961356389546lo3v745
mode: single
3 Likes

This is working. Thanks so much for the assist. BTW the 3rd automation was not working because you have written device_id instead of entity_id.

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.

Do you mean this part?

            target:
              device_id: 33v54g00v2f75961356389546lo3v745

The target statement accepts entity_id, device_id and area_id.

1 Like

I was trying to mark your post as solution. But there is no option to do so. I refered to the guideline link that you provided, but I was unable to find that option under your post.
My bad regarding the device_id confusion. It is in fact working.
I have another request that is related to the 2nd automation.
Is there any way to perform the action of increasing or decreasing the exisiting temperature of the AC by using an automation. I mean the automation should either simply increment the existing temperature by +1 or -1. Can this be done?

Because you have the original thread/post under the wrong category (Blueprint Exchange), it should be under “Configuration”. if you change that, you should be able to mark it as solved.

1 Like

Thanks fort pointing that out.