anszom / rethink

reverse engineering the network protocols for LG ThinQ devices
GNU General Public License v2.0
4 stars 0 forks source link

Homeassistant MQTT discovery shows climate is unavailable #1

Open Pr0mises opened 2 weeks ago

Pr0mises commented 2 weeks ago

Hey @anszom firstly thank you for your amazing work in this. I wanted to reverse it myself but somehow stumbled across your repo today, and It works!!

As I'm no node expert and didn't want to cluster my server up I wrote two dockerfiles, one for the client and one for the server, need to do some proper checks if it works out of the box. If you're interested, I can create a PR for that.

Now to my problem, everything works fine, the LG wall mounted AC connects to the server and publishes its topics towards it and I receive payloads inside HASS:

<ServerIP> LG Air Conditioner (climate.<redactedID>)
MQTT discovery data:

    Topic: homeassistant/climate/rethink/<redactedID>/config 

Payload:
availability:
  - topic: rethink/<redactedID>/availability
  - topic: rethink/availability
optimistic: false
object_id: <redactedID>
unique_id: <redactedID>
device:
  identifiers: <redactedID>
  manufacturer: LG
  model: RAC_056905_WW
  sw_version: '690409'
current_temperature_topic: rethink/<redactedID>/current_temperature
power_command_topic: rethink/<redactedID>/power/set
mode_state_topic: rethink/<redactedID>/mode
mode_command_topic: rethink/<redactedID>/mode/set
fan_mode_state_topic: rethink/<redactedID>/fan_mode
fan_mode_command_topic: rethink/<redactedID>/fan_mode/set
temperature_state_topic: rethink/<redactedID>/temperature
temperature_command_topic: rethink/<redactedID>/temperature/set
swing_mode_state_topic: rethink/<redactedID>/swing_mode
swing_mode_command_topic: rethink/<redactedID>/swing_mode/set
temperature_unit: C
temp_step: 0.5
precision: 0.5
fan_modes:
  - auto
  - very low
  - low
  - medium
  - high
  - very high
swing_modes:
  - '1'
  - '2'
  - '3'
  - '4'
  - '5'
  - 1-3
  - 3-5
  - 'on'
  - 'off'
vertical_swing_modes:
  - '1'
  - '2'
  - '3'
  - '4'
  - '5'
  - '6'
  - 'on'
  - 'off'
name: LG Air Conditioner
platform: mqtt

The subscribed topics are:

rethink/<redactedID>/availability
rethink/availability
rethink/<redactedID>/mode
rethink/<redactedID>/fan_mode
rethink/<redactedID>/swing_mode
rethink/<redactedID>/current_temperature
rethink/<redactedID>/temperature

So that's working as expected, but somehow the "LG Air Conditioner" climate entity shows "Unavailable".

I'm not sure if I missed something in the docs, debugging the MQTT component didn't help either, do you perhaps have a clue what could be wrong here?

Thank you in advance

Pr0mises commented 2 weeks ago

Off-topic: My AC had also this Wi-Fi open all the time [LG_Wall-Mounted A/C]yyyy, password did work as described. Doing the setup you shouldn't use it tho as this SSID never closes after that. It only closes itself after using the proper SSID (LGE_XXX_yyyy) using the wifi setup with the remote

anszom commented 2 weeks ago

First of all, thank you for checking out the project, you are the first person to provide any feedback :)

The MQTT data looks ok. I suspect that this is an issue with HA<->MQTT integration, but I'm not sure what could be the cause. My understanding of HA is very limited.

I'm not sure how you obtained this dump, but for comparison here is a list of topics published by my copy of rethink, as shown by mosquitto_sub:

homeassistant/climate/rethink/<redactedID>/config {"availability":[{"topic":"rethink/<redactedID>/availability"},{"topic":"rethink/availability"}],"optimistic":false,"object_id":"<redactedID>","unique_id":"<redactedID>","device":{"identifiers":"<redactedID>","manufacturer":"LG","model":"RAC_056905_WW","sw_version":"690409"},"current_temperature_topic":"rethink/<redactedID>/current_temperature","power_command_topic":"rethink/<redactedID>/power/set","mode_state_topic":"rethink/<redactedID>/mode","mode_command_topic":"rethink/<redactedID>/mode/set","fan_mode_state_topic":"rethink/<redactedID>/fan_mode","fan_mode_command_topic":"rethink/<redactedID>/fan_mode/set","temperature_state_topic":"rethink/<redactedID>/temperature","temperature_command_topic":"rethink/<redactedID>/temperature/set","swing_mode_state_topic":"rethink/<redactedID>/swing_mode","swing_mode_command_topic":"rethink/<redactedID>/swing_mode/set","name":"LG Air Conditioner","temperature_unit":"C","temp_step":0.5,"precision":0.5,"fan_modes":["auto","very low","low","medium","high","very high"],"swing_modes":["1","2","3","4","5","1-3","3-5","on","off"],"vertical_swing_modes":["1","2","3","4","5","6","on","off"]}
rethink/<redactedID>/availability online
rethink/<redactedID>/mode fan_only
rethink/<redactedID>/mode off
rethink/<redactedID>/fan_mode very low
rethink/<redactedID>/current_temperature 21
rethink/<redactedID>/temperature 21
rethink/<redactedID>/vertical_swing_mode off
rethink/<redactedID>/swing_mode off
rethink/<redactedID>/mode off
rethink/<redactedID>/mode off
rethink/<redactedID>/fan_mode very low
rethink/<redactedID>/current_temperature 21
rethink/<redactedID>/temperature 21
rethink/<redactedID>/vertical_swing_mode off
rethink/<redactedID>/swing_mode off

