ESPEasy - Home Assistant mqtt not working - What am i doing wrong? - Resolved

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Zodiac69
Normal user
Posts: 85
Joined: 13 Jun 2016, 17:20

ESPEasy - Home Assistant mqtt not working - What am i doing wrong? - Resolved

#1 Post by Zodiac69 » 17 Jul 2021, 18:39

I am trying to get ESPEasy to connected to Home Assistant via MQTT.
In the Mosquitto log in HA i can see that the ESP establish a connection and the controller Subscribe match my settings on the ESP - homeassistant/sensor/%sysname%, but i have not been able to get the info in HA.
When i look at Mosquitto with MQTT explored, i can see my other sensor - RPI data via Node-RED to HA mqtt, but i do not see the ESP data in the HA mqtt.

I have setup a rule on the ESP to post the IP every 30 sec. for testing.
When i look at the ESP log file, i can see the published IP.
I have also confirmed that he ESP is connected to the MQTT, if i stop HA Mosquitto, the ESP log file show the error.

I confirmed that ESP with Mosquitto is working by stetting up a Mosquitto mqtt on a separate RPI with the same credentials, and on that RPI, i can see the data when i connect with MQTT Explorer.

I have tried this with 4x ESP versions, and none of them work on HA.
ESP_Easy_mega_20210615_normal_ESP8266_4M1M
ESP_Easy_mega_20210503_normal_ESP8266_4M1M
ESP_Easy_mega_20210223_normal_ESP8266_4M1M
ESP_Easy_mega_20201130_normal_ESP8266_4M1M

Am i missing something obvious?
Last edited by Zodiac69 on 18 Jul 2021, 14:30, edited 1 time in total.

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#2 Post by Ath » 17 Jul 2021, 18:45

Please show your Controller configuration.
/Ton (PayPal.me)

Zodiac69
Normal user
Posts: 85
Joined: 13 Jun 2016, 17:20

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#3 Post by Zodiac69 » 17 Jul 2021, 19:15

Controller Settings
Protocol: Home Assistant (openHAB) MQTT
Locate Controller: Use IP address
Controller IP: 192.168.2.200
Controller Port: 1883
Controller Queue
Minimum Send Interval: 100 [ms]
Max Queue Depth: 10
Max Retries: 10
Full Queue Action: Ignore New
Allow Expire:
De-duplicate:
Check Reply: Check Acknowledgement
Client Timeout: 2500 [ms]
Credentials
Use Extended Credentials: YES
Controller User: mqtt
Controller Password: •••••
MQTT
Controller Client ID: homeassistant/sensor/%sysname%
Unique Client ID on
Reconnect:
Current Client ID: homeassistant/sensor/Garage_Door
Note: Updated on load of this page
Publish Retain Flag: YES
Controller Subscribe: homeassistant/sensor/%sysname%
Controller Publish: homeassistant/sensor/%sysname%/%tskname%/%valname%
Controller LWT Topic:
LWT Connect Message:
LWT Disconnect Message:
Send LWT to broker: YES
Will Retain: YES
Clean Session: YES
Enabled: YES

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#4 Post by TD-er » 17 Jul 2021, 19:27

Why have you checked the "extended credentials" ? That's only needed if the username or password does not fit in the normal credentials.

And please double check if your topic is the same. Mainly whether it needs a leading slash or not.
Preferred is without leading slash, but some still use a leading slash.
You have to use the same (with or without leading slash) in your entire setup.

Zodiac69
Normal user
Posts: 85
Joined: 13 Jun 2016, 17:20

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#5 Post by Zodiac69 » 17 Jul 2021, 19:37

Hi TD-er

If i do not enable "Extended Credentials" then i cant connect to HA Mosquitto as it has a username and password.
This is what i see in the HA Mosquitto log - New client connected from 192.168.2.197 as homeassistant/sensor/Garage_Door (p2, c1, k10, u'mqtt').

On my PRI with Node-RED the topic is - homeassistant/sensor/energy - no leading slashes.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#6 Post by TD-er » 17 Jul 2021, 20:15

You can still enter credentials.
The extended checkbox is to allow for longer username and password.
Can you try it with this unchecked and make sure the correct user/pass is filled in.

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#7 Post by ThomasB » 17 Jul 2021, 20:27

