Multiple triggers and actions

How to simplify below code? I don’t want to create separate automation for each different color/brightness.

- id: '1582362294780'
  alias: yeelight color change
  description: ''
  trigger:
  - entity_id: input_select.yeelight_mode
    platform: state
    to: red
  condition: []
  action:
  - data:
      brightness: 1
      rgb_color:
      - 139
      - 0
      - 0
    entity_id: light.yeelight
    service: yeelight.set_color_scene
- id: '1582362994505'
  alias: yeelight blue
  description: ''
  trigger:
  - entity_id: input_select.yeelight_mode
    platform: state
    to: blue
  condition: []
  action:
  - data:
      brightness: 1
      rgb_color:
      - 30
      - 144
      - 255
    entity_id: light.yeelight
    service: yeelight.set_color_scene

Make sure you only have CSS3 colour names in your input select then do this:

- id: '1582362294780'
  alias: yeelight color change
  trigger:
  - platform: state
    entity_id: input_select.yeelight_mode
  action:
    service: light.turn_on
    data_template:
      entity_id: light.yeelight
      color_name: "{{ states('input_select.yeelight_mode') }}"
1 Like