Tidying up Automations

So, I have the following 9 Automations and I’m looking for suggestions on how I could tidy them up the best way. They all run with similar parameters and I believe they currently putting a reasonable load on the system.

Would i be best using Scenes / Scripts? And how would they look?

# Fibaro Change Channel
- id: fibaro_kids
  alias: Variable Channel Kids
  trigger:
  - entity_id: sensor.ha_change_channel
    from: '0'
    platform: state
    to: '1'
  action:
  - data:
      command:
        - 2
        - 2
      device: "20292110"
      entity_id: remote.living_room
    service: remote.send_command
- id: fibaro_mate
  alias: Variable Channel Mate
  trigger:
  - entity_id: sensor.ha_change_channel
    from: '0'
    platform: state
    to: '2'
  action:
  - data:
      command:
        - 6
        - 3
      device: "20292110"
      entity_id: remote.living_room
    service: remote.send_command
- id: fibaro_life
  alias: Variable Channel Life
  trigger:
  - entity_id: sensor.ha_change_channel
    from: '0'
    platform: state
    to: '3'
  action:
  - data:
      command:
        - 5
        - 4
      device: "20292110"
      entity_id: remote.living_room
    service: remote.send_command
- id: fibaro_nine
  alias: Variable Channel Nine
  trigger:
  - entity_id: sensor.ha_change_channel
    from: '0'
    platform: state
    to: '4'
  action:
  - data:
      command:
        - 5
        - 0
      device: "20292110"
      entity_id: remote.living_room
    service: remote.send_command
- id: fibaro_go
  alias: Variable Channel Go
  trigger:
  - entity_id: sensor.ha_change_channel
    from: '0'
    platform: state
    to: '5'
  action:
  - data:
      command:
        - 5
        - 3
      device: "20292110"
      entity_id: remote.living_room
    service: remote.send_command
- id: fibaro_seven
  alias: Variable Channel Seven
  trigger:
  - entity_id: sensor.ha_change_channel
    from: '0'
    platform: state
    to: '6'
  action:
  - data:
      command:
        - 6
        - 0
      device: "20292110"
      entity_id: remote.living_room
    service: remote.send_command
- id: fibaro_me
  alias: Variable Channel Me
  trigger:
  - entity_id: sensor.ha_change_channel
    from: '0'
    platform: state
    to: '7'
  action:
  - data:
      command:
        - 2
        - 3
      device: "20292110"
      entity_id: remote.living_room
    service: remote.send_command
- id: fibaro_abc
  alias: Variable Channel ABC
  trigger:
  - entity_id: sensor.ha_change_channel
    from: '0'
    platform: state
    to: '8'
  action:
  - data:
      command:
        - 2
        - 0
      device: "20292110"
      entity_id: remote.living_room
    service: remote.send_command
- id: fibaro_sbs
  alias: Variable Channel SBS
  trigger:
  - entity_id: sensor.ha_change_channel
    from: '0'
    platform: state
    to: '9'
  action:
  - data:
      command:
        - 3
        - 0
      device: "20292110"
      entity_id: remote.living_room
    service: remote.send_command

Why do you think that?

They sit there doing nothing using no resources until triggered. It does not look like they would be triggered very often either.

When they are triggered they don’t do massive recursive operations either. Just one straight forward service call.

Even if you surf tv channels all night your cpu would barely notice.

You could do something like this:

- id: fibaro_change_channel
  alias: Fibaro Change Channel
  trigger:
  - entity_id: sensor.ha_change_channel
    from: '0'
    platform: state
  action:
  - data_template:
      command:
        - "{{ [2, 6, 5, 5, 5, 6, 2, 2, 3][trigger.to_state.state|int - 1] }}"
        - "{{ [2, 3, 4, 0, 3, 0, 3, 0, 0][trigger.to_state.state|int - 1] }}"
      device: "20292110"
      entity_id: remote.living_room
    service: remote.send_command

EDIT: It’s possible, however, that that won’t work, if the remote.send_command service doesn’t properly deal with strings in its command parameter. I’ve seen this before with other, similar services. In that case, the action could very easily be done in a python_script that is called by the automation.

1 Like

That’s pretty nifty Phil.