bisand / node-red-contrib-panasonic-comfort-cloud

MIT License
6 stars 4 forks source link

Setting temperature #5

Closed smadds closed 2 years ago

smadds commented 2 years ago

Hi. Thanks for creating this - looks like a great start. Connected to our Panasonic aircon straight away.

Do you have any plans to add the ability to turn it on/off and set the temperature?

It would then be REALLY useful.....

bisand commented 2 years ago

Hi. Thanks for showing interest in this module. I have no immediate plans for this feature, but since you are asking, I will take a look at it and do some research into the topic. I cannot guarantee a quick resolution, but will try to move it up on my list.

If you are familiar with node.js development, feel free to submit a pull request.

Regards, André

smadds commented 2 years ago

Thanks, André. I wish I was a programmer, but am not - some web design and sql is about my limit.

Happy to look through protocols though - where you able to find it documented, or did you have to wireshark it?

Regards

Simon

On Tue, 30 Nov 2021 at 18:27, André Biseth @.***> wrote:

Hi. Thanks for showing interest in this module. I have no immediate plans for this feature, but since you are asking, I will take a look at it and do some research into the topic. I cannot guarantee a quick resolution, but will try to move it up on my list.

If you are familiar with node.js development, feel free to submit a pull request.

Regards, André

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bisand/node-red-contrib-panasonic-comfort-cloud/issues/5#issuecomment-982903584, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIEEXTS3TOX2AMTQ2ZENJ3UOUJRZANCNFSM5JB3DN7Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

smadds commented 2 years ago

Looks like marc2016 has already created an npm node that includes setting would this help?

https://github.com/marc2016/panasonic-comfort-cloud-client

bisand commented 2 years ago

You are right about that. That is exactly the module I'm using in "node-red-contrib-panasonic-comfort-cloud". I will certainly try to find some time to implement setting of values. Feel free to suggest features you want me to prioritize first.

smadds commented 2 years ago

I think if you could create a 3rd node-red node that is the command one with the 8 functions Marc has implemented (e.g. the taking command as the topic and the value as the payload) that would be ideal. I see he has also created the enums for 'Auto', 'High' etc.

If you wanted to do them 1 at a time the most important it turning it on & off ;)

bisand commented 2 years ago

I have now published a new version of "node-red-contrib-panasonic-comfort-cloud" (v1.0.1). This includes a command node that takes a JSON object for payload and sets the applicable config values for the selected device. I have also updated the readme to contain some kind of documentation on how to use the new node. It would be nice if you have time to take it for a spin and let me know what you think. I have tested it on my heat pump and it works for me. Don't hesitate to submit bugs or improvements, for nodes and/or documentation.

Good luck!

smadds commented 2 years ago

That's amazing! Thank you so much for putting some time into this.

It's not working for me at the moment, but I'm sure we're close!

If I store account credentials, they work for the previous 2 nodes, but the new command one does not seem to be using them properly - I get this if I hook a debug node onto its output: image

Another (much smaller) thing is your naming of the Device ID configuration field - it's the same on the Device status and the command nodes. Maybe rename the label to Device ID or GUID? image

Thanks

bisand commented 2 years ago

I have done some more testing, and it seems to be working on my setup.. Could it be a faulty payload? Can you please provide the JSON object you injected in the payload. It should be in JSON format, not text. Use the JSON example below as a starting point. The Device ID could be set in either the JSON object or the node. I have also changed the label to Device ID

{
"deviceId": "CS-XXXXXXX+1234567890",
"operate": "On",
"operationMode": "Heat",
"ecoMode": "Auto",
"temperatureSet": 22,
"airSwingUD": "Mid",
"airSwingLR": "Mid",
"fanAutoMode": "AirSwingAuto",
"fanSpeed": "Auto"
}

By the way, I am testing on Node-Red v.2.1.4

smadds commented 2 years ago

Strange. I was just sending the GUID and operate JSON, using an inject node set to JSON payload. { "deviceId": "CS-XXXXXXX+1234567890", "operate": "On", }

I also tried adding the Device ID at the command node, but this did not work either.

I have just tried injecting the same packet that you did (with the guid updated to that of my A/C unit) but I'm still getting the 'tried 3 times' error.

When I look at the device status the responses are mainly starting with underscores. Is this the same for you?

07/12/2021, 23:20:10node: 74714f31.9e4aa msg : Object object _msgid: "302963a4.8d04ec" topic: "" payload: object _operate: 0 _operationMode: 3 _temperatureSet: 22 _fanSpeed: 0 _fanAutoMode: 1 _airSwingLR: 2 _airSwingUD: 2 _ecoMode: 0 _actualNanoe: 1 _ecoNavi: 0 _nanoe: 2 _iAuto: 0 _airDirection: 1 _ecoFunctionData: 0 _insideTemperature: 22 _outTemperature: 5 lastSettingMode: 0 airQuality: 0

I'm using Node-Red v1.0.2 on a RPi - maybe that's the issue?

bisand commented 2 years ago

It seemed to be a problem with the payload validation. Earlier versions of Node-Red was a little bit more picky when it comes accepting payloads in the flows, so the payload you sent contained an invalid JSON string (see comma after "on",). This made the JSON parsing to fail on your version.

{
    "deviceId": "CS-XXXXXXX+1234567890",
    "operate": "On", <- Error here. No comma after last element.
}

I have improved that logic and tested in on Node-Red 1.0.2, and it seems to be running OK. I have also improved the error handling, so the error messages should be a little bit better now.

The underscores just indicates that the returned object is using private variables. That should be OK.

smadds commented 2 years ago

Thanks for the update. I've spent quite some time today trying to get the new version installed - with not much success.

I have switched to another instance of node-red - version 2.1.3 running on a RPi. The nodes install fine from Manage Palette, but when I configure and deploy the Command node disappears - missing from the flows tab and the library.

image

Any ideas?

smadds commented 2 years ago

image

bisand commented 2 years ago

I suspect the new problems you are experiencing is probably because I used optional chaining (?.) in an expression and that was not supported until Node.js until version 14, and I suspect your installation is using an earlier version. This expression has now been replaced by a more supported one. My bad! Try to install the new version (1.0.4) and see if it works now.

smadds commented 2 years ago

Hi André. Firstly, thanks again for putting time into this - I know how difficult this can be - especially if it is working for you!

The nodes install now and deploy fine, but I'm still getting the connection issue - just on the Command node:

Screenshot 2021-12-09 102418 I've checked and the command is of course not getting through. I'm using your example json - just with the GUID line removed and with the Device ID put into the node configuration. It works on the Device status node.

There is 1 other thing I have noticed and don't understand. If I connect a debug node to the Device node with the debug set to show msg.payload it indicates an object, but is unable to expand it: Screenshot 2021-12-09 102144

If I configure the debug node to show full msg object it works fine: Screenshot 2021-12-09 102252

Using msg.payload on the Groups status node works fine too. Not a big deal, but there must be something different in the Device Status node.

I'm using node-red within Docker (IOTStack build for RPi). Here is a dump of the log:

9 Dec 10:22:07 - [info] [mqtt-broker:Local] Connected to broker: mqtt://192.168.24.250:1883

9 Dec 10:22:14 - [info] [pcc-device:896b8e0501d6f750] true

9 Dec 10:23:08 - [info] [pcc-device:896b8e0501d6f750] true

9 Dec 10:23:28 - [info] [pcc-command:5f0e30c4443206f6] [object Object]

9 Dec 10:23:30 - [info] [pcc-command:5f0e30c4443206f6] 1

9 Dec 10:23:30 - [info] [pcc-command:5f0e30c4443206f6] 3

9 Dec 10:23:30 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:23:30 - [info] [pcc-command:5f0e30c4443206f6] 22

9 Dec 10:23:30 - [info] [pcc-command:5f0e30c4443206f6] 2

9 Dec 10:23:30 - [info] [pcc-command:5f0e30c4443206f6] 2

9 Dec 10:23:30 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:23:30 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:23:34 - [info] [pcc-command:5f0e30c4443206f6] Obtained a new access token.

9 Dec 10:23:34 - [info] [pcc-command:5f0e30c4443206f6] [object Object]

9 Dec 10:23:36 - [info] [pcc-command:5f0e30c4443206f6] 1

9 Dec 10:23:36 - [info] [pcc-command:5f0e30c4443206f6] 3

9 Dec 10:23:36 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:23:36 - [info] [pcc-command:5f0e30c4443206f6] 22

9 Dec 10:23:36 - [info] [pcc-command:5f0e30c4443206f6] 2

9 Dec 10:23:36 - [info] [pcc-command:5f0e30c4443206f6] 2

9 Dec 10:23:36 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:23:36 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:23:40 - [info] [pcc-device:896b8e0501d6f750] true

9 Dec 10:23:40 - [info] [pcc-command:5f0e30c4443206f6] Obtained a new access token.

9 Dec 10:23:40 - [info] [pcc-command:5f0e30c4443206f6] [object Object]

9 Dec 10:23:42 - [info] [pcc-command:5f0e30c4443206f6] 1

9 Dec 10:23:42 - [info] [pcc-command:5f0e30c4443206f6] 3

9 Dec 10:23:42 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:23:42 - [info] [pcc-command:5f0e30c4443206f6] 22

9 Dec 10:23:42 - [info] [pcc-command:5f0e30c4443206f6] 2

9 Dec 10:23:42 - [info] [pcc-command:5f0e30c4443206f6] 2

9 Dec 10:23:42 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:23:42 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:23:45 - [info] [pcc-command:5f0e30c4443206f6] Obtained a new access token.

9 Dec 10:23:45 - [error] [pcc-command:5f0e30c4443206f6] Error: Reached max retry count 3. Please check your credentials, or read the logs for more information.

9 Dec 10:24:34 - [info] [pcc-device:896b8e0501d6f750] true

9 Dec 10:25:21 - [info] [pcc-command:5f0e30c4443206f6] [object Object]

9 Dec 10:25:22 - [info] [pcc-command:5f0e30c4443206f6] 1

9 Dec 10:25:22 - [info] [pcc-command:5f0e30c4443206f6] 3

9 Dec 10:25:22 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:25:22 - [info] [pcc-command:5f0e30c4443206f6] 22

9 Dec 10:25:22 - [info] [pcc-command:5f0e30c4443206f6] 2

9 Dec 10:25:22 - [info] [pcc-command:5f0e30c4443206f6] 2

9 Dec 10:25:22 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:25:22 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:25:26 - [info] [pcc-command:5f0e30c4443206f6] Obtained a new access token.

9 Dec 10:25:26 - [info] [pcc-command:5f0e30c4443206f6] [object Object]

9 Dec 10:25:28 - [info] [pcc-command:5f0e30c4443206f6] 1

9 Dec 10:25:28 - [info] [pcc-command:5f0e30c4443206f6] 3

9 Dec 10:25:28 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:25:28 - [info] [pcc-command:5f0e30c4443206f6] 22

9 Dec 10:25:28 - [info] [pcc-command:5f0e30c4443206f6] 2

9 Dec 10:25:28 - [info] [pcc-command:5f0e30c4443206f6] 2

9 Dec 10:25:28 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:25:28 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:25:32 - [info] [pcc-command:5f0e30c4443206f6] Obtained a new access token.

9 Dec 10:25:32 - [info] [pcc-command:5f0e30c4443206f6] [object Object]

9 Dec 10:25:34 - [info] [pcc-command:5f0e30c4443206f6] 1

9 Dec 10:25:34 - [info] [pcc-command:5f0e30c4443206f6] 3

9 Dec 10:25:34 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:25:34 - [info] [pcc-command:5f0e30c4443206f6] 22

9 Dec 10:25:34 - [info] [pcc-command:5f0e30c4443206f6] 2

9 Dec 10:25:34 - [info] [pcc-command:5f0e30c4443206f6] 2

9 Dec 10:25:34 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:25:34 - [info] [pcc-command:5f0e30c4443206f6] 0

9 Dec 10:25:39 - [info] [pcc-command:5f0e30c4443206f6] Obtained a new access token.

bisand commented 2 years ago

Ok, I will have to do some research and maybe spin up a RPi with the same environment as you. Could you provide some details on the RPi environment you are using. Could you also try to spin up a Node-Red instance on your own PC with the latest Node.js LTS to see if you get the same result as on the Pi. What version of Node.js is running on the Pi? In the meantime, I will conduct some analyzing and testing on my side to see if I can get the same results as you are getting.

bisand commented 2 years ago

@smadds, I've released a new version with (hopefully) improved error logging. Could you please try to install it to see if you get some more informative error messages? I really appreciate your help and patience on this matter. Thanks! :)

smadds commented 2 years ago

I think we're getting there - and I really appreciate the effort you are putting in.

The Device node now returns a recognisable object in msg.payload

The command node is still returning an error:

image

This happens when I inject the demo json you supply (less the guid, which is in the node) or just a simple single command:

image

Logs:

10 Dec 15:23:22 - [error] [pcc-command:5f0e30c4443206f6] Error: An error ocurred while trying to set device parameter: ServiceError: Adapter internal error, 10 Dec 15:23:17 - [info] [pcc-command:5f0e30c4443206f6] [object Object], 10 Dec 15:23:19 - [info] [pcc-command:5f0e30c4443206f6] 1

smadds commented 2 years ago

These are the versions I am using: NODE_RED_VERSION v2.1.3 NODE_VERSION 12.22.7

bisand commented 2 years ago

Strange! I have also tested with node.js v12.22.7 with success.. Just a thought.. Could it be a firewall or something on your side that could be blocking HTTP POST calls?

Using legacy attach mode for --inspect-brk in npm scripts. We recommend removing --inspect-brk, and using `stopOnEntry` in your launch.json if you need it.
/home/bisand/.nvm/versions/node/v12.22.7/bin/npm run-script debug
10 Dec 20:02:20 - [info] 

Welcome to Node-RED
===================
10 Dec 20:02:20 - [info] Node-RED version: v2.1.4
10 Dec 20:02:20 - [info] Node.js  version: v12.22.7
10 Dec 20:02:20 - [info] Linux 5.13.0-22-generic x64 LE
10 Dec 20:02:20 - [info] Loading palette nodes
10 Dec 20:02:23 - [info] Settings file  : /home/bisand/dev/node-red-contrib-panasonic-comfort-cloud/node_modules/node-red/settings.js
10 Dec 20:02:23 - [info] Context store  : 'default' [module=memory]
10 Dec 20:02:23 - [info] User directory : /home/bisand/dev/node-red-contrib-panasonic-comfort-cloud
10 Dec 20:02:23 - [warn] Projects disabled : editorTheme.projects.enabled=false
10 Dec 20:02:23 - [info] Flows file     : /home/bisand/dev/node-red-contrib-panasonic-comfort-cloud/flows.json
10 Dec 20:02:23 - [warn] 

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
10 Dec 20:02:23 - [info] Server now running at http://127.0.0.1:1880/
10 Dec 20:02:24 - [info] Starting flows
10 Dec 20:02:24 - [info] Started flows
10 Dec 20:02:45 - [info] [pcc-device:81ca689eb01e0f92] 1639162965627
10 Dec 20:02:49 - [info] [pcc-device:81ca689eb01e0f92] Obtained a new access token.
10 Dec 20:02:49 - [info] [pcc-device:81ca689eb01e0f92] 1639162965627
10 Dec 20:02:56 - [info] [pcc-command:8bfe15f39fef0bf6] [object Object]
10 Dec 20:02:59 - [info] [pcc-command:8bfe15f39fef0bf6] 22
10 Dec 20:04:46 - [info] Stopping flows
10 Dec 20:04:46 - [info] Stopped flows
10 Dec 20:04:46 - [info] Starting flows
10 Dec 20:04:46 - [info] Started flows
10 Dec 20:04:48 - [info] [pcc-command:8bfe15f39fef0bf6] [object Object]
10 Dec 20:04:50 - [info] [pcc-command:8bfe15f39fef0bf6] 23
10 Dec 20:05:06 - [info] Stopping flows
10 Dec 20:05:06 - [info] Stopped flows
10 Dec 20:05:06 - [info] Starting flows
10 Dec 20:05:06 - [info] Started flows
10 Dec 20:05:09 - [info] [pcc-command:8bfe15f39fef0bf6] [object Object]
10 Dec 20:06:56 - [info] Stopping flows
10 Dec 20:06:56 - [info] Stopped flows
10 Dec 20:06:56 - [info] Starting flows
10 Dec 20:06:56 - [info] Started flows
10 Dec 20:06:58 - [info] [pcc-command:8bfe15f39fef0bf6] [object Object]
10 Dec 20:07:00 - [info] [pcc-command:8bfe15f39fef0bf6] 1
smadds commented 2 years ago

I don't think its a firewall issue. I'm running the node-red from home on a domestic broadband - and the app works fine on my phone on the same wifi network. I can control the device from the phone app then see the status change from your device node.

I would be interested to see if you can connect to our aircon successfully. Happy to share the Comfort Cloud login privately with you. My Whatsapp is +447785504340

smadds commented 2 years ago

This is my test config:

[
    {
        "id": "adc583949d87ddd2",
        "type": "pcc-groups",
        "z": "a5b7afd8.59ad6",
        "name": "",
        "comfortCloudConfig": "706049c58d4f7494",
        "x": 490,
        "y": 240,
        "wires": [
            [
                "2af5cbb33e0c537a"
            ]
        ]
    },
    {
        "id": "896b8e0501d6f750",
        "type": "pcc-device",
        "z": "a5b7afd8.59ad6",
        "name": "",
        "comfortCloudConfig": "706049c58d4f7494",
        "deviceId": "<<<HIDDEN>>>",
        "x": 490,
        "y": 320,
        "wires": [
            [
                "aa12c69fb92fa59c"
            ]
        ]
    },
    {
        "id": "5f0e30c4443206f6",
        "type": "pcc-command",
        "z": "a5b7afd8.59ad6",
        "name": "",
        "comfortCloudConfig": "706049c58d4f7494",
        "deviceId": "<<<HIDDEN>>>",
        "x": 500,
        "y": 400,
        "wires": [
            [
                "eb40479f8efc1bab"
            ]
        ]
    },
    {
        "id": "4e5343a98f8ba96c",
        "type": "inject",
        "z": "a5b7afd8.59ad6",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 290,
        "y": 240,
        "wires": [
            [
                "adc583949d87ddd2"
            ]
        ]
    },
    {
        "id": "2af5cbb33e0c537a",
        "type": "debug",
        "z": "a5b7afd8.59ad6",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 730,
        "y": 240,
        "wires": []
    },
    {
        "id": "7e62452fda91d936",
        "type": "inject",
        "z": "a5b7afd8.59ad6",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 290,
        "y": 320,
        "wires": [
            [
                "896b8e0501d6f750"
            ]
        ]
    },
    {
        "id": "aa12c69fb92fa59c",
        "type": "debug",
        "z": "a5b7afd8.59ad6",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 730,
        "y": 320,
        "wires": []
    },
    {
        "id": "eb40479f8efc1bab",
        "type": "debug",
        "z": "a5b7afd8.59ad6",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 730,
        "y": 400,
        "wires": []
    },
    {
        "id": "c2f11c7f373258f4",
        "type": "inject",
        "z": "a5b7afd8.59ad6",
        "name": "On",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"operate\":\"On\"}",
        "payloadType": "json",
        "x": 290,
        "y": 400,
        "wires": [
            [
                "5f0e30c4443206f6"
            ]
        ]
    },
    {
        "id": "2eb27b87980b5b92",
        "type": "inject",
        "z": "a5b7afd8.59ad6",
        "name": "Off",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"operate\":\"Off\"}",
        "payloadType": "json",
        "x": 290,
        "y": 460,
        "wires": [
            [
                "5f0e30c4443206f6"
            ]
        ]
    },
    {
        "id": "706049c58d4f7494",
        "type": "pcc-config",
        "name": "CC Panasonic Account"
    }
]
bisand commented 2 years ago

@smadds, Before going down the road of exchanging credentials, I would like you to try one more time. I have switched out the old API client with my own implementation, which also give me a lot more control over the different elements. This client leverages the built in https client in Node.js to communicate with the API.

The command node will now try to do some validation on the provided parameters and only send the parameters you define to the Comfort Cloud API. That will most likely rule out some incompatibility issues (I hope).

It would be nice if you could test it one more time. Make sure to use v1.2.8 or above.

Thanks!

smadds commented 2 years ago

Looks like we have some success here!

I'll do more testing tomorrow, but I am not getting errors and I can see that I'm able to change operate mode between 0 and 1 with my test setup.

Thanks!

bisand commented 2 years ago

Have you had time to do some more testing? Can we close this?

smadds commented 2 years ago

image

I've tried, but looks like the Panasonic server is down at the moment!

smadds commented 2 years ago

Panasonic Comfort Cloud server working again today...

Yes, this looks good now - thanks for all the time you've put into it.

bisand commented 2 years ago

Perfect! Thank you for doing all the testing. Have a wonderful Christmas!