MQTT automation to on/off devices

alias: MQTT for computer LCDs
description: ""
trigger:
  - platform: mqtt
    topic: switch/lcds
condition:
  - condition: template
    value_template: trigger.payload
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id:
        - switch.m1_lcd
        - switch.m2_lcd
  - service: switch.turn_on
    data: {}
    target:
      entity_id:
        - switch.m1_lcd
        - switch.m2_lcd
mode: single

Above is my semi-working automation. It only turns off the monitors…

I would like the LCDs to turn on/off when I run publish switch/lcds on or publish switch/lcds off from my tasmota.

What am I missing?

Thank you.

alias: MQTT for computer LCDs
description: ""
trigger:
  - platform: mqtt
    topic: switch/lcds
action:
  - choose:
    - conditions:
        - condition: template
          value_template: '{{ trigger.payload == "on" }}'
      sequence:
        - service: switch.turn_on
          data: {}
          target:
            entity_id:
              - switch.m1_lcd
              - switch.m2_lcd
    default:
      - choose:
        - conditions:
            - condition: template
              value_template: '{{ trigger.payload == "off" }}'
          sequence:
            - service: switch.turn_off
              data: {}
              target:
                entity_id:
                  - switch.m1_lcd
                  - switch.m2_lcd
mode: single

I managed to get it to work, but:

  1. Is there a way to make it case-insensitive? ON and on both will work etc?
  2. Or shorten/simplify it? It looks like too much code for something this simple, i.e. not readable
alias: MQTT for computer LCDs
description: ""
trigger:
  - platform: mqtt
    topic: switch/lcds
action:
  - data:
      entity_id: 
        - switch.m1_lcd
        - switch.m2_lcd
    service: switch.turn_{{ trigger.payload}}
mode: single
1 Like

OMG BEAUTIFUL!:man_facepalming: haha