MQTT Publish in scripts.yaml

Hi al, I’m really struggling with getting a mqtt publish in my scripts.yaml file. With the musquitto client I am able to send my mqtt message with the following command:

mosquitto_pub -h localhost -p 1883 -m '{"command": "switchlight", "idx" : 223, "switchcmd": "On" }' -t domoticz/in

When I try to put it in my scripts.yaml I keep getting errors in my log regarding to my scripts.yaml file, I finally got something that give no error, but now it simply does not work. This is what I got now:

mqqtappletv:
  alias: 'Send AppleTV state to Domoticz'
  sequence:
    - service: mqtt.publish
      data:
        topic: "command: switchlight, idx: 223, switchcmd: On"
        payload: "domoticz/in"

I tried many different things, adding ’ or " or { and } but nothing seems to work so far. I hope someone has the answer!

There seems to be a mix-up between topic and payload.

Oh yeahhh, how stupid. Can’t tell you for how many hours I have been staring at my code without realising that.

After switching it back I still had some troubles, but after re-adding the { and } signs with the needed quotes I got it working, many thanks!

This is my working code, just in case anybody would be interested:

mqqtappletv:
  alias: 'Send AppleTV state to Domoticz'
  sequence:
    - service: mqtt.publish
      data:
        topic: "domoticz/in"
        payload: '{ "command": "switchlight", "idx": 223, "switchcmd": "On" }'
4 Likes