Eikkargh / Candy-API-to-JSON

Communicates with Candy/Hoover washer dryers to produce a JSON readable by Home Assistant
6 stars 2 forks source link

Add commands #8

Open Eikkargh opened 1 week ago

Eikkargh commented 1 week ago

Add commands?

Originally posted by @BenGlossop09 in https://github.com/Eikkargh/Candy-API-to-JSON/issues/5#issuecomment-2352374357

BenGlossop09 commented 18 hours ago

Hi Eikkargh how are you?

I've made some progress with the commands side of things. I used an android app "PCAPdroid" to sniff packets sent from my phone to the Hoover servers. Happy to say I have got commands 'run a 15min wash', 'pause', and 'stop' to work. The best thing is the command executes immediately once sent, that is compared to the app commands which can take a few seconds to travel through the Hoover servers and back to the machine.

Methodology

  1. Download PCAPdroid app, select 'create a PCAP file' and target the 'Wizard' app (or whichever app you are using to send commands to the washer.
  2. Open the Wizard app and turn the washer (physically) to remote control mode (if you have that mode) - ensure a connection is established.
  3. Click run on PCAPdroid to begin sniffing.
  4. Go back to the Wizard app and begin a wash/dry/drain/whatever you want. Run any commands you are looking to replicate via Home Assistant or a browser.
  5. End the session on PCAPdroid, save the PCAP file and open it within the app.
  6. Find a connection that has your machines local IP as the destination (192.168.4.38 in my case) and look at the payload. You are looking for a sent payload [TX] that starts with "GET /http-write.json?encrypted=1&data=ENCRYPTED_COMMAND_HERE".
  7. Decrypt the hex using Xor - hex to text, and make sure to enter your decryption key (select hex).
  8. Profit - you now have the decrypted message sent from the Wizard app to the machine.

Commands I have decrypted so far: 14' Wash "Write=1&StSt=1&DelVl=0&PrNm=10&PrCode=39&PrStr=Rapid Care 14'&TmpTgt=30&SLevTgt=1&SpdTgt=8&OptMsk1=0&OptMsk2=0&Lang=1&Stm=0&Dry=0&ED=0&RecipeId=0&StartCheckUp=0&DispTestOn=1" Pause "encrypted=0&Pa=1" Stop "Write=1&StSt=0&PrNm=10" Resume "encrypted=0&Pa=0" You could use the format of the above commands and insert known values to set (custom?) programmes without having to sniff them first. For example, replace "TmpTgt=30" with "TmpTgt=40" to change from 30 to 40 degC wash temperature.

Successful execution "{"response":"SUCCESS"}" Failed execution due to not in remote control mode "{"response":"READ ONLY"}"

To send a command to your machine use the following format "http://192.168.X.XX/http-write.json?encrypted=1&data=ENCRYPTED_COMMAND_GOES_HERE"

The next step should be to check the above can be reliably replicated on your model and then figure out how to combine this process into something Home Assistant can execute from a user input within the Home Assistant UI.

Eikkargh commented 14 hours ago

Excellent. Sounds doable. Ill give it a go over the next few days. Best route seems to be to compile the command as a string in Home Assistant. A few helper input_select , input_button and a shell_command would do this. Ill need to adjust the python script to accept the command a string as an argument, encrypt it, send it and return the response. Pretty sure I can come up with something.

BenGlossop09 commented 14 hours ago

For each command I've used an input button and a rest command as a temporary implementation. Using Mushroom Chips, it looks quite clean. I'd recommend using a confirmation dialog to prevent accidents.

Feels like big progress being able to both view data and control the machine from within HA!

Eikkargh commented 12 hours ago

That is plenty for the way I use my machine. Would be fun to be able to do everything the app can do just for completeness. Ill have to see if my machine has the same command format.