MQTT Discovery with ESPEasy firmware?

Hi

As I played too much with my existing HA system (tweaking things, trying lot of stuffs), I’m going to reinstall it soon clean on a new system. I’d like to take that opportunity to implement the autodiscovery for MQTT. I used in past the Mosquitto MQTT and plan to reinstall same broker (excepted if there is an other one really better and working on Raspberry PI).
I use for my ESP modules mainly the ESPEasy firmware and Espurna one for all Sonoff devices I have !
Did someone succeeded to implement the autodiscovery with these two ESP firmwares and if so would you mind to share your MQTT setup in these firmwares to get it working with HA autodiscover feature ?

Thanks in advance for help

Vincèn

No one on this ? :frowning:

You added this to your configuration.yaml?

mqtt:
  broker: !secret mqtt_broker_ip
    port: !secret mqtt_broker_port
    client_id: home-assistant
    username: !secret mqtt_user
    password: !secret mqtt_password
    discovery: true
    discovery_prefix: homeassistant

Last two lines are important :slight_smile:

Did you manage to get ESP Easy or Espurna auto discovering in Home Assistant?

[quote=“c0mm4nd3r, post:3, topic:39312”]You added this to your configuration.yaml?
Last two lines are important :slight_smile:
[/quote]
Yep my main concern now is how to setup ESP firmware to get it compatible with it :confused:

