Automation MQTT send text

In order to send a fix text over MQTT, I have added the following in my config.yaml:

automation:
- alias: Red1
  trigger:
    platform: state
    entity_id: switch.R1_REL1
    state: 'on'
  action:
    service: mqtt.publish
    data: {"payload": "Test message from HA", "topic": "home/notification", "qos": 0, "retain": 0}

and I got error:

   homeassistant.util.yaml: mapping values are not allowed here
    in "/home/homeassistant/.homeassistant/configuration.yaml", line 241, column 19

Please tell me what syntax to use here. Thank you

1 Like

Not sure but try changing from

data: your message
TO
data:
  message: your message

Thank you, finally I got it working:

  action:
    service: mqtt.publish
    data:
      topic: "home/notification"
      payload: "Test message from HA"
5 Likes