bitfocus / companion-module-homeassistant-server

MIT License
12 stars 7 forks source link

How to use the "Mqtt: publish" service? #29

Open metawops opened 1 year ago

metawops commented 1 year ago

I want to use the MQTT Publish service on a button and don't know how to write the payload. First of all, the "Call service" action starts with an "Entities" parameter. Do I really need to select an entity here? Normally, the device I want to send the MQTT message to, gets addressed by the MQTT topic string. And isn't that topic string a part of the payload of the MQTT Publish service? I'm confused.

And the MQTT message I want to send needs a payload itself, in my case it's as simple as { 'name': 'mcdog' }. But putting just this into the "Payload" field and selecting the device I want to send/publish in the "Entities" field dosen't work.

Here's the yaml code that works inside a HA automation's action part:

service: mqtt.publish
data:
  qos: "0"
  topic: awtrix_a97b4c/switch
  payload: "{\"name\": \"mcdog\"}"

Here's an additional screenshot of the visual editor for the same action in HA:

Screenshot 2023-06-28 at 15 36 42

Now the question is: how can I make this work in Companion? I tried to write everything from the data: part of the above yaml code as JSON and put that into the Payload field ...

Screenshot 2023-06-28 at 15 32 00

... and tried different formats, like:

{ "qos": "0", "topic": "awtrix_a97b4c/switch", "payload": { "name": "mcdog"} }

and

{ "qos": "0", "topic": "awtrix_a97b4c/switch", "payload": "{ \"name\": \"mcdog\"}" }

... but to no avail.

I couldn't find any documentation on how to use the MQTT Publish service from within the homeassistant module. Hopefully someone can help? 😳

BenJamesAndo commented 11 months ago

Why not just use the generic MQTT module from Companion? image