Nope and at least for ESPEasy it looks like only solution is to make cumbersome rules for that so definitively not an easy way (ESPEasy with Autodiscover MQTT feature in Home Assistant ? - Let's Control It) :frowning:
ESPurna might be the solution as it lists support of auto discover feature of HA but it doesn’t give any explanations somewhere or was not able to find it :frowning: I posted a question on repository of ESPurna and let see how it goes :wink:
Will update thread here about my progress !

Great, let us know if you make any findings!

I never used ESPurna, usually I flash Tasmota into sonoff’s and esp easy in nodemcu’s for my diy projects.
Besides the support for auto discovery in Hass what are the major differences from Espurna and ESPEasy?
Is even Espurna really something like ESPEasy where I choose what module is connected and where is connected and pretty much works?

Just saw in another threat the new release notes from Tasmota and it is also supporting auto-discovery in Hass.

* Add option define HOME_ASSISTANT_DISCOVERY_ENABLE in user_config.h (#1685)

https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino

For ESPurna, here are explanations of guy on how to implement it:

The MQTT auto discover feature works for switches and lights. You have to have Home Assistant connected to the same MQTT broker as the ESP and then just enable the Home Assistant option in the General tab of the web UI. If you have not configured otherwise the default prefix "homeassistant" should work.

Once you enable it (and click on the "Save" button) it will send an MQTT message to a topic like "homeassistant/switch/ESPURNA_XXXXXX/config" with the required information so HA can configure the switch. Same for lights.

Thanks @Sthope I’m going to test too the Tasmota one to check how it goes too with the automatic discovery feature :wink:

First results with ESPurna:
-> configured the MQTT autodiscovery feature in HA (basically add these two lines in your MQTT declaration in configuration.yaml:

discovery: true
discovery_prefix: homeassistant

-> flash your ESP device (Sonoff mainly) with ESPurna firmware (done here with current version 1.12.1 as of January 26th 2018 :wink:
-> configure network and wifi in your ESPurna flashed device.
-> General tab in ESPurna webpages: hostname will be name of device as it’ll appear in HA, you activate HA option and check it’s well “homeassistant” indicated as prefix or same as one you declared in HA :wink: You’ll need also to activate the Retain feature on MQTT setup page !
-> You are done ! Reboot your ESP (electrically or by reboot button in web interface) and it should show up automatically in HA :slight_smile: If you control the device from HA it should immediately react and same if you change device status through web pages of ESPurna, it’ll reflect back in HA !! If the device goes offline it’ll show up as “Unavalaible” in HA !

General tab in ESPurna


MQTT tab in ESPurna

Result in HA (no edition of any config file in HA, it showed up automatically :wink:
Capture%20d'%C3%A9cran%20de%202018-01-26%2009-47-49

Will check how it goes now with Tasmota firmware for non Sonoff ESP based devices :wink: Unable to get it working on my W1 mini boards so will check other alternative firmwares for ESP supporting autodiscover in MQTT and sensors !

Hope it might help and feel free to ask for questions :wink:

So far it looks like ESPurna is only ESP firmware that supports the autodiscovery feature in MQTT :frowning: which is boring as It can’t be used on regular ESP boards (non Sonoff ones !) and I need it for sensors ESP boards i have !

This is supported for example in ESPurna; “NodeMCU Lolin”

Not only ESPurna :slight_smile: Also my AiLight firmware uses the MQTT auto discovery feature.

I’m fairly new to HA, used the forums a lot to get going, so I thought to try to contribute also :slight_smile:

I’ve flashed my Sonoff modules with Tamota, and was also having a bit trouble to understand the correct syntax for the MQTT settings. Ultimately, I’ve got the setting correct almost the same time I got my autodiscover working.
(If there are more experienced users that notice there’s a better way, I still want to learn :wink:

First your MQTT settings need to be correct. I put them this way:
image
As far as I learnt it’s always best to get some descent structure in there, hence my full path myhome/room/%topic%/%prefix%/

In the “configure other” tab, put a Friendly name (This is the name that will be displayed in the dashboard)

Finally, you need to go into the Console of the Sonoff (main webpage => Console) and put in the command: “SetOption19 1”. The module will reboot, and announce himself to the MQTT broker.

Important! in your configuration.yaml, you need the discovery lines:
mqtt:
discovery: true
discovery_prefix: homeassistant

Here I did the mistake to choose the prefix myself (I thought it would be “myhome” as that was the start of my full topic) But the “homeassistant” prefix is hard coded, so just use that one…
It sends a message like this:
homeassistant/switch/SO_POW_Test/config = {"name":"Sonoff XXX","command_topic":"myhome/room/SO_POW_Test/cmnd/POWER","state_topic":.....

1 Like

Just to be complete…
(I’m a bit confused and not sure about the capitalization in the end Power/POWER… So open for advice :-))

The manual settings would be:
- platform: mqtt
name: “Sonoff Test MANUAL”
command_topic: “myhome/room/SO_POW_Test/cmnd/Power”
state_topic: “myhome/room/SO_POW_Test/stat/POWER”
payload_on: “ON”
payload_off: “OFF”
value_template: ‘{{ value_json.POWER }}’

Thanks for the tips - I was close, but didn’t catch the SetOption19 1 part!

Hi everyone!
Let me begin by saying that this is one of the best open source project and community out there and I want to thank all the contributors for their time and effort.
I am a long time lurker here and posting for the first time.

I just did a blog post about MQTT discovery with ESPEasy. Hope this helps someone.

cheers!

1 Like

Do you know if this requires a specific version of espeasy?
I used your examples from the blog (thanks) but the espeasy is not sending the config on start.
Other mqtt is being sent ok (sensors and device stats)
Thanks for any info

Switch to ESPhome firmware, it has a native API with HA, no more need of MQTT :slight_smile:

Ive seen esphome/esphomeyaml and would love to try it, but right now the device in question is installed and not easily accessible and has espeasy deployed. Also due to the esp being a sonoff there is only 1mb memory, so OTA is not possible.

I am using my own build of ESPEasy, purely because I wanted to try building it and also didn’t want to go through the Wifi setup for each device. So I embedded the Wifi creds in the firmware.
As long as the MQTT#Connected trigger is supported in the rules engine, it should work IMHO. This is my version:

Build: 20103 - Mega
Libraries: ESP82xx Core 2_4_2, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3
GIT version: MyBuildNum
Plugins: 4 [Normal] [Minimal 1M OTA - Sandman]
Build time: Dec 29 2018 17:17:37
Binary filename: Self built!

Which version are you using? Did you look at the log? What does it say?
ESPHome would be one option, but without the possibility of OTA, it is a pain to get a new firmware on the 1M flash boards. I went with ESPEasy as I was playing with it for a while already. I will try ESPHome with some of my other projects soon.