You may also want to compare the MQTT diagnostic output available here: obraz

Here is an anonymized copy from my setup: mqtt-diagnostics.txt

Pr0mises commented 2 weeks ago

Alright it looks like it's pretty unreliable after reloading the MQTT integration (and probably after restarting hass, the mqtt broker or rethink cloud?) It appeared after doing multiple restarts of everything. Maybe that's a problem on my side (every other mqtt device is working well tho)

Sometimes it appeared while being ON through the remote, sometimes it didn't. Sometimes it appeared while being off most of the time it didn't (yes there are always incoming packets towards the rethink cloud).

Also how did you obtain the IDs for your AC? It looks like everything is working as expected besides of the OFF function, I can cool, dry, fan, heat, auto etc but I can't turn it off.

After using the remote turning off the AC it sends this packet: clip/message/devices/<redactedID> {"mid":7023523,"did":"<redactedID>","kind":"RAC_056905_WW","cmd":"device_packet","rssi":-41,"fs":"idle","data":"0000040000008702047C0D7DC08C898CD026BF6004001B001EED","type":1}

Pr0mises commented 2 weeks ago

First of all, thank you for checking out the project, you are the first person to provide any feedback :)

Thanks for your fast answer. It was pretty hard to find this repo tbh xD

anszom commented 2 weeks ago

Also how did you obtain the IDs for your AC?

You mean the IDs of the commands? I've monitored the network & UART messages while using the official LG app to control the AC. The network part was a little bit tricky because of all the encryption, I've needed to essentially create a "simulated" AC which connected to the LG cloud and would then forward the incoming/outgoing messages to the real one (or not - I didn't want them to trigger a firmware update or something).

Pr0mises commented 2 weeks ago

Yea, the IDs of the command as Off isn't working somehow, which is weird as it shows Off after turning the AC off via the remote,... I might need to check if the AC sends the correct data for all functions while using the remote, maybe it's possible to reverse it that way...

I didn't deep dive into your code yet. Do you extract the model ID from the AC itself or from the device file? If you extract it from the AC itself, I was able to identify two things.

  1. We've the same model and sw_version
  2. My AC supports 425 features and your AC 41 (also do you extract this info from the AC as well?)
anszom commented 2 weeks ago

All the identifiers reported by rethink come from the device itself. Very little is hardcoded - mostly constants for mapping values such as fan levels and so on, see https://github.com/anszom/rethink/blob/master/rethink/cloud/devices/RAC_056905_WW.js

I'm not sure where the "supported_features" come from, rethink doesn't report anything like this.

Also I've re-checked now and the OFF command works correctly on my AC. On rethink's console output I see this message being produced:

lime/devices/... {"did":"...","mid":1718920916901,"cmd":"packet","type":1,"data":"01010400000065020101027dc00576"}

The payload decodes to type=0x1f7 value=0

$ node packet-parser.js  -message 01010400000065020101027dc00576
t= 1f7 v= 0
Pr0mises commented 2 weeks ago

That's helpful, so clip from ac to hass and lime hass to AC.

I'm not receiving anything in the rethinks console after switching the mode to Off, that might be the problem. Could you also share your message while doing Mode: Cool?

I'll try to debug it a bit more tomorrow, thanks for your help. I'll keep you updated

And again awesome project, you can be proud of yourself creating such a masterpiece.

Pr0mises commented 2 weeks ago

I did some more research and figured out how your packet-send.js works.

I'm able to turn my AC off with this command node packet-sender.js <redacted-ID> 0x1 0x1 0x2 0x1 0x1 0x1f7 0x0 therefore it should work.

My discovery is the following right now:

Modes: everything works besides of Off, no message towards the cloud at all (I don't rly understand this field, but it might be the problem)

Fan Mode: does not work out of the box for my AC

What I figured:

Swing mode: works

Turn off Light (from here) needs a group, didn't figure which one

Current temperature: works Set temperature: works

anszom commented 2 weeks ago

Regarding the power-off issue - can you check if HA publishes a message when you select "Off". I see the following MQTT messages:

rethink/<ID>/power/set OFF
rethink/<ID>/mode/set off

and shortly after, a response appears:

rethink/<ID>/mode off
anszom commented 2 weeks ago

write_attach: [0x1f9] has to be write_attach: [0x1f9, 0x1fe] this fixed the problem for me

You are right, I must have missed this because my AC also requires this change to accept a fan_mode command. I will push a fix.

Pr0mises commented 1 week ago

Regarding the power-off issue - can you check if HA publishes a message when you select "Off". I see the following MQTT messages:

rethink/<ID>/power/set OFF
rethink/<ID>/mode/set off

Interesting, I only transmitted rethink/<ID>/mode set off while using the default climate ui doing Mode: Off

Using service: climate.turnoff, rethink/<ID>/power/set OFF appears and actually powers off the AC.

Gonna investigate it a bit further.

Thanks for your help, I'll keep you updated