mattdavis90 / node-red-contrib-tado-client

Tado web API client node for Node Red
MIT License
23 stars 16 forks source link

AxiosError: Request failed with status code 422 #47

Closed MrAlfabet closed 1 year ago

MrAlfabet commented 2 years ago

Since a few days I've been getting the following error when trying to set a zone's overlay:

AxiosError: Request failed with status code 422

Has something changed?

mattdavis90 commented 2 years ago

Hi @MrAlfabet, Yes there were some changes made over the weekend to upgrade the underlying library that this node uses. I thought I'd tested all of the integration points but clearly missed something. Do you have an example of the overlay that you're sending? This may help me test.

I'll push a change now to downgrade the library and get things working again - then we can try to the upgrade again once setOverlay is working again. Apologies for the problems

MrAlfabet commented 2 years ago

I'm trying to set heating off as the overlay.

On the plus side: the house is nice and warm now. On the down side: gas prices....

On Wed, Nov 23, 2022, 20:50 Matt Davis @.***> wrote:

Hi @MrAlfabet https://github.com/MrAlfabet, Yes there were some changes made over the weekend to upgrade the underlying library that this node uses. I thought I'd tested all of the integration points but clearly missed something. Do you have an example of the overlay that you're sending? This may help me test.

I'll push a change now to downgrade the library and get things working again - then we can try to the upgrade again once setOverlay is working again.

— Reply to this email directly, view it on GitHub https://github.com/mattdavis90/node-red-contrib-tado-client/issues/47#issuecomment-1325581315, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHYMS7AGROPQ6TXXEQO7BL3WJZYPDANCNFSM6AAAAAASIMABQE . You are receiving this because you were mentioned.Message ID: @.***>

mattdavis90 commented 2 years ago

Hi, I've pushed a version to npm that uses an older version of the library. If you have a flow JSON that is broken and you're happy to send it to me that would help so much - I don't need your login details just how the nodes are configured or what options you're using. This seems to work on my setup so curious what broke.

MrAlfabet commented 2 years ago
[
    {
        "id": "512f9271ad769b56",
        "type": "tado",
        "z": "83b78f0b26ffa154",
        "configName": "86bbe474.0008e8",
        "apiCall": "setZoneOverlay",
        "homeId": "111111",
        "deviceId": "",
        "zoneId": "8",
        "power": "on",
        "temperature": "5",
        "terminationType": "manual",
        "terminationTimeout": 900,
        "name": "Kippenhok off",
        "reportDate": "",
        "presence": "HOME",
        "geoTracking": true,
        "temperatureOffset": 0,
        "windowDetection": true,
        "windowDetectionTimeout": 900,
        "openWindowMode": true,
        "timetableId": "",
        "x": 500,
        "y": 140,
        "wires": [
            [
                "0a94cbf31a6d3f49"
            ]
        ]
    },
    {
        "id": "7b740b2b3dbece3e",
        "type": "inject",
        "z": "83b78f0b26ffa154",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 260,
        "y": 140,
        "wires": [
            [
                "512f9271ad769b56"
            ]
        ]
    },
    {
        "id": "0a94cbf31a6d3f49",
        "type": "debug",
        "z": "83b78f0b26ffa154",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 760,
        "y": 140,
        "wires": []
    },
    {
        "id": "86bbe474.0008e8",
        "type": "tado-config",
        "name": "My Name"
    }
]
MrAlfabet commented 2 years ago

It's still not working on the latest version by the way.

mattdavis90 commented 2 years ago

Hi, I've just been doing some testing with the latest version and it looks as though the lowest temperature that I can set on an overlay is 5℃ - I can't change to 3 like your flow is trying to - this isn't a change that I've made in the library and is likely something that Tado have done on their end.

MrAlfabet commented 2 years ago

Is it trying to set to 3? In the gui I have the settings 'set overlay' > heating off.

Would a screen shot help?

On Thu, Nov 24, 2022, 19:43 Matt Davis @.***> wrote:

Hi, I've just been doing some testing with the latest version and it looks as though the lowest temperature that I can set on an overlay is 5℃ - I can't change to 3 like your flow is trying to - this isn't a change that I've made in the library and is likely something that Tado have done on their end.

— Reply to this email directly, view it on GitHub https://github.com/mattdavis90/node-red-contrib-tado-client/issues/47#issuecomment-1326768965, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHYMS7FEBHQ4LVNIUY3B7I3WJ6ZONANCNFSM6AAAAAASIMABQE . You are receiving this because you were mentioned.Message ID: @.***>

mattdavis90 commented 2 years ago

You're totally correct, it says 5℃ in your flow... not sure where I saw the 3... but the flow you sent has heating power set to on - I'm not sure why that isn't matching the settings you have in the GUI. If you have a screenshot that would be handy

"zoneId": "8",
"power": "on",
"temperature": "5",
"terminationType": "manual",
MrAlfabet commented 2 years ago

My bad, I've been playing around with it trying to see what would work. This is the flow for turning the heating off. Neither this, nor the setting it to 5C works.

[
    {
        "id": "7e9de366ca0659ca",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "7c2e29da387fd0f2",
        "type": "tado",
        "z": "7e9de366ca0659ca",
        "configName": "86bbe474.0008e8",
        "apiCall": "setZoneOverlay",
        "homeId": "419521",
        "deviceId": "",
        "zoneId": "8",
        "power": "off",
        "temperature": "5",
        "terminationType": "manual",
        "terminationTimeout": 900,
        "name": "Kippenhok off",
        "reportDate": "",
        "presence": "HOME",
        "geoTracking": true,
        "temperatureOffset": 0,
        "windowDetection": true,
        "windowDetectionTimeout": 900,
        "openWindowMode": true,
        "timetableId": "",
        "x": 520,
        "y": 220,
        "wires": [
            [
                "c99390f767219d44"
            ]
        ]
    },
    {
        "id": "59d681d6cf7c3ce7",
        "type": "inject",
        "z": "7e9de366ca0659ca",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 280,
        "y": 220,
        "wires": [
            [
                "7c2e29da387fd0f2"
            ]
        ]
    },
    {
        "id": "c99390f767219d44",
        "type": "debug",
        "z": "7e9de366ca0659ca",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 780,
        "y": 220,
        "wires": []
    },
    {
        "id": "86bbe474.0008e8",
        "type": "tado-config",
        "name": "Marijn Blom"
    }
]
MrAlfabet commented 2 years ago

Now that I'm trying a bit more, it seems that I cannot set any overlay. No temperatures work with heating on, heating off doesn't work either. 'ClearZoneOverlay' does seem to work though.

getOverlay returns an empty message. It something more is going on here... I am able to set the water heater temperature, so it's not the connection to the tado service.

mattdavis90 commented 2 years ago

That's interesting. I'm struggling to replicate this. I've updated my install to the latest v0.10.1 version of the plugin and can set overlays with and without heating at home. Just to double check this was working before the weekend and all of a sudden stopped working? Did you upgrade to v0.10.0 of the plugin when it stopped working? I'm just trying to work out what things may have changed. Also, would you mind trying to set and clear overlays on the mobile or web app and just double check there's nothing wrong with Tado. Thanks

mattdavis90 commented 2 years ago

I've just noticed that your flow JSON doesn't contain the following

"fanSpeed": "AUTO",
"acMode": "AUTO",

These were added in v0.9.8 of the library which was released in June 2021 - could you check that you're running a recent version? Thanks

MrAlfabet commented 2 years ago

I updated yesterday from 10.0 to 10.1 I think. Would I have to recreate the nodes?

On Thu, Nov 24, 2022, 20:29 Matt Davis @.***> wrote:

I've just noticed that your flow JSON doesn't contain the following

"fanSpeed": "AUTO","acMode": "AUTO",

These were added in v0.9.8 of the library which was released in June 2021

  • could you check that you're running a recent version? Thanks

— Reply to this email directly, view it on GitHub https://github.com/mattdavis90/node-red-contrib-tado-client/issues/47#issuecomment-1326792603, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHYMS7BM4EGRDBT3FSCDG4TWJ66YPANCNFSM6AAAAAASIMABQE . You are receiving this because you were mentioned.Message ID: @.***>

mattdavis90 commented 2 years ago

You shouldn't have to recreate the nodes, it does that when you restart NodeRed after the update. I'll keep playing around on this side and see if there's anything I can do to recreate the 422 error that you're seeing

MrAlfabet commented 2 years ago

My sincere apologies, apparently the update yesterday didn't go through. I've just upgraded from 10.0 to 10.1 and everything is working again.

mattdavis90 commented 2 years ago

Great news. Now I just need to work out what went wrong with the updates over the weekend with the underlying library.

MrAlfabet commented 2 years ago

Please let me know if I can help test anything. You've been great!

xHUNx commented 1 year ago

Any ETA on the fix ? I'm also suffer from the same Issue and cannot "override" any SetZoneOverlay property. Whatever set on the GUI node works once triggered but doesn't matter how/what message I send in payload cannot override the property ( example) power On/Off.

mattdavis90 commented 1 year ago

The update that broke setZoneOverlay was reverted two weeks ago. Although the issue isn't really fixed because I'd like to be able to reapply the update it should be in a working state.

The issue you're facing sounds different to the one this issue is tracking. Could you open a new issue with an example flow? and double check that you're running v0.10.1 of the library. Thanks

MrAlfabet commented 1 year ago

I am now (or perhaps also before and didn't notice) also getting the same error when trying to turn off the water heater.

[{"id":"9da623335b83404b","type":"tado","z":"397af457.1b217c","configName":"86bbe474.0008e8","apiCall":"setZoneOverlay","homeId":"1111111","deviceId":"","zoneId":"0","power":"off","temperature":"18","terminationType":"manual","terminationTimeout":900,"name":"Warm Water Off","reportDate":"","presence":"HOME","geoTracking":true,"temperatureOffset":0,"windowDetection":true,"windowDetectionTimeout":900,"openWindowMode":true,"timetableId":"","x":360,"y":1420,"wires":[["7299f7bc68dfabae"]]},{"id":"86bbe474.0008e8","type":"tado-config","name":"Marijn Blom"}]
MrAlfabet commented 1 year ago

Also, some more functions wrt the hot water heater don't seem to work, like the temporary temperature overlay

mattdavis90 commented 1 year ago

Hi, that's interesting. Hot water is something I'm unable to test - my boiler doesn't have an input for it - central heating is actually the only Tado product I have (though I'm hopefully getting some TRVs soon). The 422 error on the Tado API seems to cover quite a few circumstances so it may be that the API arguments are slightly different for a hot water zone. In Google Chrome or Mozilla Firefox are you able to go to app.tado.com and open DevTools. When you perform the actions in the web app you should see the API calls in the Network tab - this is what my library replicates. This may shine a light on whether there are any changes to the API needed for hot water. Thanks

MrAlfabet commented 1 year ago

The request URL when changing the water temperature is https://my.tado.com/api/v2/homes/111111/zones/0/overlay?ngsw-bypass=true where I replaced my home ID with 11111. Is that what you're looking for?

mattdavis90 commented 1 year ago

Yes, that's great. Do you see the payload? This is the same API call I already implement with a PUT method. It would be good to know if the payload is different for hit water compared to heating. Thanks

MrAlfabet commented 1 year ago

{"termination":{"typeSkillBasedApp":"TIMER","durationInSeconds":3600,"remainingTimeInSeconds":3600,"projectedExpiry":"Thu, 22 Dec 2022 23:54:53 GMT"},"setting":{"type":"HOT_WATER","power":"ON","temperature":{"celsius":44,"fahrenheit":111.2}}}

Overlay with timer termination

MrAlfabet commented 1 year ago

{"setting":{"type":"HOT_WATER","power":"ON","temperature":{"celsius":44,"fahrenheit":111.2}},"termination":{"typeSkillBasedApp":"MANUAL"}}

Overlay until manual override

MrAlfabet commented 1 year ago

{"termination":{"typeSkillBasedApp":"MANUAL"},"setting":{"type":"HOT_WATER","power":"OFF"}}

Turn hot water off

MrAlfabet commented 1 year ago

{"setting":{"type":"HOT_WATER","power":"OFF","temperature":null},"termination":{"typeSkillBasedApp":"TIMER","durationInSeconds":3600}}

Hot water off for duration

MrAlfabet commented 1 year ago

Not sure what other use cases I missed, but I gather you can probably distill a pattern from this of what needs to be changed/updated?

mattdavis90 commented 1 year ago

That's really helpful. Thanks. I think the issue is that my library only currently caters for HEATING and AIR_CONDITIONING in the type field. Using your example I should be able to put something together. I'm struggling to commit too much time at the minute due to family commitments (replying is ok but getting the laptop out and writing code seems like a stretch) but I'll see if I can fit it in over the holidays

MrAlfabet commented 1 year ago

Doesn't help that the HA service call didn't work today for a few hours, having me pull my hair out over why only to just go back to working by itself.

mattdavis90 commented 1 year ago

I'm not sure what your referring to when you say HA service. Is that Home Assistant?

