ckuburlis / homebridge-tado

16 stars 15 forks source link

Error while parsing Tado response. "Temperature" not found #20

Closed nicktmro closed 7 years ago

nicktmro commented 7 years ago

Hi,

I installed the latest from git today and gave the tado plugin another try. Unfortunately I get the response below:

/usr/local/lib/node_modules/homebridge-tado/index.js:323
            if (obj.setting.temperature == null) {
                           ^

TypeError: Cannot read property 'temperature' of undefined
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/homebridge-tado/index.js:323:28)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

For reference, this is the state that I see when inspecting the http response from my.tado.com using my browser:

{
    "tadoMode": "HOME",
    "geolocationOverride": true,
    "geolocationOverrideDisableTime": "2017-01-23T16:45:00Z",
    "preparation": null,
    "setting": {
        "type": "AIR_CONDITIONING",
        "power": "ON",
        "mode": "AUTO"
    },
    "overlayType": "MANUAL",
    "overlay": {
        "type": "MANUAL",
        "setting": {
            "type": "AIR_CONDITIONING",
            "power": "ON",
            "mode": "AUTO"
        },
        "termination": {
            "type": "TADO_MODE",
            "projectedExpiry": "2017-01-23T16:45:00Z"
        }
    },
    "link": {
        "state": "ONLINE"
    },
    "activityDataPoints": {},
    "sensorDataPoints": {
        "insideTemperature": {
            "celsius": 22.63,
            "fahrenheit": 72.73,
            "timestamp": "2017-01-23T08:35:49.150Z",
            "type": "TEMPERATURE",
            "precision": {
                "celsius": 0.1,
                "fahrenheit": 0.1
            }
        },
        "humidity": {
            "type": "PERCENTAGE",
            "percentage": 56.4,
            "timestamp": "2017-01-23T08:35:49.150Z"
        }
    }
}

I hope this helps with diagnosing the problem.

Cheers, Nick

nitaybz commented 7 years ago

@nicktmro seems like your tado set your air conditioner to an auto state. Unfortunately the plugin does not support auto state on the air conditioner Since the homekit support only those conditions (OFF, HEAT, COOL, AUTO), I set the auto to support Tado auto mode and not the aircon auto mode since not everyone has that state in their air conditioner.

Please change your aircon to cool or heat mode (that will return the temperature) and it should solve your problem, let me know how it goes.

nicktmro commented 7 years ago

Thanks for the quick reply. I changed to "HEAT" and now I'm getting this:

/usr/local/lib/node_modules/homebridge-tado/index.js:301
                accessory.log("Room temperature is " + obj.sensorDataPoints.insideTemperature.celsius + "ºC");
                                                                           ^

TypeError: Cannot read property 'insideTemperature' of undefined
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/homebridge-tado/index.js:301:76)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

and in the browser:

{
    "tadoMode": "HOME",
    "geolocationOverride": true,
    "geolocationOverrideDisableTime": "2017-01-23T16:45:00Z",
    "preparation": null,
    "setting": {
        "type": "AIR_CONDITIONING",
        "power": "ON",
        "mode": "HEAT",
        "temperature": {
            "celsius": 21,
            "fahrenheit": 69.8
        },
        "fanSpeed": "LOW"
    },
    "overlayType": "MANUAL",
    "overlay": {
        "type": "MANUAL",
        "setting": {
            "type": "AIR_CONDITIONING",
            "power": "ON",
            "mode": "HEAT",
            "temperature": {
                "celsius": 21,
                "fahrenheit": 69.8
            },
            "fanSpeed": "LOW"
        },
        "termination": {
            "type": "TADO_MODE",
            "projectedExpiry": "2017-01-23T16:45:00Z"
        }
    },
    "link": {
        "state": "ONLINE"
    },
    "activityDataPoints": {},
    "sensorDataPoints": {
        "insideTemperature": {
            "celsius": 22.92,
            "fahrenheit": 73.26,
            "timestamp": "2017-01-23T09:06:05.094Z",
            "type": "TEMPERATURE",
            "precision": {
                "celsius": 0.1,
                "fahrenheit": 0.1
            }
        },
        "humidity": {
            "type": "PERCENTAGE",
            "percentage": 56.5,
            "timestamp": "2017-01-23T09:06:05.094Z"
        }
    }
}

Hope this helps

nicktmro commented 7 years ago

FWIW, I don't have a username for Tado. I can only log in by using my email address + password combo, so that's what I put in my config.

nitaybz commented 7 years ago

username is your email

nitaybz commented 7 years ago

can you show me your config? hide your personal details of course

nicktmro commented 7 years ago

Sure thing.

{
"accessory":"TADO", "name":"Tado", "homeID":"55555", "username":"my@email.com", "password":"my_password", "useFahrenheit":false }

nitaybz commented 7 years ago

there is a new config... try updating your config according to the new one (explanations are in README.md)

nicktmro commented 7 years ago

Thanks. I cannot seem to find what I'm doing wrong in the config. I added the fields below but still, no luck.

        {  
            "accessory":"TADO",
            "name":"Tado",
            "homeID":"55555",
            "username":"my@email.com",
            "password":"my_password",
            "useFahrenheit":false,
            "maxValue": 31,
            "minValue": 16,
        "zone": 1,
            "useFanSpeed": "AUTO",
            "useSwing": false
        }

I'm also in the homebridgeteam slack if it helps with the comms.

nitaybz commented 7 years ago

try installing that: sudo npm install -g https://github.com/ckuburlis/homebridge-tado.git#Test I want to see your console afterwards. that should print the object before and after the parsing.

nicktmro commented 7 years ago
   [ { code: 'accessDenied',
       title: 'current user is not allowed to access home <redacated 5 digit number> } ] }

Hmmm... Looks like the login is the issue.

nitaybz commented 7 years ago

are you sure your username and password are correct? how about the homeID? sure it's correct?

nicktmro commented 7 years ago

Trying the old api to check the HomeID doesn't work. Is there another way? It looks like they removed it from the JSON response I used to look at...

The username / pwd are definitely correct.

nicktmro commented 7 years ago

I currently grab it from the URL: https://my.tado.com/api/v2/homes/55555/zones/1/state. I swapped my id with 55555

nitaybz commented 7 years ago

it does work for me so there is probably something wrong with your credential or the way you are making the request. when I call: https://my.tado.com/mobile/1.4/getCurrentState?username=ACTUAL_USERNAME&password=ACTUAL_PASSWORD

I get the HomeId perfectly.

don't you add your credentials to your request? - "?username=ACTUAL_USERNAME&password=ACTUAL_PASSWORD"

nitaybz commented 7 years ago

try to login to your account through the web, in tado website, see if you can do that: https://www.tado.com/login

nicktmro commented 7 years ago

If I use Chrome to make the request above I get:

{  
   "success":true,
   "operation":"HOME",
   "autoOperation":"UNDEFINED",
   "operationTrigger":"USER",
   "insideTemp":null,
   "setPointTemp":null,
   "controlPhase":"UNDEFINED",
   "boxConnected":false,
   "gwConnected":false,
   "tsConnected":false,
   "currentUserPrivacyEnabled":false,
   "currentUserGeoStale":false,
   "deviceUpdating":false,
   "homeId":55555,
   "pendingDeviceInstallation":false
}

Safari just errors with

{"errors":[{"code":"unauthorized","title":"Invalid referrer"}]}
nitaybz commented 7 years ago

I know whats the problem!!!!!! I think! remove the "" from your homeId! should solve it

nicktmro commented 7 years ago

I just tried removing the quotes. I got the same

[1/23/2017, 10:44:54 PM] [Tado] { errors: 
   [ { code: 'accessDenied',
       title: 'current user is not allowed to access home 55555' } ] }
nitaybz commented 7 years ago

can you call this? https://my.tado.com/api/v2/homes/55555/zones/1/state?username=ACTUAL_USERNAME&password=ACTUAL_PASSWORD

with your user details in the url?

nicktmro commented 7 years ago

UPDATED:

{"errors":[{"code":"accessDenied","title":"current user is not allowed to access home 55555"}]}

You may be onto something though: we have two users registered to connect to the Tado so maybe that's part of the problem...

nitaybz commented 7 years ago

so how did you bring the state earlier in the reply?

nicktmro commented 7 years ago

I cannot get the state via the v2 api. I'm given the access denied error.

It does work with the https://my.tado.com/mobile/1.4/getCurrentState?username=ACTUAL_USERNAME&password=ACTUAL_PASSWORD version.

nitaybz commented 7 years ago

are you able to connect to your tado account from the web? maybe you need to update your device, it is weird that only v2 makes you issues, when on my side it works great.

nicktmro commented 7 years ago

I'm able to connect via the web and I can also make changes that get applied correctly.

Maybe relevant: I noticed in my browser that they use refresh tokens.

{
    "access_token": "REDACTED",
    "token_type": "bearer",
    "refresh_token": "REDACTED",
    "expires_in": 599,
    "scope": "home.user"
}
nicktmro commented 7 years ago

Regarding the "update" part, here's what I have (redacted serial):

Smart AC Control

        "deviceType": "WR01",
        "serialNo": "WR1234123412",
        "shortSerialNo": "WR1234123412",
        "currentFwVersion": "26.3",
nitaybz commented 7 years ago

I know they use tokens but getting permissions through the url is still valid, and unless I get more complains about error login that way I'm not sure the solution will be to change the authorization method.

nitaybz commented 7 years ago

is it possible that you are participating in Tado beta program?

nicktmro commented 7 years ago

I didn't register for the beta program...

This request does return correctly.

REQUEST: curl -s "https://my.tado.com/oauth/token" -d client_id=tado-webapp -d grant_type=password -d password=my_password -d scope=home.user -d username=my@email.com

RESPONSE:

{  
 "access_token":"REDACTED",
   "token_type":"bearer",
   "refresh_token":"12345678-f128-41b1-9046-9199af9311c7",
   "expires_in":599,
   "scope":"home.user"
}
nicktmro commented 7 years ago

By the way, I found this blog post to be useful: http://blog.scphillips.com/posts/2017/01/the-tado-api-v2/

nitaybz commented 7 years ago

I'm aware of this blog...

when I look at your results I actually see that you are using more advanced version of the device than me. might be the reason why mine is still working in the old way.... though I don't know how to update it to your version since it's automatically updating anyway. my version returns:

deviceType: "WR01",
serialNo: "WR1505FT01001359151360",
shortSerialNo: "WR1359151360",
currentFwVersion: "22.13",
nicktmro commented 7 years ago

Thanks for looking into this @nitaybz

I'm thinking that the more Tados people buy, the more likely it is that you will see requests like mine :(

If I knew more about Node, I'd look into sending you a pull request using https://www.npmjs.com/package/refresh-token but I'm not a JavaScript dev...

nitaybz commented 7 years ago

I will fix it... give me some time and I will change the way it works for the new version... hope it will be sooner than later

nicktmro commented 7 years ago

Thank you. Please get in touch if you need me to help with testing. I'm available via the homebridge Slack, as well.

nitaybz commented 7 years ago

I'm not there... how do I get there?

nicktmro commented 7 years ago

http://homebridge-slackin.herokuapp.com/

nitaybz commented 7 years ago

@nicktmro I tried to update the authorization method to the new one but I don't have a way to look if it works today. I only changed the get current state/temperature for now, if you see that it can update the status i will also implement it on the 'Set' option (set temperature/mode).

you can try this version here: sudo npm install -g https://github.com/ckuburlis/homebridge-tado.git#Test

Let me know how it goes

nicktmro commented 7 years ago

Thanks @nitaybz

I installed the Test branch, and this is what I see:

[1/24/2017, 7:19:28 AM] [Tado] New Token is <TOKEN1>
[1/24/2017, 7:19:32 AM] [Tado] Getting target state
[1/24/2017, 7:19:32 AM] [Tado] check header:   Bearer <TOKEN1>
[1/24/2017, 7:19:32 AM] [Tado] Getting target state
[1/24/2017, 7:19:32 AM] [Tado] check header:   Bearer <TOKEN1>
[1/24/2017, 7:19:32 AM] [Tado] Getting target state
[1/24/2017, 7:19:32 AM] [Tado] check header:   Bearer <TOKEN1>
[1/24/2017, 7:19:32 AM] [Tado] Getting target state
[1/24/2017, 7:19:32 AM] [Tado] check header:   Bearer <TOKEN1>
[1/24/2017, 7:19:32 AM] [Tado] The current temperature display unit is ºC
[1/24/2017, 7:19:33 AM] [Tado] {"errors":[{"code":"accessDenied","title":"current user is not allowed to access home 55555"}]}
[1/24/2017, 7:19:33 AM] [Tado] { errors: 
   [ { code: 'accessDenied',
       title: 'current user is not allowed to access home 55555' } ] }
/usr/local/lib/node_modules/homebridge-tado/index.js:334
                accessory.log("Room temperature is " + obj.sensorDataPoints.insideTemperature.celsius + "ºC");

TypeError: Cannot read property 'insideTemperature' of undefined
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/homebridge-tado/index.js:334:76)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

The tokens appear to be correct... somehow the API calls don't seem to use them, maybe?

nicktmro commented 7 years ago

The errors seem to happen in a few places (whichever callback gets made first) when I restart home bridge:

nitaybz commented 7 years ago

Please try to install again... I tried a different way to save the token.

nicktmro commented 7 years ago

I updated to the latest Test branch and re-run:

[1/24/2017, 11:05:37 AM] [Tado] Getting target state
[1/24/2017, 11:05:37 AM] [Tado] check header:   Bearer <TOKEN REDACTED>
/usr/local/lib/node_modules/homebridge-tado/index.js:214
            if (obj.setting.temperature != null) {
                           ^

TypeError: Cannot read property 'temperature' of undefined
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/homebridge-tado/index.js:214:28)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
nicktmro commented 7 years ago

The second time I ran homebridge I got:

[1/24/2017, 11:08:13 AM] [Tado] {"errors":[{"code":"accessDenied","title":"current user is not allowed to access home 55555"}]}
[1/24/2017, 11:08:13 AM] [Tado] { errors: 
   [ { code: 'accessDenied',
       title: 'current user is not allowed to access home 55555' } ] }
/usr/local/lib/node_modules/homebridge-tado/index.js:340
                accessory.log("Room temperature is " + obj.sensorDataPoints.insideTemperature.celsius + "ºC");
                                                                           ^

TypeError: Cannot read property 'insideTemperature' of undefined
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/homebridge-tado/index.js:340:76)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
nitaybz commented 7 years ago

I need to see more. For some reason you can't pull the token properly. There is another log I used there to detect if the Token is accepted, send me the logs of the homebridge after starting. There should be something written: New Token is...

Also, please look in the persist folder for a file name 'Tado_Token' and tell me what's inside.

I've tested this branch on my side and it actually works great.

On 24 Jan 2017, at 0:09, Nick notifications@github.com wrote:

The second time I ran homebridge I got:

[1/24/2017, 11:08:13 AM] [Tado] {"errors":[{"code":"accessDenied","title":"current user is not allowed to access home 55555"}]} [1/24/2017, 11:08:13 AM] [Tado] { errors: [ { code: 'accessDenied', title: 'current user is not allowed to access home 55555' } ] } /usr/local/lib/node_modules/homebridge-tado/index.js:340 accessory.log("Room temperature is " + obj.sensorDataPoints.insideTemperature.celsius + "ºC"); ^

TypeError: Cannot read property 'insideTemperature' of undefined at IncomingMessage. (/usr/local/lib/node_modules/homebridge-tado/index.js:340:76) at emitNone (events.js:91:20) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:74:11) at process._tickCallback (internal/process/next_tick.js:98:9)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

nicktmro commented 7 years ago

Upon startup I do see the new token:

[1/24/2017, 11:12:18 AM] [Tado] New Token is <REDACTED 857 CHARACTER LONG TOKEN>

I see two files in the persist folder. One called Tado_lastTemp that contains the number 25 (correct temperature, actually!) and the other file is called Tado_Token that contains the correct TOKEN but between double quotes.

nicktmro commented 7 years ago

I'm so sorry, I found the issue: my homeID had a typo in it. I can confirm that it now works.

I set up a local copy of your test branch, learned how to use the util module, created a npm link, and inspected the request...

nicktmro commented 7 years ago

Now that it works I did some testing and I found an issue that causes the Mode to be reset to HEAT when the temperature slider is used: #22. You mentioned in a comment above that you didn't implement Set but I wasn't sure if the Mode should also be reset in the process (upon pushing the token support in the Test branch).

nitaybz commented 7 years ago

Fixed in the last branch update... let me know that it works well on your side so I can close the issue and update the master branch.