ztalbot2000 / homebridge-cmd4

CMD4 Plugin for Homebridge - Supports ~All Accessory Types & now all Characteristics too
Apache License 2.0
145 stars 14 forks source link

[Support] how to change the properties of `currentTemperature` and `targetTemperature` of `Thermostat` device. #141

Closed uswong closed 5 months ago

uswong commented 6 months ago

Change the properties of currentTemperature and targetTemperature of Thermostat device.

Describe Your Problem:

The AdvantageAir thermostat has a temperature range of 16-32 degrees and a step of 1 degree so I would also like to change the min, max and step of my Homekit `Thermostat' device to have the same range with a step of 1.

I tested using the "props" as per your example (please see the config below) but it did not work for me.

There was no error from CMD4. I did remove the cache before I restart Homebridge. The Thermostat on Homekit still remains to have a temperature range of 10-38 degrees with a step of 0.5 degrees.

Paste of Logs:

[13/01/2024, 10:22:47 am] [Cmd4] Cmd4Platform didFinishLaunching
[13/01/2024, 10:22:47 am] [Cmd4] Adding new platformAccessory: Aircon
[13/01/2024, 10:22:47 am] [Cmd4] Configuring platformAccessory: Aircon
[13/01/2024, 10:22:50 am] [Cmd4] Creating linked accessories for: Aircon
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Aircon Fan
[13/01/2024, 10:22:50 am] [Cmd4] Creating linked accessories for: Aircon Fan
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Aircon Timer
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Aircon Fan Timer
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Aircon Cool Timer
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Aircon Heat Timer
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Family Zone
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Games Zone
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Meals Zone
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Dining Zone
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Studio Zone
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Master Zone
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Bed 2 Zone
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Bed 3 Zone
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Bed 4 Zone
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Master Fan Timer
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Bed 4 Light Dimmer
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Bed 4 Light Timer
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Master Light Dimmer
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Master Light Timer
[13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Bed 4 Fan Timer

Cmd4 Config:

        {
            "type": "Thermostat",
            "displayName": "Aircon",
            "currentHeatingCoolingState": "OFF",
            "targetHeatingCoolingState": "OFF",
            "currentTemperature": 24,
            "targetTemperature": 24,
            "temperatureDisplayUnits": "CELSIUS",
            "name": "Aircon",
            "manufacturer": "Advantage Air Australia",
            "model": "e-zone",
            "serialNumber": "PIC7GS10-A",
            "queue": "AAA",
            "polling": [
                {
                    "characteristic": "currentHeatingCoolingState"
                },
                {
                    "characteristic": "targetHeatingCoolingState"
                },
                {
                    "characteristic": "currentTemperature"
                },
                {
                    "characteristic": "targetTemperature"
                }
            ],
            "props": [
                {
                    "currentTemperature": {
                        "maxValue": 32,
                        "minValue": 16,
                        "minStep": 1
                    }
                },
                {
                    "targetTemperature": {
                        "maxValue": 32,
                        "minValue": 16,
                        "minStep": 1
                    }
                }
            ],
            "state_cmd": "'/var/lib/homebridge/node_modules/homebridge-cmd4-advantageair/AdvAir.sh'",
            "state_cmd_suffix": "${AAIP}"
        },
            "linkedTypes": [
                {
                    "type": "Fan",
                    "displayName": "Aircon FanSpeed",
                    "on": "TRUE",
                    "rotationSpeed": 25,
                    "name": "Aircon FanSpeed",
                    "manufacturer": "Advantage Air Australia",
                    "model": "e-zone",
                    "serialNumber": "PIC7GS10-A",
                    "queue": "AAA",
                    "polling": [
                        {
                            "characteristic": "on"
                        },
                        {
                            "characteristic": "rotationSpeed"
                        }
                    ],
                    "state_cmd": "'/var/lib/homebridge/node_modules/homebridge-cmd4-advantageair/AdvAir.sh'",
                    "state_cmd_suffix": "${AAIP} fanSpeed"
                }
            ]
        },

Screenshots:

Environment:

uswong commented 6 months ago

Hey John,

I did some more testing and I have some success.

I changed the config a bit by removing the square brackets:

        "props": {
             "currentTemperature": {
                 "maxValue": 32,
                 "minValue": 16,
                 "minStep": 1
             },
             "targetTemperature": {
                 "maxValue": 32,
                 "minValue": 16,
                 "minStep": 1
             }
         }.

it still did not work, however when I removed the curly brackets { on line 819 and } on line 824 of Cmd4Accessory.js module, it worked!

When you do have a moment, I would be most grateful if you could take a look at this, perhaps the curly brackets on lines 819 and 824 should be removed.

ztalbot2000 commented 6 months ago

Hi Sing,

If your remember a year ago I was doing some changes for you and had discovered this issue. It was delaying the release of something else you wanted. I spent a couple of months trying to fix it. The issue at the time was with a GarageDoorOpener going from Open to closing to closed. The same thing you are seeing now, but with a thermometer. I finally gave up and did the submission anyway. From what I figured at the time it was either a HomeKit or HAP problem. Homebridge says you are to call the updateValue API, but it does not work. I found HomeKit only accepts one response of updateValue or setValue to its Set command. The accessory would go unresponsive sending HomeKit an unsolicited updateValue. I can't guarantee I will try any time soon to see if this is still the case. I did take Cmd4 out of the picture creating a dummy plugin that proved it, but remember that Apple really does not support Homebridge. I had seen HAP send the response to HomeKit, Apple is then the culprit if it does not update.

Ttyl, John

On Fri, Jan 12, 2024 at 10:18 PM Ung Sing Wong @.***> wrote:

Change the properties of currentTemperature and targetTemperature of Thermostat device.

Describe Your Problem:

The AdvantageAir thermostat has a temperature range of 16-32 degrees and a step of 1 degree so I would also like to change the min, max and step of my Homekit `Thermostat' device to have the same range with a step of 1.