MQTT
Controller Client ID: homeassistant/sensor/%sysname%
Unique Client ID on
Reconnect:
Current Client ID: homeassistant/sensor/Garage_Door
Note: Updated on load of this page
Publish Retain Flag: YES
Controller Subscribe: homeassistant/sensor/%sysname%
Your Controller subscribe is missing the multilevel (#) wildcard. Maybe this matters, I don't know. As an experiment, change it to this:

Code: Select all

Controller Subscribe: homeassistant/sensor/%sysname%/#
- Thomas

Zodiac69
Normal user
Posts: 85
Joined: 13 Jun 2016, 17:20

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#8 Post by Zodiac69 » 17 Jul 2021, 20:35

Hi TD-er

Uncheck the extended credentials did not make any change.

ThomasB

If i change Controller Subscribe: homeassistant/sensor/%sysname%#
Then the HA Mosquitto does not accept the connection and the mqtt connection fail.

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#9 Post by ThomasB » 17 Jul 2021, 20:37

If i change Controller Subscribe: homeassistant/sensor/%sysname%#
Then the HA Mosquitto does not accept the connection and the mqtt connection fail.
Change it to:

Code: Select all

Controller Subscribe: homeassistant/sensor/%sysname%/#
- Thomas

Zodiac69
Normal user
Posts: 85
Joined: 13 Jun 2016, 17:20

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#10 Post by Zodiac69 » 17 Jul 2021, 21:39

Hi ThomasB

The ESP subscribe to both - homeassistant/sensor/%sysname% or homeassistant/sensor/%sysname%/#
So the "Subscribe" is working.
The issue is that i am not seeing any info in the HA mqtt.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#11 Post by TD-er » 17 Jul 2021, 21:52

How do you publish to the MQTT broker?
I assume you have some task, which is configured to send to your MQTT controller.

Zodiac69
Normal user
Posts: 85
Joined: 13 Jun 2016, 17:20

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#12 Post by Zodiac69 » 17 Jul 2021, 22:16

Hi TD-er

I have "two" ways:
1. Rule - publish IP address on mqtt connect and then every 30 seconds
On MQTT#Connected Do
Publish,homeassistant/sensor/%sysname%/IP,%ip%
timerSet,1,30 //Resets the Timer 1 for another 30 seconds
EndOn

On Rules#Timer=1 Do
Publish,homeassistant/sensor/%sysname%/IP,%ip%
timerSet,1,30 //Resets the Timer 1 for another 30 seconds
EndOn

2. Device - input switch - "Send to Controller"

As indicated before, both of these work when i use Mosquitto on a 2nd RPI that does not have HA.
192.168.2.220
$SYS
homeassistant
sensor
Garage_Door
Door1
State = 1
Door2
State = 1
IP = 192.168.2.197
status
LWT = Connected

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#13 Post by TD-er » 17 Jul 2021, 22:57

Is it possible your MQTT broker does require TLS ?

Zodiac69
Normal user
Posts: 85
Joined: 13 Jun 2016, 17:20

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#14 Post by Zodiac69 » 17 Jul 2021, 23:19

Hi TD-er

No, TLS is not required.

On the RPI running Node-RED, the TLS option is not selected
I also run another ESP8266 that send my electricity meter readings to HA using this in micro python - https://github.com/dalehumby/powermeter

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#15 Post by ThomasB » 18 Jul 2021, 02:47

I suggest using an MQTT tool to confirm that ESPeasy can communicate with the broker. This will help isolate where the problem is occurring.

I use the MQTTLens app that is available in the Chrome browser. But pick your favorite to do the test.

- Thomas

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#16 Post by Ath » 18 Jul 2021, 09:42

Have you activated 2 MQTT controllers on 1 ESPEasy unit? That's not a supported setup, only the first enabled MQTT controller will be correctly handled, any second/third MQTT controller is unsupported. Different types of controllers can be combined, f.e. you could use the HA MQTT and Domoticz HTTP controllers simultaneously, and they will both send out the values provided.
/Ton (PayPal.me)

Zodiac69
Normal user
Posts: 85
Joined: 13 Jun 2016, 17:20

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#17 Post by Zodiac69 » 18 Jul 2021, 10:06

Hi ThomasB

In my 1st post i indicated that i use MQTT Exporer to connect to the Mosquitto broker in HA.
There i can see my Electricity meter - esp8266 running Micropython - https://github.com/dalehumby/powermeter and my RPI Zero W running Node-RED sending serial data from my 16x current sensors.
I do not see the ESPEasy data.

Hi Ath

I only have one controller activated on the ESPEasy - HA mqtt.
I only change the IP address of the broker to my RPI with stand alone Mosquitto and then i can see the data, so the ESPEasy is sending the correct data.

When i connect to HA, HA Mosquitto log show i am connected - New client connected from 192.168.2.197 as homeassistant/sensor/Garage_Door (p2, c1, k10, u'mqtt').
But i do not see any data from ESPEasy in HA Mosquitto when i use MQTT Explorer.

ESPEasy is connected to HA broker, but for some reason i don't see the data getting into the broker.
I have looked at HA log files and i don't see any errors or notifications regarding the broker.

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#18 Post by Ath » 18 Jul 2021, 10:45

Zodiac69 wrote: 18 Jul 2021, 10:06 I only have one controller activated on the ESPEasy - HA mqtt.
I only change the IP address of the broker to my RPI with stand alone Mosquitto and then i can see the data, so the ESPEasy is sending the correct data.

When i connect to HA, HA Mosquitto log show i am connected - New client connected from 192.168.2.197 as homeassistant/sensor/Garage_Door (p2, c1, k10, u'mqtt').
But i do not see any data from ESPEasy in HA Mosquitto when i use MQTT Explorer.

ESPEasy is connected to HA broker, but for some reason i don't see the data getting into the broker.
I have looked at HA log files and i don't see any errors or notifications regarding the broker.
So it is not an issue with ESPEasy, but with your HA/mosquitto setup. Can't help with that, no HA here, sorry.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#19 Post by TD-er » 18 Jul 2021, 12:01

If you keep watching the broker via MQTT explorer (great Windows application by the way, use it all the time) you can see the history of everything sent to it.
When ESPEasy connects to it, it will send the LWT (Last Will and Testament) message if configured, which will be published by the broker as soon as the client is no longer connected.
For example a message like "disconnected", but can be anything.

Do you see this LWT message appear if you disconnect the ESP after a while?

Can you provide some logs from ESPEasy indicating a successful connection to the broker?

Zodiac69
Normal user
Posts: 85
Joined: 13 Jun 2016, 17:20

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#20 Post by Zodiac69 » 18 Jul 2021, 13:38

Hi TD-er

As i indicated before, i did not see any history from the ESPEasy device when using MQTT Explorer and connected to HA Mosquitto broker.

BUT i have had some success, not sure why, i need to do some RTFM to understand why...
I removed - homeassistant/sensor/ from my settings and now i can see the ESPEasy data in MQTT Explorer.
I 1st remove "sensor/", then i removed "homeassistant/" as well - desperation and trying anything...
It seems that when i include homeassistant, the mqtt broker accepts the connection, but the data does not get into the broker and i don't know why at the moment.

This work: - but HA "auto discover" does not see the entries
Controller Client ID: %sysname%
Controller Subscribe: %sysname%/#
Controller Publish: %sysname%/%tskname%/%valname%

This does NOT work:
Controller Client ID: homeassistant/%sysname%
Controller Subscribe: homeassistant/%sysname%/#
Controller Publish: homeassistant/%sysname%/%tskname%/%valname%

This work: HA auto discover detect the "Main unit" - GarageDoor
Controller Client ID: %sysname%
Controller Subscribe: /homeassistant/%sysname%/#
Controller Publish: /homeassistant/%sysname%/%tskname%/%valname%

Need to figure out how to detect the ESP Devices

Zodiac69
Normal user
Posts: 85
Joined: 13 Jun 2016, 17:20

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong?

#21 Post by Zodiac69 » 18 Jul 2021, 14:25

Hi TD-er / Ath

Is there a way to get JSON format on HA mqtt?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESPEasy - Home Assistant mqtt not working - What am i doing wrong? - Resolved

#22 Post by TD-er » 18 Jul 2021, 14:58

You can always create JSON format from the rules.
As far as I know, the HA MQTT controller does not send messages in JSON format.

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests