biemond / com.athom.philipsair

Philips AIR purifier app for Homey
GNU General Public License v3.0
4 stars 2 forks source link

AC3829/10 gives 'secretKey of null' in Homey app #4

Open iceburg1991 opened 4 years ago

iceburg1991 commented 4 years ago

Hi Edwin,

I recently, few days ago, bought a AC3829/10 and I can't connect the device in the Homey App. Initial i can add the device, but when I try to change something (like the Light level ring) it give me the error 'Cannot set property 'secretkey' of null' and all measurements are empty (see image). I read something from you that they changed firmware so maybe that's the case for me, but maybe we can work it out together.

I know the IP address i used is correct because i found a forum topic somewhere which named the same hostname MiCo and i have only 1 device in my network which is not identified yet.

I tried to use the airctrl debug you linked to in another issue, but I get an timeout on the 192.168.1.1 ip . So I'm stuck right now, maybe you can help me test/debug or something so we can work it out together so the app is 'compatible' with the latest firmware. I never really developed a Homey app so you need to help me with that if needed.

Kind regards, IJsbrand (dutch)

Screenshot_20200415-182638 Screenshot_20200415-182828

biemond commented 4 years ago

Hi,

sorry , can you try to remove the device and add it again. Also 192.168.1.1 did you assign this with dhcp because it looks like a router ip address.

my mac address starts with e8:c1:d7:01:30:

you can try this

https://github.com/rgerganov/py-air-control

airctrl --ipaddr your ip or let it discover it .

if above works, we can fix it , if below works we can work on it. try to make a node scrip like https://github.com/biemond/com.athom.philipsair/blob/master/test6.js reverse the python code after that we can move it to this app

airctrl --ipaddr ip --protocol coap

biemond commented 4 years ago

So I fixed the issue when ip address is not correct , now device will be disabled. you can test it out https://homey.app/nl-nl/app/com.athom.philipsair/Philips-Air/test/

iceburg1991 commented 4 years ago

Hi,

you are right about the IP address. I copied it from the docs, but didn't checked it. So i used my correct ip address (10.0.0.2) in my case. I also used the pip3 command to install the package, i saw that there is no --ipaddr, but by just typing 'airctrl 10.0.0.2 --wifi-ssid --wifi-pwd ' it is accepted but throws a HTTP 404 error. I think I need the --protocol argument... i noticed the --protocol argument is not available, i think you used the master branch from the github repo https://github.com/rgerganov/py-air-control/tree/master instead of the 0.0.3 version which was 'official' released and i used. I tried to install the master version, but for some reason i can't get this version working as shown in the image. I'm not sure if there is a solution for this airctrl problem..i will try to find something on the internet...but maybe i can try your script instead because i'm not sure if i can fix the airctrl problem.

I will let you know if i have an update...if you know a fix for the airctrl problem it's welcome.

IJsbrand

master-branch-not-working
biemond commented 4 years ago

Oh, I guess you are already connected to air matters or not. so no need for wifi.

this works for me

edwinbiemond@Edwins-MBP ~ % airctrl 192.168.2.195
GET error: Padding is incorrect.
Will retry after getting a new key ...
Exchanging secret key with the device ...
Saving session_key e2ea6f757dd080e2739e6266b6a21dad to /Users/edwinbiemond/.pyairctrl
[pwr]   Power: ON
[pm25]  PM25: 5
[iaql]  Allergen index: 2
[mode]  Mode: auto
[om]    Fan speed: silent
[aqil]  Light brightness: 100
[uil]   Buttons light: ON
[ddp]   Used index: PM2.5
[cl]    Child lock: False
biemond commented 4 years ago

maybe this can help with master branch https://dzone.com/articles/executable-package-pip-install

biemond commented 4 years ago

it looks like it is more complicated https://github.com/rgerganov/py-air-control/issues/21

iceburg1991 commented 4 years ago

Hm well, i managed the airctrl package to work. so now i connected to the 'PHILIPS setup' network, then entered 'airctrl 10.0.0.2 --protocol coap' and got a new error i'm afraid.

Still don't know why i have this strange 10.0.0.2 address... but my laptop is saying it's correct?...

Schermafbeelding 2020-04-15 om 23 09 04 Schermafbeelding 2020-04-15 om 23 14 57
biemond commented 4 years ago

I think you are on the philips network, can you pair or use air matters to setup

When I connect my notebook to the SSID “PHILIPS Setup” on my AC3829 air purifier, I get the address 10.0.0.2. I conclude that the default address of the air purifier will be 10.0.0.1.
biemond commented 4 years ago
telnet 10.0.0.1 30123
Trying 10.0.0.1...
Connected to 10.0.0.1.
Escape character is '^]'.
{"type":"deviceinfo","meta":{"message":"check device info","code":100},"data":{"name":"AirPurifier","type":"AC2729","modelid":"AC2729/50","swversion":"0.2.1"}}
iceburg1991 commented 4 years ago

yes that works like a charm.

But

airctrl --ipaddr 10.0.0.1 --protocol coap
coapthon.client.coap - WARNING - Give up on message From None, To ('10.0.0.1', 5683), CON-55467, EMPTY-None, [] No payload
Schermafbeelding 2020-04-15 om 23 34 04
biemond commented 4 years ago

what is your firmware of the telnet cmd?

biemond commented 4 years ago

1.4.0 I see

biemond commented 4 years ago

I think you need to connect to your wifi and air matters . and use that ip

iceburg1991 commented 4 years ago

so the normal pairing proces with the Air Matters app. And then use the IP address of the philips device to try the airctrl --ipaddr <ip> --protocol coap command ?

biemond commented 4 years ago

indeed, it will be an ip of your wifi network

iceburg1991 commented 4 years ago

well... it kind of works.. no errors... but also no result. I see in my router that the IP should be correct.

Schermafbeelding 2020-04-15 om 23 59 19 Schermafbeelding 2020-04-15 om 23 58 08

When pinging the IP on my laptop i get a request timeout so it's not reachable

biemond commented 4 years ago

use --debug to see the full output

iceburg1991 commented 4 years ago

Seems that the request is still not right

Schermafbeelding 2020-04-16 om 00 05 40
biemond commented 4 years ago

yep same as this https://github.com/rgerganov/py-air-control/issues/21#issuecomment-605464339

iceburg1991 commented 4 years ago

Hm yes i see. Thx for noticing that issue. Well, your code is based on his repo right? So then best we can do is wait for his response i think. Worst case is that Philips blocked the reversed engineered communication to create a (full) closed source application.

biemond commented 4 years ago

yep, more issues with 1.4.0 https://github.com/rgerganov/py-air-control/issues/21#issuecomment-581017602

biemond commented 4 years ago

Maybe we can check if the cloud ctrl of him will work instead

biemond commented 4 years ago

it looks like they are making some progress on it. https://github.com/rgerganov/py-air-control/issues/35

iceburg1991 commented 4 years ago

Hm sorry for my late response. I tried to use de clou ctrl, but haven't found my ID yet. I did manage to send a diagnostic mail to myself from the Air Matters App, i think the ID is in there :-p.

I'm reading the progress from rgerganov/py-air-control#35 and it sounds promising !! 👍 When they have a PR and it's approved by rgerganov, maybe we can make this work for Homey too :-)

biemond commented 4 years ago

Yep nice,

So ctrl is only controlling your device, you won't get the current status. Which we need. If they have it working we can do the same in node. especially now homey is using node12 instead of version 8.

biemond commented 4 years ago

Can you try this https://github.com/timbuktu-t/poc-philipsair/blob/master/src/main/java/philipsair/PhilipsAir.java

biemond commented 4 years ago

also this should work now

Installation (maybe you need sudo):

git clone -b coap_1_0_7 https://github.com/Cyber1000/py-air-control.git && cd py-air-control
python3 setup.py install
What works for now:

airctrl --ipaddr 192.168.11.190 --version 1.0.7 -d
airctrl --ipaddr 192.168.11.190 --version 1.0.7
iceburg1991 commented 4 years ago

Hi,

so i tried your suggestion. unfortunately i get the error 'Unexpected error:non-hexadecimal number found in fromhex() arg at position 1069'.

Schermafbeelding 2020-05-11 om 21 09 06
biemond commented 4 years ago

Oh, can you try the java client. Above looks like a programming bug. weird

Also found the node example code which we can use for this https://github.com/holomekc/pch-code-collection/tree/master/pch

iceburg1991 commented 4 years ago

ah you mean https://github.com/timbuktu-t/poc-philipsair/blob/master/src/main/java/philipsair/PhilipsAir.java yes I will look at this, I need to setup/configure Eclipse californium i saw in the imports of the file so i need a spare evening/weekend day to get it running i think. :-)

biemond commented 4 years ago

I guess you only need maven with java 11 jdk plus some editor maven will build it for you and download the dependencies

GSzabados commented 4 years ago

@biemond , @iceburg1991 The guys at py-air-control has found the problem with coap and did a PR there. After that you grab the latest version (which is literally changing a value to 1500 in the coap.py) from github the py-air-control works with the 1.4.0 firmware version when using coap protocol.

iceburg1991 commented 4 years ago

So I just now downloaded the release 2.0.0 from https://github.com/rgerganov/py-air-control And

