MQTT publish in JSON format

Hello! I’m trying to set the color (to full red) of an internal RGB light of an android tablet. I use the following code but It does not work. All commands should be in JSON format according to the tablet MQTT API documentation

service: mqtt.publish

topic: …/rgb/commands
payload: “{“command”:“SET_STATE”,“value”:“FF0000”}”

When I manually set the state and listen to the topic I got the following:
Message 1 received on …/rgb/events at 8:51 PM:

“function”: “RGB”,
“timestamp”: 1643053906517,
“unit”: null,
“value”: “11665424”

I tried publishing with a different value (“11665424” instead of “FF0000”) and without escaping, but nothing works.

I only use MQTT with zigbee through zigbee2mqtt, so I am not sure if it applies to you, but the topic goes without quotes in yaml. Also, numeric values often go without quotes too. In your example "11665424" could be 11665424. I am pasting a piece of my format, which works, but again I am not sure if this applies to you. Perhaps you can experiment with the syntax based on it?

- service: mqtt.publish
    topic: zigbee2mqtt/LED Strip Sypialnia/set
    payload: '{"brightness":254,"color":{"x":0.444,"y":0.517},"color_mode":"xy","state":"ON"}'

Thanks for the suggestion. Unfortunately It’s not working without quotes

Perhaps you can point out the API you have mentioned, so someone who might also be using it will help you?

I would test whether the topic is right, as even capital letter vs non capital makes a difference in my mqtt.publish stuff. Just an idea?

I use MQTT Explorer to test things independently from HA and it really helps to grab nicely what is published.

It’s a Zipatile2 (android oreo 8.1) tablet that I’m trying to control locally with my HA server. The API is quite simple and can be found here:

This works for me:

  - data:
      payload: '{"Protocol":"NEC","Bits":32,"Data":"0x44BBD827","DataLSB":"0x22DD1BE4","Repeat":0}'
      topic: IR_bridge/cmnd/IRsend
    service: mqtt.publish

I think the issue on my side is that json format is required but I’m not sure how to do it properly