osresearch / hcpy

Python tool to talk to Home Connect appliances over the local network (no cloud required)
276 stars 32 forks source link

Allow for posting to appliance #26

Open Skons opened 1 year ago

Skons commented 1 year ago

This update allows to change settings at the appliance. My main goal was to set the time, and that seems to be working. I have seen mixed results on switching the appliance on or off, sometimes error 516 will show up. I haven't figured out what that error is yet. For now it has a basic implementation of being able to send information to the appliance.

See the README for information how to send messages to an appliance.

I also updated the logging to see which message belongs to which appliance.

This PR integrates #25 and #19. It solves issue #17 and #3

JW5PX commented 1 year ago

Very nice!! Thank you for this

nebkrid commented 1 year ago

Did you figured out how to actually start a program? (e.g. dishwasher, but I guess it will be similar to other) I can turn it on and successfully tried some other features, which have explicit write access according to the config.json. But I have no idea where to get the structure of the json data for even only starting the pre-set program. Already tried to post to '/ro/activeProgram' but always getting a "400 Bad Request response", no matter which combination even with options I tried.

PS: I already have done some work using your PR as base branch to implement the Homie-MQTT protocoll for auto-detection in e.g. smart-home environments. Is it better to make a PR to your branch or directly into the main of this repository?

Skons commented 1 year ago

No i did not, but as said it is very alpha. i could look into that, but i need to bring my android phone back to live to see how the home connect app does that stuff.

You could best bring a PR to my branch. I doubt if @osresearch is looking into these PR's... The development is not very active.

chris-mc1 commented 1 year ago

The json data for /ro/activeProgram should looks like this: [{"program":8196, "options":[{"uid":558,"value":0},{"uid":5123,"value":false},{"uid":5126,"value":false},{"uid":5127,"value":false}]}] Don’t know if the options need to be set beforehand.

nebkrid commented 1 year ago

Thank you both! "program" was the missing keyword! I created the PR to @Skons branch

DimiPaparas commented 1 year ago

Is there any documentation regarding what resource values exist when making requests and general information regarding the structure of the data variable?

I assume that there isn't any... If that's the case, what would be a good way to intercept and decode the packets without needing to root an android phone?

As a side note, I'd be interested in hidden features. I have a fridge/freezer and I would like to monitor the temperature inside. However, that doesn't seem to be part of ro/allMandatoryValues. It is a pity that they didn't include it. I'm wondering if some debug style output would include it. Alas...

Skons commented 1 year ago

First. There is documentation on how to use the cloud api, which seems to be very similar to the api exposed by the devices: https://api-docs.home-connect.com/settings/#temperature-unit I think it can be used as some sort of reference, but not as a guidance.

Second. If your device has got key and iv in the config.json, the traffic is encrypted by the client. If this is case, you can capture the traffic with a router that can have wireshark, tcpdump or whatever tool that can create a pcap from the traffic. I once had a script that could decrypt the a pcap based on the config.json, but i have lost that. I am planning on recreating that script. If capturing the traffic is not possible, or you've only have got the value key in your config.json, then your best bet is an android emulator. But, to do that, you will need a device with an arm processor. Home connect does not have, the last time i checked at least, an x86 compiled app. It is not possible to emulate arm software on a x86 processor.

Skons commented 1 year ago

It seems to be that i am wrong about the x86 version of the app: https://www.apkmirror.com/apk/bsh-home-appliances-corporation/home-connect-america/home-connect-america-9-5-0-release/home-connect-america-9-5-0-4-android-apk-download/download/?key=a6439dafbcfb8528316590bbeb41da2e28f54690

and it seems that i am wrong about the emulation: https://android.stackexchange.com/questions/194629/is-it-possible-to-install-an-app-compiled-for-arm-on-an-x86-emulator-image

DimiPaparas commented 1 year ago

@Skons thanks a lot for the advice. I'll try to use wireshark to get an insight into what's going on.

I was considering contacting the BSH Group, but I don't think they would disclose that information. Even their API is free but not open source.

I tried reverse engineering the local network HTTP communication using their cloud API as a blueprint but it's not one to one. The mismatch between the two is very significant.

chris-mc1 commented 1 year ago

A list of possible resource values is here: https://github.com/osresearch/hcpy/blob/main/HCDevice.py. Don’t know if it is complete or what most of them do.

For /ro/values the data variable is something like [{"uid":558,"value":0},{"uid":5123,"value":false}] For the datatype of the "value" field, lookup the "refCID" values from the config.json in the CID list here: https://www.home-connect.com/schemas/DeviceDescription/20140417/HC_INT_BSH_CTD.xml

ericblade commented 12 months ago

re: emulators and all that

of course, Windows 11 can just run Android apps (through the magic of emulators and all that, but it's all concealed from the user), so that's an interesting tool.

Just got a Home Connect Dishwasher, and discovered that IFTTT has been completely neutered, so I'm going to have to build something myself. I guess this means I become active on this project :-) Either that or I setup a proper HomeAssistant and/or Node-RED .. but this seems like the best option. I intend to write an app that will keep track of the state of the dishwasher, and notify people that it's done with what it's doing. And have it get progressively more annoying the longer it goes without someone unloading it. :-)

but I'd also like to implement control capability as well, because why not?

so.. here I am :-)

If there's anything I can do to help reverse the protocol, I'd be happy to load it up on one of my win11 machines and mess with it. Just let me know what needs to happen