So, this makes some assumptions. But I think this can be done in a single automation.
I don’t have all of the devices you have, so I can’t fully test this. I have all Roku devices that I can control from HA and I stole some of my code from that.
Assumptions:
- All of your devices use the remote.send_command action to send the button presses.
- All of your devices use the same commands for the button presses.
- The entity ids of your devices are remote.atv, remote.Chromecast, remote.cableTV, and remote.shieldTV.
Adjustments may need to be made.
I made an input_text helper named remote_device.
There are two sets of triggers. The first set is the four color buttons that use a trigger_id of color.
The rest of the irremote buttons are in the next group and no trigger_id.
The first choose action condition is for trigger_id of color. If so, strip off the front of the trigger.entity_id and save the color in the input_text helper.
Anything not a color button falls into the choose default. Build a couple variables:
device_entity_id - derived from a list of button color and entity_id using the input_text helper to select the correct one.
remote_command - strips off the front of the trigger.entity_id to get the button name. For my Rokus, the vol up and down commands are actually volume_up and volume_down. So, I do a replacement to change those.
Then the action is the remote.send_command using those two variables.
Mode is queued so each subsequent button push will run after the previous completes.
Maybe you can adapt this based on your specific device requirements.
description: "Remote"
mode: queued
triggers:
- entity_id:
- binary_sensor.irremote_red
- binary_sensor.irremote_green
- binary_sensor.irremote_yellow
- binary_sensor.irremote_blue
to: "on"
id: color
- entity_id:
- binary_sensor.irremote_up
- binary_sensor.irremote_down
- binary_sensor.irremote_right
- binary_sensor.irremote_left
- binary_sensor.irremote_enter
- binary_sensor.irremote_channel_up
- binary_sensor.irremote_channel_down
- binary_sensor.irremote_vol_up
- binary_sensor.irremote_vol_down
to: "on"
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id:
- color
sequence:
- action: input_text.set_value
target:
entity_id: input_text.remote_device
data:
value: "{{ trigger.entity_id | replace('binary_sensor.irremote_', '') }}"
default:
- variables:
device_entity_id: |
{{ ([
{'button_color': 'red', 'device_entity_id': 'atv'},
{'button_color': 'green', 'device_entity_id': 'Chromecast'},
{'button_color': 'yellow', 'device_entity_id': 'cableTV'},
{'button_color': 'blue', 'device_entity_id': 'shieldTV'}
] | selectattr("button_color", "eq", states('input_text.remote_device')) | map(attribute="device_entity_id") | list)[0] }}
remote_command: "trigger.entity_id | replace('binary_sensor.irremote_', '') | replace('vol_', 'volume_')"
- action: remote.send_command
metadata: {}
data:
command: "{{ remote_command }}"
target:
entity_id: remote.{{ device_entity_id }}