MQTT Discovery with ESPEasy firmware?

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.

Im on ESPEasy v2.0.0-dev12 from ~1.5 years back.
Im upgrading my project from that period:

I was inspired by some tasmota devices and by zigbee2mqtt that both support autodiscovery… then I found your blog post (via google rather than this topic ;))

That looks like a cool project. That is one of the reasons I also started with ESPEasy - the sheer number of plugins/integrations it supported (and still does), though others are catching up now.

I think the rules worked the same in v2.0.0, but I may be wrong. If you have a spare ESP lying around, I’d suggest you try the same firmware on it and see if the auto discovery works and keep an eye on the log. I used a Wemos D1 mini as my development and test environment :slight_smile:

I also wanted the auto-discover feature for espeasy and keep it simple for the device so i have created a Node-Red flow to do the work at creating devices according to the name of the variable
Current support of

  • Sensors
  • Switches
  • Dimmer
  • RGB Dimmer

Working on Termostat to get it to output set temperature

note that because there is not /Set to set a variable i do need to have rules on each device but i dont need to do anything inside configuration.yaml
and each device is under Devices and has all values there.

1 Like

And now i have added support for Termostat with version 2.1.0 :slight_smile: do tell if you miss anything

V 2.2.0 released that add error message handling to show if any unsupported character is used in topic.

I have created this in the system boot proces rule:

// START Boot
On System#Boot do
  TaskValueSet 11,1,0
  TaskValueSet 11,2,0
  TaskValueSet 11,4,0
  GPIO,16,0
  NeopixelAll,0,255,0
  TimerSet,8,5
Endon

On Rules#Timer=8 do
  GPIO,16,1
  NeopixelAll,0,255,255
  Publish homeassistant/switch/meek_switches/balcony/config,'{"name": "balcony","state_topic": "homeassistant/ha_switches/balcony","command_topic": "homeassistant/ha_switches/balcony","unique_id": "14685093-ad68-4e03-a978-6fb858e34390","device": {"identifiers": "meek_switches","name": "Meek switches","manufacturer": "Peter Oudenes"},"optimistic": "false","qos": "1","retain": "false","payload_on": "1","payload_off": "0","state_on": "1","state_off": "0","icon": "mdi:nintendo-switch"}'
  Publish homeassistant/switch/meek_switches/dressoir/config,'{"name": "dressoir","state_topic": "homeassistant/ha_switches/dressoir","command_topic": "homeassistant/ha_switches/dressoir","unique_id": "14685093-ad68-4e03-a978-6fb858e34391","device": {"identifiers": "meek_switches","name": "Meek switches","manufacturer": "Peter Oudenes"},"optimistic": "false","qos": "1","retain": "false","payload_on": "1","payload_off": "0","state_on": "1","state_off": "0","icon": "mdi:nintendo-switch"}'
Endon
// END

Evertime my ESP needs to restart it will send this 2 Publish actions and the switches will be created.
Those topics are used inside the “Devices” the control switches based on MQTT topic input.

Work great for me. And never needed to create MQTT switches in Home Assistant again.