KlausMu / esp32-fan-controller

ESP32 fan controller with temperature sensor and MQTT
300 stars 56 forks source link

Add homeassistent mqtt discovery #16

Closed s4saken closed 1 year ago

s4saken commented 1 year ago

Hi KlausMu,

I managed to take the changes from #15 and modify the home assistent discovery payloads. I am getting the hang of stuff, but i am not a programmer. I managed to succeed in subscribing to topic [homeassistent/status] and act accordingly when receiving a online message, to facilitate for HA restarts. The fan state also has to be in a topic, this is also created.

For testing, you can use mqtt explorer to send online message to topic [homeassistent/status].

At this points mqtt discovery of the fan and sensors is only fully done on HA restart/online message. This needs a good look by some1 who has programming knowledge in c.

The newly created discovery payloads need to be done at the start of the device, but i could not wrap my head around this, with my knowledge :).

For now there is just a few things left to do, to make this great. Since the groundwork has been done. I assume this could be easy for you to do.

  1. All discovery payloads on esp32 start.
  2. Make pubsubclient set a retained last will message on connect to topic [homeassistant/climate/esp32_fan_controller/status] payload >>[offline] (seems to be quite easy to do, but my programming skills/time are insufficient).
  3. Enable retained messages. modify "mqtt.cpp" line nr. 97 to mqttClient.publish(topic, payload, true).

If these changes can be made, i can modify the discovery string of the fan to include availability on the last will topic. After this, the discovery on restart part can be removed and retained messages enabled. We make the fan unavailable when pulling the power and available when online. No ghost entities and proper handling of online/offline status of the device. mqttdiscoveryfan

s4saken commented 1 year ago

Could be done in 1 commit, sorry for this. Git for this usecase, is new to me.