Air Condition Controller (ESP32 based) MQTT auto-discovery integration

Hi all, I have developed a project based on the ESP32 (using VSCODE + PlatformIO). It includes an IR Receiver (for recognizing the type of AC to control), IR Transmitter to send commands to the AC, and a Temp/Humidity sensor. The control of the device is done via MQTT. I want to integrate it into HA using its MQTT automatic discovery mechanism. I found little info (https://www.home-assistant.io/docs/mqtt/discovery/) with very limited info about AC. Anybody did that and can share how? Any help in adding this into my project will be highly appreciated. Thanks a lot!

Hi @Motti_Bazar, youā€™re looking for a climate device discovery.
You may have a look at mine but it is a heating device.
The discovered modes should include cool I think.

Maybe share your repo.

Thanks Dominik!
I will check your code and report back.
I hope to find how to do that as it is the best way to integrate with HA.
I will highly appreciate additional help from you guys. Thanks a lot!

Dear Dominik, I reviewed your code and implemented mine in a similar way. But, HA sees the device (I see the device on the console screen using the round temp part circle + mode icons at the bottom + device name) but in the middle of the circle, I get a message of ā€œUnavailableā€. Do you have any clue why this happens? Can you point me in the direction to fix that? I will very highly appreciate your help! Thanks a lot, Motti

Please provide your discovery message and the state/command/availability topics you use.

Hi Dominik,

Thanks a lot for agreeing to help!

I am including below the MQTT information. If you would like, I can send you the source code. Please send me your email address and I will forward. Thanks a lot!!!

Device unique name: IOTTI30AEA4472C80

Topics:

  • homeassistant/climate/IOTTI30AEA4472C80/availability
  • homeassistant/climate/IOTTI30AEA4472C80/config
  • homeassistant/climate/IOTTI30AEA4472C80/state

I subscribe to all topics:

  • homeassistant/climate/IOTTI30AEA4472C80/#

Printed via Serial before sending:
Sending on topic ā€˜homeassistant/climate/IOTTI30AEA4472C80/configā€™: 437 bytes, ā€˜{"~":ā€œhomeassistant/climate/IOTTI30AEA4472C80ā€,ā€œnameā€:ā€œIotti AC Controlā€,ā€œmax_tempā€:ā€œ30ā€,ā€œmin_tempā€:ā€œ16ā€,ā€œinitialā€:ā€œ24ā€,ā€œtemp_stepā€:ā€œ1ā€,ā€œavty_tā€:"~/availability",ā€œmode_cmd_tā€:"~/mode",ā€œmode_stat_tā€:"~/state",ā€œtemp_cmd_tā€:"~/temp",ā€œtemp_stat_tā€:"~/state",ā€œcurr_temp_tā€:"~/state",ā€œcurr_temp_tplā€:"",ā€œmode_stat_tplā€:"",ā€œtemp_stat_tplā€:"",ā€œmodesā€:[ā€œoffā€,ā€œcoolā€,ā€œheatā€,ā€œfan_onlyā€],ā€œtemp_unitā€:ā€œCā€,ā€œpl_availā€:ā€œonlineā€,ā€œpl_not_availā€:ā€œofflineā€}ā€™

Sending ā€œonlineā€ on the availability topic

Sending on topic ā€˜homeassistant/climate/IOTTI30AEA4472C80/stateā€™: 53 bytes, ā€˜{ā€œmodeā€:ā€œoffā€,ā€œtarget_tempā€:ā€œ24ā€,ā€œcurrent_tempā€:ā€œ29ā€}ā€™

As I subscribed to all topics, I get the following messages from HAā€™s broker:
MQTT: Received msg - Len=7, Topic=ā€˜homeassistant/climate/IOTTI30AEA4472C80/availabilityā€™, Cmd=ā€˜offlineā€™
MQTT: Received msg - Len=255, Topic=ā€˜homeassistant/climate/IOTTI30AEA4472C80/configā€™, Cmd=ā€™{"~":ā€œhomeassistant/climate/IOTTI30AEA4472C80ā€,ā€œnameā€:ā€œIotti AC Controlā€,ā€œmax_tempā€:ā€œ30ā€,ā€œmin_tempā€:ā€œ16ā€,ā€œinitialā€:ā€œ24ā€,ā€œtemp_stepā€:ā€œ1ā€,ā€œavty_tā€:"~/availability",ā€œmode_cmd_tā€:"~/mode",ā€œmode_stat_tā€:"~/state",ā€œtemp_cmd_tā€:"~/temp",ā€œtemp_stat_tā€:"~/state","ā€™
MQTT: Received msg - Len=53, Topic=ā€˜homeassistant/climate/IOTTI30AEA4472C80/stateā€™, Cmd=ā€™{ā€œmodeā€:ā€œoffā€,ā€œtarget_tempā€:ā€œ24ā€,ā€œcurrent_tempā€:ā€œ29ā€}ā€™
MQTT: Received msg - Len=255, Topic=ā€˜homeassistant/climate/IOTTI30AEA4472C80/configā€™, Cmd=ā€™{"~":ā€œhomeassistant/climate/IOTTI30AEA4472C80ā€,ā€œnameā€:ā€œIotti AC Controlā€,ā€œmax_tempā€:ā€œ30ā€,ā€œmin_tempā€:ā€œ16ā€,ā€œinitialā€:ā€œ24ā€,ā€œtemp_stepā€:ā€œ1ā€,ā€œavty_tā€:"~/availability",ā€œmode_cmd_tā€:"~/mode",ā€œmode_stat_tā€:"~/state",ā€œtemp_cmd_tā€:"~/temp",ā€œtemp_stat_tā€:"~/state","ā€™
MQTT: Received msg - Len=7, Topic=ā€˜homeassistant/climate/IOTTI30AEA4472C80/availabilityā€™, Cmd=ā€˜onlineā€™
MQTT: Received msg - Len=53, Topic=ā€˜homeassistant/climate/IOTTI30AEA4472C80/stateā€™, Cmd=ā€™{ā€œmodeā€:ā€œoffā€,ā€œtarget_tempā€:ā€œ24ā€,ā€œcurrent_tempā€:ā€œ29ā€}ā€™

One thing that I see is that the received message from the config topic is cut to 255 bytes even though I defined on my side a buffer size of 700. I am using the PubSub MQTT library.

Best regards,
Motti

Doesnā€™t look too bad but you need to provide the value templates for extracting the particular payload from the ~/state topic.

Iā€™m not using PubSubclient since I feel more comfortable with the MQTT library but defined a 2048 byte buffer for it.

Do you have a 3rd party tool to monitor MQTT? I really like the MQTT Explorer.
With that you can doublecheck if the 255 byte problem is on sender or receiver side.

Are there any other realted log entries in HA itself?

This is your ~/config topic, pretty formatted and added the value templates.

{
  "~": "homeassistant/climate/IOTTI30AEA4472C80",
  "name": "Iotti AC Control",
  "max_temp": "30",
  "min_temp": "16",
  "initial": "24",
  "temp_step": "1",
  "avty_t": "~/availability",
  "mode_cmd_t": "~/mode",
  "mode_stat_t": "~/state",
  "temp_cmd_t": "~/temp",
  "temp_stat_t": "~/state",
  "curr_temp_t": "~/state",
  "curr_temp_tpl": "{{value_json.current_temp}}",
  "mode_stat_tpl": "{{value_json.mode}}",
  "temp_stat_tpl": "{{value_json.target_temp}}",
  "modes": [
    "off",
    "cool",
    "heat",
    "fan_only"
  ],
  "temp_unit": "C",
  "pl_avail": "online",
  "pl_not_avail": "offline"
}

Hi Dominik,

I finally got it to work. HA sees my AC controller as an AC unit and I can control items such as mode, target temp, fan, and swing. But, I am still facing some issues:

  1. When I click the 3 dots on the upper-right corner of the AC component in the HA UI, I get a window with a graph and options to set some of the parameters. When I click the upper right setup icon, I get another window with two tabs: SETTINGS and RELATED. The issue is that under SETTINGS, I get the message ā€œThis entity does not have a unique ID, therefore its settings cannot be managed from the UIā€. Any clue why I am getting this strange error message? As I want to add some unique settings that are not part of the standard UI, I need a way to add them here. Any idea what I should do in order to fix that and add my own settings parameters here?

  2. My controller also provide humidity reading but I do not see any way to announce it on the MQTT auto discovery config message (I did not see an option for that on the list of the MQTT Discovery configuration items). On the other side, it looks like it should be supported. Any clue what I should do?

Thanks a lot for your help!

Best regards, Motti

Regarding 1:
I donā€™t know, for me this is available.
Can you change the desired settings via customize?

Regarding 2:
I managed humidity in 2 ways.

  1. I just discover a seperate humidity sensor only grabbing the humidity from the state topic. I also did this for the temperature btw.
  2. I also use my state topic as attributes topic and use the simple-thermostat card to parse it

You can also use just another sensor in that card:

Hi Dominik,

Thanks for getting back to me.

Regarding 1, I removed the AC from HA and following a new auto discovery, the issue disappeared.

Regarding 2, I was able to add temp and humidity sensors (all automatically via MQTT discovery, without modifying config files on HA) but I get two red circles on the top (with many more such circles that HA decided on its own to put there) with the two sensors, not something nice at allā€¦ Looks like I am missing some key info on the HA UI configuration. Can you please point me in the direction to learn how to modify the UI so that it looks nice like yours? Thanks a lot!

Best regards,
Motti