MQTT on HA Docker

I am trying to get the MQTT up running but have issues as usual.
Installed the Mosquitto-MQTT.
Installed the “apt-get install mosquitto-clients”.
I am now trying the mosquitto_sub / mosquitto_pub but it fails.

The mosquitto_sub I assume should listen on the device IP even though I run MQTT in a container .
I have the device IP in the config file…

Anyone that can give a hint to how I can see if there are any events comming in?
Thanks in advance

I am confused about how you installed Mosquitto.

You said you installed it via “apt-get” but then you said you installed it via a docker container. Could you be more specific on how you installed it?

and what do you mean by it fails?

I can probably help you out whether you installed it via the command line or via docker but I need to know which one you’re trying to get working first.

Sorry if I am unclear.
I am running HA on docker 0.100.1. and installed Mosquitto broker as a normal HA add-on and this is now running in a container as well.
Then to test MQTT I wanted to use the mosquitto_sub / mosquitto_pub and to do so I needed to install “mosquitto-clients” with apt-get command. This was not done in the Mosquitto Container but on the Pi operating system.

My objective is just to publish something and see it on the MQTT bus with the “_sub” - and I fail to do this…
I suspect it might be related to that the clients are not in the container but MQTT is - but this is just a guess…
I hope this makes a bit of sense and that you or anyone can hint something to get me forward.

There is no reason to use mosquitto-client. All you need is a mqtt sniffer program on some computer that can connect to your mqtt broker. Mqttfx or mqtt explorer will work. Then you can publish and subscribe there to check the broker operation.

If that works then you can do a mqtt.publish service in HA and see if it shows up in your sniffer program.

In the docker command for mosquitto you exposed port 1883?

And with mosquitto_pub and sub, is that being called from the host? so
mosquitto_sub -h localhost:1883 -t test -m "just testing"
would work if your docker command did have the port exposed.

Or from another machine, the -h will change to
<machine or ip of mosquitto docker container>

MQTT explorer is what you want on your desktop/laptop to troubleshoot

I managed to get things ongoing but one question left…

In automation I have a lamp that should toggle based on MQTT trigger:

- id: '1547694321781'
  alias: MQTT - Light Control - Wallswitch
  - payload: 'true'
    platform: mqtt
    topic: home-assistant/switch1/status
  - payload: 'false'
    platform: mqtt
    topic: home-assistant/switch1/status
  condition: []
  - data:
      entity_id: light.fibaro_system_fgd212_dimmer_2_level
    service: light.toggle

With MQTT explorer I can update MQTT broker on topic: “home-assistant/switch1/status” and the light toggle.
I also created a switch:

- id: '1571081499999'
  alias: mqtt_on
  - entity_id: switch.wallswitch
    from: 'off'
    platform: state
    to: 'on'
  - data:
      payload: true
      topic: home-assistant/switch1/status
    service: mqtt.publish
- id: '1571081499998'
  alias: mqtt_off
  - entity_id: switch.wallswitch
    from: 'on'
    platform: state
    to: 'off'
  - data:
      payload: false
      topic: home-assistant/switch1/status
    service: mqtt.publish

Now the strange thing:
When I publish from MQTT explorer client the broker is updated and the light toggles.
When i turn the 433Mhz “switch.wallswitch” on or off the broker is updated with correct information (same as from the MQTT explorer) but the light does not toggle.
The light only reacts on MQTT updates when they come from MQTT explorer and not from the Automation script…

Anyone that can see what I am doing wrong?

The only difference I see is that you have quotes around the true & false payloads in the first automation above but in the second there are no quotes.

1 Like

Thanks man!
Works with this change :slight_smile: