MQTT question about automation

So, I followed this guide with a couple of ESPEasy flashed Wemos D1’s. Basically it runs an MQTT sniffer and looks for a command packet and responds with one of 3 things, IP addr, time or reboots. Seems to work well, so far.
https://www.letscontrolit.com/forum/viewtopic.php?f=6&t=4029

The response is coded as follows:
Publish %sysname%/IP,%ip%

Basically it is a broadcast on MQTT and the devices that are programmed to listen for it respond. The response is a perfectly formed ip address with the topic (right word) containing the name of the system that responded.

I would love to have an automation that would fire maybe once per hour and accept the response ip address and list the system as online. I would also love a switch to reboot they system. This part should be fairly easy as all that I would need to send would be to send a targeted 3 to the system with the sniffer set up to look for an MQTT command that contained the following NAME/cmdMQTT/3.

Can I have a sensor that will look for multiple responses and then sort them out and list them? This part sounds sketchy to me. I think I will have to know the system name ahead and build the sensor. Would be a nice way to find new ESPEasy boards as the came online.

The Ping Binary Sensor will let you know if your devices are online

A flaw in your system is that if your device is not responding, it probably won’t be listening for a signal to reboot.

Somewhat a flaw, I am more concerned with them acting badly and the main program stopping. I knew about the ping sensor, but there is no way to use it for any kind of discovery. With this, the units can and do report their boot IP addess when they come up. That is what I want to capture and use. I could do static DHCP for them, but really other than getting to the website the IP address is not needed with MQTT.

I thought it would be nice to build that MQTT name to IP address relationship when they boot on the frontend UI. It would make getting to the web interface easier.

You can use ping sensor to determine if that device is online or offline.
You can also have a sensor giving you the IP from a MQTT json payload.


If you read alittle bit the MQTT components documentation you’ll find most answers for your questions and examples to apply it.

I will re-read the section… I have spent far to much time reading this stuff! I have gone from zero HA experience to being able to write complex automatons in a month and a half. At 52 with 2 kids in school and a full time job, I can only uptake so much. I missed the way to make the second part happen and will review further.

For extracting the IP from a MQTT payload have a look here
https://home-assistant.io/components/sensor.mqtt/ at the end there are 2 examples of it they are taking other values but the method is the same.

I think the real flaw is that the sensor must be preconfigured and cannot be added on the fly. For example, if a new unit is brought up then it should be discovered, not brought up and manually found and added before use.

You mean auto-discovery? As home assistant will add it automatically without any yaml configuration?
If it is that, someone told me earlier it was possible in esp easy with a bunch of rules, if that’s the case I think adding everything in home assistant manually is the best option.

Set up an MQTT sensor with the state topic that ESPeasy will be sending the IP on.
The sensor will display the IP.
You can then set up a rule in ESPeasy and have it rebroadcast the IP every X minutes.

You will then be able to create an automation and have the trigger based on the .last_updated attribute of the sensor.

Thanks, will really start looking at the HA side of the equation from a config standpoint as soon as time allows. I have all the rules and responses defined in a couple of ESPEasy systems now and they work great manually with MQTTfx.

ESPurna is Autodiscover compatible with HA in its latest version (1.12.3) and it works ! I tested it and really easy to setup ! Just put a name in the device and tick “Auto Discover for HA” option and then your circuit appears immediately in HA interface :smiley:

I will look into ESPurna, ESPEasy is so easy to cookie cutter sensors and such with.

I agree too for ESPurna but it doesn’t handle automatic discovery in MQTT and doesn’t have any protection on web interface too !