Basic setup. How to check if mqtt is working?

My situation: I don’t have any smart devices yet, but I want to test if I can send a message from my phone via MQTT, like described here.

I have HASS (python-env) and embedded MQTT broker (I only added 1 line with password in configuration.yaml)
I used the android app, from the topic which I linked above. I see there that connection to MQTT broker was established (“Connected to MQTT broker”).

Then I want to test that It really works. When I send a test message, nothing happens in HA web-interface, so I write an automation.

- id: '1543085016756'
  alias: 'Alarm-clock #1'
  initial_state: True
  - platform: mqtt
    topic: 'android/broadcast/redmi-4'
    condition: and
    - condition: template
      value_template: '{{ trigger.payload_json.action == "" }}'
  - entity_id: scene.awaken
    service: scene.turn_on
  - service: notify.notify
        message: 'Alarm clock triggered'

Note, that (1) I have condition with and and only 1 condition there, because otherwise I got some syntax error (will figure it out later), (2) I have two actions - one changes a scene, but I didn’t set up a scene yet, and I don’t have devices yet. The second one is - notification, which I was hoping to see. Is it the right way to get some message in HA web interface?

I can see this automation running in the web-interface, but it never got triggered.
So I wanted to ask:

  1. How can I check that my messages arrived at MQTT broker? I couldn’t find any log file for the embedded broker.
  2. How can I check that MQTT broker gave the information to HA? And do I need to do extra setup for that?
  3. If the first two steps work, what else do I need to do to trigger the automation action?

If that’s very simple questions, please tell me where I should look for answers, and what keywords to search?

That automation is definitely not running because the code is invalid. You can’t have 2 action blocks.

There is lots of software available that can be pointed to your mqtt server and see what messages it is receiving, although the names escape me at the moment. A quick Google should turn plenty up.

Interesting, the web interface says the configuration (which includes automations, I suppose) is correct. I will check what happens if I leave only one action, but I guess there are other problems.

To check for MQTT availability this should be an independent process from HA (IMHO).
For instance, I’ve a process running heartbeat checks, through MQTT, with HA and connection to MQTT, after N heartbeat failures this process restarts HA and after N missed connections to MQTT it restarts MQTT (mosquitto in my case).

I use MQTTFx on a windows machine. I connect that to my MQTT broker and then subscribe to all topics using #. then you will see every message pop up that the broker sees.

Thank you all.

I have confirmed with MQTTFx that mesages from my phone arrive at the MQTT broker. For some reason it says QoS=0 instead of 1, but I can live with that.

And actually after removing one of the actions from my original automation code - I can see it has successfully triggered, so this was the problem after all.

1 Like