I tested using the "props" as per your example (please see the config below) but it did not work for me.

There was no error from CMD4. I did remove the cache before I restart Homebridge. The Thermostat on Homekit still remains to have a temperature range of 10-38 degrees with a step of 0.5 degrees.

Paste of Logs:

[13/01/2024, 10:22:47 am] [Cmd4] Cmd4Platform didFinishLaunching [13/01/2024, 10:22:47 am] [Cmd4] Adding new platformAccessory: Aircon [13/01/2024, 10:22:47 am] [Cmd4] Configuring platformAccessory: Aircon [13/01/2024, 10:22:50 am] [Cmd4] Creating linked accessories for: Aircon [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Aircon Fan [13/01/2024, 10:22:50 am] [Cmd4] Creating linked accessories for: Aircon Fan [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Aircon Timer [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Aircon Fan Timer [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Aircon Cool Timer [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Aircon Heat Timer [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Family Zone [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Games Zone [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Meals Zone [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Dining Zone [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Studio Zone [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Master Zone [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Bed 2 Zone [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Bed 3 Zone [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Bed 4 Zone [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Master Fan Timer [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Bed 4 Light Dimmer [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Bed 4 Light Timer [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Master Light Dimmer [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Master Light Timer [13/01/2024, 10:22:50 am] [Cmd4] Restoring existing accessory from cache: Bed 4 Fan Timer

Cmd4 Config:

    {
        "type": "Thermostat",
        "displayName": "Aircon",
        "currentHeatingCoolingState": "OFF",
        "targetHeatingCoolingState": "OFF",
        "currentTemperature": 24,
        "targetTemperature": 24,
        "temperatureDisplayUnits": "CELSIUS",
        "name": "Aircon",
        "manufacturer": "Advantage Air Australia",
        "model": "e-zone",
        "serialNumber": "PIC7GS10-A",
        "queue": "AAA",
        "polling": [
            {
                "characteristic": "currentHeatingCoolingState"
            },
            {
                "characteristic": "targetHeatingCoolingState"
            },
            {
                "characteristic": "currentTemperature"
            },
            {
                "characteristic": "targetTemperature"
            }
        ],
        "props": [
            {
                "currentTemperature": {
                    "maxValue": 32,
                    "minValue": 16,
                    "minStep": 1
                }
            },
            {
                "targetTemperature": {
                    "maxValue": 32,
                    "minValue": 16,
                    "minStep": 1
                }
            }
        ],
        "state_cmd": "'/var/lib/homebridge/node_modules/homebridge-cmd4-advantageair/AdvAir.sh'",
        "state_cmd_suffix": "${AAIP}"
    },
        "linkedTypes": [
            {
                "type": "Fan",
                "displayName": "Aircon FanSpeed",
                "on": "TRUE",
                "rotationSpeed": 25,
                "name": "Aircon FanSpeed",
                "manufacturer": "Advantage Air Australia",
                "model": "e-zone",
                "serialNumber": "PIC7GS10-A",
                "queue": "AAA",
                "polling": [
                    {
                        "characteristic": "on"
                    },
                    {
                        "characteristic": "rotationSpeed"
                    }
                ],
                "state_cmd": "'/var/lib/homebridge/node_modules/homebridge-cmd4-advantageair/AdvAir.sh'",
                "state_cmd_suffix": "${AAIP} fanSpeed"
            }
        ]
    },

Screenshots:

Environment:

  • Node.js Version: v18.19.0
  • NPM Version: 10.2.3
  • Homebridge Version: 1.7.0
  • homebridge-cmd4 Version: v7.0.2
  • Operating System: Raspbian / Ubuntu / Debian / Windows / macOS / Docker / other Raspbian
  • Process Supervisor: Systemd / init.d / pm2 / launchctl / Docker / hb-service / other / none hb-service

— Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/141, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCXYIG44MK2VDP4BOOCDYOH4IFAVCNFSM6AAAAABBY767OWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA4DAMBRHAZDGOA . You are receiving this because you were assigned.Message ID: @.***>

uswong commented 6 months ago

Hi John,

Yes, I did remember you were trying to figure out what was wrong with GarageDoorOpener. I can try to test it out in my end if you can send me the config you use to test it. As far as my experience with GarageDoorOpener, it is all working very well. It goes from Open to Closing to Closed nicely and goes from Closed to Opening to Open nicely too. Videos of that in action are attached here.

https://github.com/ztalbot2000/homebridge-cmd4/assets/96530237/0971818f-ff31-4657-814d-d234c7300b9b

https://github.com/ztalbot2000/homebridge-cmd4/assets/96530237/7998e708-3760-4c41-8381-b1046b58d13f

This Thermostat issue is somewhat different, it is using the setProps API. The properties variable props parsed from the config is a JSON object, e.g. { maxValue: 32, minValue: 16, minStep: 1 } . The existing code (see enclosed screenshot below) for setProps in Cmd4Accesssory has this JSON object enclosed within a set of curly brackets (line 819 and line 824) and that extra curly brackets seem to be the culprit.

image

When I removed the extra curly brackets in line 819 nd 824. it worked brilliantly. The code ended up as follow:

 accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].
        characteristic )
 .setProps( 
    props
 );

I would like to tag @mitch7391 here to allow him to follow our discussion on this Thermostat issue.

ztalbot2000 commented 6 months ago

Hi Sing,

Ok, so not what I understood from the first discussion. I added setProps way early on in the Cmd4 development when the HAP properties for temperature would not allow an obvious range. I don't know if anyone has used it since. I can check out if the API has changed, but not today. Today is the last day for a while that it will not be to far below zero outside. I'm in Canada. brrrrr. The spindle on my CNC in my shed will not rotate if it's too cold. Today may be the last kind of warm day to use my CNC. I've been busy working on designing/ building a 3D printer, you can check it out on my GitHub page. I will keep you notified on any setProps updates I have.

Ttyl, John

On Sun, Jan 14, 2024 at 5:09 AM Ung Sing Wong @.***> wrote:

Hi John,

Yes, I did remember you were trying to figure out what was wrong with GarageDoorOpener. I can try to test it out in my end if you can send me the config you use to test it. As far as my experience with GarageDoorOpener, it is all working very well. It goes from Open to Closing to Closed nicely and goes from Closed to Opening to Open nicely too. Videos of that in action are attached here.

https://github.com/ztalbot2000/homebridge-cmd4/assets/96530237/0971818f-ff31-4657-814d-d234c7300b9b

https://github.com/ztalbot2000/homebridge-cmd4/assets/96530237/7998e708-3760-4c41-8381-b1046b58d13f

This Thermostat issue is somewhat different, it is using the setProps API. The properties variable props parsed from the config is a JSON object, e.g. { maxValue: 32, minValue: 16, minStep: 1 } . The existing code (see enclosed screenshot below) for setProps in Cmd4Accesssory has this JSON object enclosed within a set of curly brackets (line 819 and line 824) and that extra curly brackets seem to be the culprit.

image.png (view on web) https://github.com/ztalbot2000/homebridge-cmd4/assets/96530237/2d356093-5c47-48fb-af52-d19c21356cef

When I removed the extra curly brackets in line 819 nd 824. it worked brilliantly. The code ended up as follow:

accessory.service.getCharacteristic( CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ]. characteristic ) .setProps( props );

I would like to tag @mitch7391 https://github.com/mitch7391 here to allow him to follow our discussion on this Thermostat issue.

— Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/141#issuecomment-1890906853, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX6FTJAWY3RZGGOWEBTYOOVFPAVCNFSM6AAAAABBY767OWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJQHEYDMOBVGM . You are receiving this because you were assigned.Message ID: @.***>

uswong commented 6 months ago

Hey John,

Your My100 project really looks quite an undertaking! All the best to it!

No real rush for the setProps fix. It is just for some refinement on the functionality of Mitch's AdvantageAir plugin especially for the Thermostat accessory to change the default minStep of 0.5 degrees to 1 degree as per AdvantageAir design. An user in my household has actually asked me whether I can change the step to 1 degree few days ago.

setProps certainly will be very useful for other applications. I can already envisage using it for % vent open which has a step of 5% as per AdvantageAir design.

Best regards, Ung Sing

ztalbot2000 commented 5 months ago

Hi Sing,

I have only spent a couple of hours on this so far. I'm trying to create a unit test that proves set props survive over a restart. I have a good feeling it will not matter any way and here is why. Homebridge uses HAP-nodejs to communicate with HomeKit. HAP-nodejs was originally reverse engineered and actually got a cease and desist letter on showing how they did it. The HomeKit API was then later published for Apple platforms. HomeKit actually owns the spec to each characteristic. So if there GUI says the max value of the temperature is 127 Fahrenheit then that is what they go by. The same goes for other characteristic values. HomeKit does not query HAP for these values. HAP allows you to set these parameters if by chance you have your own GUI. I'm still want to prove if the changed characteristics are still there with a reproducible unit test, but it's not an easy one. I just would not count on the effect you were hoping for. I'l let you know what I find out.

Ttyl, John

On Mon, Jan 15, 2024 at 8:28 AM Ung Sing Wong @.***> wrote:

Hey John,

Your My100 project really looks quite an undertaking! All the best to it!

No real rush for the setProps fix. It is just for some refinement on the functionality of Mitch's AdvantageAir plugin especially for the Thermostat accessory to change the default minStep of 0.5 degrees to 1 degree as per AdvantageAir design. An user in my household has actually asked me whether I can change the step to 1 degree few days ago.

setProps certainly will be very useful for other applications. I can already envisage using it for % vent open which has a step of 5% as per AdvantageAir design.

Best regards, Ung Sing

— Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/141#issuecomment-1892177639, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX7WYBOKLDOXWIOAI5TYOUVGXAVCNFSM6AAAAABBY767OWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJSGE3TONRTHE . You are receiving this because you were assigned.Message ID: @.***>

uswong commented 5 months ago

Hey John, I tested the setProps and they all survived over a restart. It seems to have been working very well for me with the edited version of Cmd4Accessory.

Best regards, Ung Sing

ztalbot2000 commented 5 months ago

Thanks Sing,

I understand that the extra brackets are creating another object, but

the variable props already is an object. That is why your solution works. I'll see about putting your fix in tomorrow.

Ttyl, John

On Thu, Jan 25, 2024 at 6:53 AM Ung Sing Wong @.***> wrote:

Hey John, I tested the setProps and they all survived over a restart. It seems to have been working very well for me with the edited version of Cmd4Accessory.

Best regards, Ung Sing

— Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/141#issuecomment-1910027777, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX3Q4IMDASDWFS3W7STYQJBTJAVCNFSM6AAAAABBY767OWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJQGAZDONZXG4 . You are receiving this because you were assigned.Message ID: @.***>

ztalbot2000 commented 5 months ago

Hi Sing,

I think there is another issue. When you define props in your config.json, it should not be an array. I uncommented out the debug line above the code you wanted me to change to verify this. The config.json should read: "props": { "currentTemperature": { "maxValue": 32, "minValue": 16, "minStep": 1 }, "targetTemperature": { "maxValue": 32, "minValue": 16, "minStep": 1 } } I have not found any Cmd4 documentation that indicates that it should be an array. Certainly there should be some indicating that it should not be. I'm currently writing test cases to prove all of this and so it does not happen again.

ttyl, John

On Fri, Jan 26, 2024 at 7:26 PM John Talbot @.***> wrote:

Thanks Sing,

I understand that the extra brackets are creating another object, but

the variable props already is an object. That is why your solution works. I'll see about putting your fix in tomorrow.

Ttyl, John

On Thu, Jan 25, 2024 at 6:53 AM Ung Sing Wong @.***> wrote:

Hey John, I tested the setProps and they all survived over a restart. It seems to have been working very well for me with the edited version of Cmd4Accessory.

Best regards, Ung Sing

— Reply to this email directly, view it on GitHub https://github.com/ztalbot2000/homebridge-cmd4/issues/141#issuecomment-1910027777, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSBCX3Q4IMDASDWFS3W7STYQJBTJAVCNFSM6AAAAABBY767OWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJQGAZDONZXG4 . You are receiving this because you were assigned.Message ID: @.***>

ztalbot2000 commented 5 months ago

Fixed with v7.0.3

uswong commented 5 months ago

Thanks John, much appreciated.

Yes, the setProps config should not be an array which I did comment earlier on the removal of the square brackets in the config https://github.com/ztalbot2000/homebridge-cmd4/issues/141#issuecomment-1890482369.