MQTT - A noob just learning!

Just looking for some guidance to help the penny drop!

I’ve setup the native MQTT broker within HA. I’ve added a MQTT test switch into my config. I’ve connected a MQTT test client (MQTT.FX) and successfully published the ON and OFF payloads and can see the switch react.

Great!

Now for the questions.

I haven’t setup any subscription on the broker or did I? Does the switch act like a subscription or by very nature does the subscription not apply to the broker? Is my HA app effectively a client with a subscription?

I think MQTT is a good way forward to add things like door and window switches to my automation setup. What information do i look for in hardware to understand that MQTT functions is supports?

If I try to use RF switches, what hardware is needed to accept the RF and fire a MQTT on the IP network? Sonoff bridge, broadlink pro?

Thanks in advance folks for any help or suggestions!

I would recommend watching a few videos. DrZzs and Bruh have several that deal with MQTT, sonoffs and Tasmota from ESP8266’s.

Also look into the cookbooks for example configurations. Cookbook

I am still just getting started with MQTT, I have learned a lot from the videos.

Any MQTT sensor gets its data from a subscription to the state_topic.
Any MQTT switch gets the status of the switch from a subscription to the state_topic, unless optimistic: true is set.

Basically, any information from the MQTT broker requires a subscription.

I use OpenMQTTGateway to get 433MHz signals in to HA. It does a lot more these days as well. There are some other similar projects around.

I haven’t setup any subscription on the broker or did I? Does the switch act like a subscription or by very nature does the subscription not apply to the broker? Is my HA app effectively a client with a subscription?

Clients publish (PUB) and subscribe (SUB) to topics and that’s pretty much MQTT in a nutshell, no joke. All of this is done with topics.

When a client connects to a broker it tells the broker which topic(s) it wants to watch. Topics are very specific. ie home-assistant/front-porch is not the same as home-assistant/front-porch/ and still not the same as home-assistant/Front-Porch. This is probably the most important thing to know. Case sensitive. Learn it. Love it. Buy it a coffee. Again, case sensitivity.

So once a client subs to a topic (Imagine subscribing to a magazine) the broker will send it a copy of any message on that topic. Similar to ordering (subscribing) a magazine from a company that sells 100’s of magazines. They know exactly which magazine you want and will only send you what you asked for.

Now for the other side. In order to get your message (magazine) the magazine company publishes the message (magazine) that you subscribed to. They send it to the broker, and the broker sends it to you. It’s that simple.

You can go even further when you start looking at wildcard subscribing and stuff but for the most part it’s pretty simple. One other important part to understand is the retain flag. This has been a big thorn in the side of most DIY people finding their lights or garage door going up and down in the middle of the night. A retain flag is just that, it tells the broker to keep that message in stock always so when someone subscribes to the topic they can get the message. If there is no retain flag the message is published and then discarded. Most of the time you won’t need the retain flag but it’s good to know how it works because it certain ecosystems it can be important.

There’s a quick and dirty about MQTT.

Appreciate the replies.

Think I’m getting there. I had to “connect” the mqtt.fx client to the broker in order to publish the payload message.

What I didn’t have to do is “connect” the MQTT switch defined in HA to the broker…did this happen automatically?

If you define an mqtt switch in your HA configuration, it tells HA to connect to your MQTT broker. It is implied in setting an HA MQTT component that HA will connect to your broker.

When you make a “dummy” switch in HA it is automatically connected to the broker thru the HA config. But that “switch” really won’t “do” anything except publish commands to the MQTT broker on a topic defined in the config and receive messages that it is subscribed to that the broker receives. To do anything in the real world your physical switch has to be subscribed or publish to the same topics. In the physical switch setup you will need to tell it the broker information so it knows where to look for the topic it is subscribed to and to where it needs to publish to a topic.

Yes your HA is a client and has a client id. and each client id has to be unique for every device. Some devices (like HA) can randomly generate one but some require that you set it up manually. just make sure they are all unique.

A broadlink can’t receive RF/IR codes except when it is temporarily placed in learning mode. So it’s good for resending codes that you have previously learned but it can’t act as a relay between RF & MQTT devices.

I was looking into the sonoff bridge but found that it can only support a limited number of devices so you will want to check that out if you are thinking of using it.

Your best bet if you really want to use RF stuff is using what @gpbenton posted about. But again there are some limitations to it as well. the biggest one for me was that it couldn’t support my hunter ceiling fan remotes. there are other options but most open source stuff is based on the same arduino libraries so if something doesn’t work on one platform it most likely won’t work on other platforms without special support being built in. Which is difficult (or impossible) to achieve at times.

Just make sure whatever hardware you use is noted as being compatible with whatever platform you go with before you buy it. I’ve got unusable stuff lying around from failed attempts.

Thanks for these suggestions. I’m just starting out trying to figure out how to Integrate Shairpoint-sync with HA via MQTT, and these videos seem like what I was missing.