MrAlfabet commented 1 year ago

Yes, Home Assistant has its own tado service calls. It's not as complete as your node-red integration though.

mattdavis90 commented 1 year ago

Ok. I believe they use the same API my library does, likely from reverse engineering the web app. I guess with it not being an officially supported API it isn't always the most stable interface. I've had to make changes in the post to accommodate.

I've just skimmed the code for overlays and it does a call to getZoneState first on order to determine the type of zone. I think it's a fairly simple fix to add HOT_WATER in but it would be handy if you could get the JSON result of getZoneState, so I can test. Thanks

MrAlfabet commented 1 year ago

Request URL: https://my.tado.com/api/v2/homes/111111/zones/0/state?ngsw-bypass=true

This is the only request that is send right after the overlay request. Is this what you're looking for? The only payload here is ngsw-bypass=true

MrAlfabet commented 1 year ago

And this is the response for that request: {"tadoMode":"HOME","geolocationOverride":false,"geolocationOverrideDisableTime":null,"preparation":null,"setting":{"type":"HOT_WATER","power":"ON","temperature":{"celsius":41.00,"fahrenheit":105.80}},"overlayType":"MANUAL","overlay":{"type":"MANUAL","setting":{"type":"HOT_WATER","power":"ON","temperature":{"celsius":41.00,"fahrenheit":105.80}},"termination":{"type":"TIMER","typeSkillBasedApp":"TIMER","durationInSeconds":3574,"expiry":"2022-12-23T00:38:34Z","remainingTimeInSeconds":3573,"projectedExpiry":"2022-12-23T00:38:34Z"}},"openWindow":null,"nextScheduleChange":null,"nextTimeBlock":null,"link":{"state":"ONLINE"},"activityDataPoints":{},"sensorDataPoints":{}}

mattdavis90 commented 1 year ago

Awesome. I think that's everything I need to work out how to add hot water into the library. Fingers crossed I get some time now 🙂

MrAlfabet commented 1 year ago

Note that this state request is sent AFTER the overlay request (at least, that's how my google chrome shows it)

mattdavis90 commented 1 year ago

Having a read of the code in the library I think the fix is adding HOT_WATER to that line. If that is the case though, then turning off should work because that doesn't require a temperature to be set. I'll push a new version shortly.

mattdavis90 commented 1 year ago

I've updated that line and pushed to the library. Could you pull this into your nodered and check that it is working before I push the library to npm and update the nodered node? I'm unable to test locally because I don't have a hot water device. Thanks

mattdavis90 commented 1 year ago

I've just pushed to the master on this repo as well with some fixes that should help with setting overlays when using the updated client. If you switch nodered over to using master then you should get the hot water feature plus typescript library with working overlays. I think I've finished testing it but it would be great if you could also - this should fix the original issues.

MrAlfabet commented 1 year ago

Could you give me some guidance? I installed node-red as a Home Assistant add-on (docker container under the hood) and I usually install/update nodes through the node-red webUI

mattdavis90 commented 1 year ago

If you can do an exec in to the nodered container, then I think if you cd /data then npm i git://github.com/mattdavis90/node-red-contrib-tado-client.git#master then I'm hoping that will pull in the master branch of this repo into your nodered - the directory may not be /data, you're looking for the directory with the NodeRed node_modules and package.json. Hope that helps, thanks.

Edit: You'll likely need to restart NodeRed after this so the files get reloaded

mattdavis90 commented 1 year ago

Testing this on my own installation and running for 2 weeks now it all seems to be working for me. I don't really make use of overlays but I have tested some out. If you're able to test it would be great because I've added quite a few features over Christmas that I've not been able to release yet. Thanks

MrAlfabet commented 1 year ago

I'll be trying it right now!

MrAlfabet commented 1 year ago

Everything except turning the hot water off seems to work. Still the same AxiosError 422.

MrAlfabet commented 1 year ago

Oh and the folder in the Home Assistant add-on node-red docker container is /config/node-red

MrAlfabet commented 1 year ago

And I also have no option to set the duration (or until manual change) for the 'hot water off' overlay

mattdavis90 commented 1 year ago

How strange the turning off doesn't work. Are you able to manually overlay turning the hot water on?

You should be able to set a duration by setting the termination mode to "timer based" as below.

image

mattdavis90 commented 1 year ago

@MrAlfabet Are you happy that everything was fixed and that I can close this ticket now? Thanks