MQTT how to setup

Hi, these are my first steps in the world of MQTT and I am banging my head now for days on how to connect my device to home assistant.

I bought a 4 channel Dingian IOT relay to control my swimming pool pump. It can connect over MQTT.

So I installed the MQTT Broker in my Home assistant pc.

In the Broker options it says:

Broker: core-mosquitto

Port: 1883

I created a new user in home assistant and added this user to the broker options username and Password.

In the next page of the options I see

Discovery prefix: Homeassistant

MQTT was added in to my integrations and looks to work fine.

Now for the relay side; I need to give the Broker Address, Broker Port, Broker UserName and Broker password. Witch I all gave. As Broker address I use homeassistant/core-mosquitto

Then there is a little undocumented button on the relay interface labeld “HA discover” If I click on it I get the message “HA Discover Success! Please go to HomeAssistant add switch/input to panel”

But where do I get this switch or input? Or how do I command a relay to switch?
And how can I see in HA that the relay is indeed connected?

If discovery worked it should show up as a new integration for you to add in Settings → Devices and Services.

Personally I’d use the IP address just in case something goes wrong with mdns.

Question over questions. :exploding_head:

Image search shows devices/pcb’s with espressif micro controller on it - is your device powered by an esp? If so long story short (and less pita) is just to skip mqtt directly :point_down:

Thanks for your answers. Switching to ESPHome is not something I want to do now. I just want to understand MQTT. And that is a very slow process since it cost me a lot of experimenting and very small steps in understanding. At this moment I have a broker on HA that seems to work. My Dingtian relay seems to be connected. I can also connect with MQTTBox and MQTT Explorer to the broker to give commands and to listen.

I do not see anything in the HA users interface that confirms the relay is indeed connected.

The big problem is that the Relay seems unresponsive with MQTT. If via the web interface (not MQTT!) I switch a relay (And I hear it switching) I don’t seen any status update even if I subscribe to topic #.

In the Dingtian user manual there are a bunch of commands like /dingtian/relay26743/in/Control I presume I have to give a payload of {“type”:“ON/OFF”,‘idx’:‘2’,“status”:“ON”,“time”:“0”,“pass”:“0”} to switch relay 2. But nothing happens whatever I try.

So I hope someone can help me to get forward.

You have to add the discovered device first. I tell you how in my previous post.

Though by the sounds of this:

I doubt the discovery message was sent to the broker correctly.

Check the broker settings in your device.

Hi Tom, thanks for your answer.
You tell me : You have to add the discovered device first. I tell you how in my previous post.
But that is just the problem. in HA there is nothing discovered.
My Broker seems to work. It is running on my HA pc and with my laptop, running MQTTBox and MQTT Explorer I can reach it and get echo’s of my messages.

This are my broker settings:
MQTT settings
Broker: core-mosquitto
Port: 1883
Username: mqtt
Password: secret

Advanced options
client id: empty
time between sending keep allive messages: 60
use client certificate: off
broker certificate validations: off
ignore broker certificate validations: off
mqtt protocol: 3.1.1
mqtt transport: TCP

MQTT Options
enable discovery: on
discovery prefix: homeassistant
enable birth message: on
birth message topic: home assistant/status
birth message payload: online
birth message qos: 0
birth message retrain: off
enable will message: on
will message topic: home assistant/status
will message payload: offline
will message qos: 0
will message retrain: off

I am just wondering if I need to add some yaml code in my configuration.yaml file. But I think the connection should not depend on it.

an other thing I am wondering is that maybe my router is blokking the mqtt message on my network.
I have got a TP EC220 router from my brazilian provider and they are quite paranoide here. Are there network settings that I shoud check?

Again thanks very much for the help.

Ok I am again a very small step further.
I have added the yaml code from the digtian sdk to my configuration.yaml file and now I see 4 switches in my settings->Devices and Servuces → entities list that I can add to a dashboard. Only problem is there status is unavailable. so I am rather shure the iot relay has no connection with HA.

Hurrah, problem is solved. it turned out that I should not have used the broker name, but the broker IP address. and apparently that is the same as my home Assistant instance.

Anyway thank you all for your help.

I did suggest that 2 days ago.

Hi all!
I’m facing exactly the same problem, but from my side, it does not work even using IP address and it’s driving me crazy.
I have tried every possible IP address, leaving blank the Broker Address in the Dingtian settings, adding an unused one (like 192.168.0.119). I have tried also using the mqtt username and the given default password, but that didn’t work either.

TCP Server → Modbus - TCP Port:5683
TCP Client → Modbus - RTU Over TCP Remote Address (your Broker IP ) Port:5683