Steps I did:

git clone https://github.com/rgerganov/py-air-control.git
cd py-air-control
python3 setup.py install
airctrl --ipaddr 192.168.1.162 --protocol coap

And as result i got all the information about the purifier (sign i can connect with it !)

so a last test is to turn it ON and OFF with airctrl --ipaddr 192.168.1.162 --protocol coap --pwr 0

AND IT WORKED !!! @biemond

biemond commented 4 years ago

I got also a coap device so now I also can work on it and add support to the homey app.

biemond commented 4 years ago

can you try this https://homey.app/nl-nl/app/com.athom.philipsair/Philips-Air/test/ it should work with the coap protocol

iceburg1991 commented 4 years ago

@biemond I tried it, and it looks like it works. I tried the on/off function and the fan speed function. The 'target humidity' doesn't seem to respons when selecting, but that's just 1 functionality. This is a very good progress you made. 👍 fyi: I used the 'humity and purifier 2020' as a device.

biemond commented 4 years ago

nice, let me check that part.

biemond commented 4 years ago

somehow I cannot find it ,maybe you can run this node testCoap.js

change ip 192.168.107.196 to yours.

change this to https://github.com/biemond/com.athom.philipsair/blob/master/testCoap.js#L283

rhset as key and "40", "50", "60", "70" as possible values with or without quotes. plus maybe it needs to be in non purifier mode 1st to make this rhset change

iceburg1991 commented 4 years ago

So i tried the rhset test,he doesn't like it very much. I also tried it with the correct 'DeviceId' but it gives the same result.

Schermafbeelding 2020-07-06 om 00 00 35

I also tried a simple power off to have a base test so my local setup was correct. This worked just fine

Schermafbeelding 2020-07-06 om 00 04 53
biemond commented 4 years ago

can you try it as a number, without quotes on 50

also did you change the mode 1st? plus can you set it active with airmatters or on the device. after that change it to 50.

iceburg1991 commented 4 years ago
biemond commented 4 years ago

will now rhset and 60 work without mode, and does it show the next time 60 in the values.

it is by the way this

            // P or PH
            let values;
            if ( value == true ) {
                values = "PH";
            } else {
                values =  "P";
            }
            this.setStateCoap("func", values);
iceburg1991 commented 4 years ago

I tried to set the function to PH

Schermafbeelding 2020-07-06 om 18 53 44

And in a second request i set the humidity to 50, but still with no result. It's like he doesn't understand the command. When I put a wrong value for the 'func' key like the value 'B' it will behave the same as the 'rhset' with value '40'/'50'/'60'. No bleep sound on the machine and nothing happens

Schermafbeelding 2020-07-06 om 18 54 58
biemond commented 4 years ago

ok can you capture the current raw status output of this script. and try to set it on the device it self ,

I am curious in the differences. plus set it off till 70%. and back to purifier mode again.

iceburg1991 commented 4 years ago

Ok so I did all that and I don't see any interesting values in the objects. But I discovered something else interesting. The keys with values I can change are all strings, but the 'rhset' is an int. When looking at the other int attributes it looks like it are all 'read-only' attributes, like error code...runtime, current temperature. Another interesting fact is that I can't change the preferred humidity in the official Air Matters app. So in my opinion this specific attribute is a read-only attribute and cannot be changed remotely. I don't know why, maybe for legal reasons. I know the smart ovens of Bosch Accent line cannot be put on remotely out of safety reasons unless you tell (every time) when you leave the house you accept the terms to use this function on your own responsibility and risk. When in the house within the same Wifi network you can put the oven on without this agreement.

Raw output when manual put it on 70%: (watch the rhset value)

 state: {
    reported: {
      name: 'Woonkamer',
      type: 'AC3829',
      modelid: 'AC3829/10',
      swversion: '1.4.0',
      DeviceVersion: '0.0.0',
      om: '2',
      pwr: '1',
      cl: false,
      aqil: 100,
      uil: '1',
      dt: 0,
      dtrs: 0,
      mode: 'M',
      func: 'PH',
      rhset: 70,
      rh: 60,
      temp: 24,
      pm25: 1,
      iaql: 1,
      aqit: 65535,
      ddp: '3',
      rddp: '0',
      err: 0,
      wl: 100,
      fltt1: 'A3',
      fltt2: 'C7',
      fltsts0: 253,
      fltsts1: 2886,
      fltsts2: 2886,
      wicksts: 2886,
      ota: 'ck',
      Runtime: 3911289237,
      WifiVersion: 'AWS_Philips_AIR@54.2',
      ProductId: '<secret>',
      DeviceId: '<secret>',
      StatusType: 'localcontrol',
      ConnectType: 'Localcontrol'
    }

Raw output when manual put it on 50%:

 state: {
    reported: {
      name: 'Woonkamer',
      type: 'AC3829',
      modelid: 'AC3829/10',
      swversion: '1.4.0',
      DeviceVersion: '0.0.0',
      om: '2',
      pwr: '1',
      cl: false,
      aqil: 100,
      uil: '1',
      dt: 0,
      dtrs: 0,
      mode: 'M',
      func: 'PH',
      rhset: 50,
      rh: 59,
      temp: 24,
      pm25: 2,
      iaql: 1,
      aqit: 65535,
      ddp: '3',
      rddp: '0',
      err: 0,
      wl: 100,
      fltt1: 'A3',
      fltt2: 'C7',
      fltsts0: 253,
      fltsts1: 2886,
      fltsts2: 2886,
      wicksts: 2886,
      ota: 'ck',
      Runtime: 3911028145,
      WifiVersion: 'AWS_Philips_AIR@54.2',
      ProductId: '<secret>',
      DeviceId: '<secret>',
      StatusType: 'localcontrol',
      ConnectType: 'Localcontrol'
    }

When using the script to set 'rhset' to 60 (no difference with other raw output)

{
  state: {
    reported: {
      name: 'Woonkamer',
      type: 'AC3829',
      modelid: 'AC3829/10',
      swversion: '1.4.0',
      DeviceVersion: '0.0.0',
      om: '2',
      pwr: '1',
      cl: false,
      aqil: 100,
      uil: '1',
      dt: 0,
      dtrs: 0,
      mode: 'M',
      func: 'PH',
      rhset: 70,
      rh: 60,
      temp: 24,
      pm25: 1,
      iaql: 1,
      aqit: 65535,
      ddp: '3',
      rddp: '0',
      err: 0,
      wl: 100,
      fltt1: 'A3',
      fltt2: 'C7',
      fltsts0: 253,
      fltsts1: 2886,
      fltsts2: 2886,
      wicksts: 2886,
      ota: 'ck',
      Runtime: 3911289237,
      WifiVersion: 'AWS_Philips_AIR@54.2',
      ProductId: '<secret>',
      DeviceId: '<secret>',
      StatusType: 'localcontrol',
      ConnectType: 'Localcontrol'
    }
  }
}
Power: ON
PM25: 1
Target humidity: 70
Allergen index: 1
Temperature: 24
Function: Purification & Humidification
Mode: manual
Fan speed: undefined
Light brightness: 100
Buttons light: ON
Used index: undefined
Water level: 100
Child lock: false
Timer hours: 0
Timer minutes: 0
Error: -
Name: Woonkamer
Product: AC3829/10
version: 1.4.0
Pre-filter: clean in 253 hours
Active Carbon C7 filter: replace in 2886 hours
HEPA A3 filter: replace in 2886 hours
-------start humidity test------------
messageString {"state":{"desired":{"CommandType":"app","DeviceId":"","EnduserId":"1","rhset":"60"}}}
-------------------
{"status":"success"}
-------------------
biemond commented 4 years ago

great work , indeed int or number , did you change the script value to a int instead of quotes around it. The old firmware allowed it and is verified by @iFac3 issue #1

maybe it can be dangerous when it is set to high.

biemond commented 4 years ago

rh: 59 is that like a timer , I saw it on the timer func you put in hours and you will see the remaining minutes. dt: 0, dtrs: 0

biemond commented 4 years ago

looks like rh is current humidity.

GSzabados commented 4 years ago

@biemond, if you look at the py-air-control issues, you would find one related to setting speed of a coap device when the mode is M, as I remember. You might be hitting that, or something similar. I am not a Homey user, but playing with my Philips Purifier and Humidifier through the airctrl. I have seen many weird things from the device itself. The coap control seems to be flakey, and I believe that is due to the firmware and the pretty bad programming from Philips. I have set once the lights that way, that the ring was off, but numbers were still displayed. I couldn't restore the normal state neither through the official app or by the buttons of the device, just physically powering off by the power cable. I managed to lock up the device once that it was not reacting anymore to airctrl. Same result, physical power cycling helped as well. Time to time the device doesn't reacts to commands at the first time as well, just at the second time.

I hope it helps.

biemond commented 4 years ago

yep , also on uil ,button lights it allows 0 or 1 but on AC-2889 it is always 2 -> the disabled state.

@iceburg1991 can we try this messageString {"state":{"desired":{"CommandType":"app","DeviceId":"","EnduserId":"1","rhset": 60}}}. it looks like coap does not do any validation, handle types not really well or does not handle protected changes and just do a fake success