PJCzx / homebridge-thermostat

Supports thermostat devices on HomeBridge Platform
Apache License 2.0
34 stars 71 forks source link

Mode #14

Closed paulkoene closed 7 years ago

paulkoene commented 7 years ago

First of all great plugin, but I have a few things I would like to have included :)

Homekit has the option to set the mode to Off, Heating, Cooling or Automatic. It would be great if I could set this through homebridge-thermostat. This way I can make my script decide what to do with the targetTemperature. This also has the added benefit of the targetTemperature being displayed in the status text within homekit.

PJCzx commented 7 years ago

You should set the TargetState and your system will set the state depending of the temparature: eg

TargetState > AUTO will give State > Heating or Cooling depending of the temperature.

Sure you can set target state Heating or cooling.

Let me know if not clear.

paulkoene commented 7 years ago

I would like to set the targetstate with the homekit widget. How will the plugin pass the targetstate to the script on the webserver (something like http://host/targetstate/auto)

PJCzx commented 7 years ago

Using the iOS Home app will allow you to chose different values that will invoque the 'setTargetHeatingCoolingState()' function. This function handle OFF/HEAT/AUTO/COOL according to Apple specifications.

Depending of the value, the plugin will send an HTTP request to apiRoute + action where action is defined bu this piece of code:

            switch(value) {
                case Characteristic.TargetHeatingCoolingState.OFF:
                action = "/off";
                break;

                case Characteristic.TargetHeatingCoolingState.HEAT:
                action = "/comfort";
                break;

                case Characteristic.TargetHeatingCoolingState.AUTO:
                action = "/auto";
                break;

                case Characteristic.TargetHeatingCoolingState.COOL:
                action = "/no-frost";
                break;

                default:
                action = "/no-frost";
                this.log("Not handled case:", value);
                break;
            }

In your case, this will call something like http://host/auto. Please have a quick look to the implementation the code is supposed to be explicit enough. If not, I'll answer ;)

Best,

paulkoene commented 7 years ago

Cheers! I see the targetstate coming in now. For some reason it is not handling the returned information from the http://host/status. homekit "forgets" the targetstate after refreshing. Am I doing something wrong? The output is as follows...

{ "targetState": "HEAT", "targetStateCode": 1, "targetTemperature": 21, "targetHeatingCoolingState": 3, "currentHeatingCoolingState": 0, "temperature": 22.3, "humidity": 42.1, "pressure": 104395 }

PJCzx commented 7 years ago

currentHeatingCoolingState can have only 3 values : HEAT/COOL/OFF. iOS Home app will call the getCurrentHeatingCoolingState and will display the result with the response of /status.

You want the system to handle the temperature automatically and the system chose to stay OFF. This is the case when the targetTemperature > currentTemperature but it's seems not to be the case.

Every single time you will open the iOS Home app, it will ask again to /status.

Please check the logic from the thermostat side cause I would expect the currentHeatingCoolingState to be heating (1) when the targetTemperature > currentTemperature.

Best,

paulkoene commented 7 years ago

In my view the logic is as follows. With homekit (or by other means) you set targetHeatingCoolingState to off, cool, heat or auto. You also set a targetTemperature. Depending on the targetHeatingCoolingState and the targetTemperature the currentHeatingCoolingState will be set. In this case the mode is auto with a target of 21 degrees. As the current temperature is 22.3 degrees the heating stays off. Theoretically it should actually go to a currentHeatingCoolingState of cooling, but I don't have an airconditioner hooked up :)

paulkoene commented 7 years ago

The problem is that the targetHeatingCoolingState is not getting back to homekit so it switches from auto to off after a refresh from http://host/status

PJCzx commented 7 years ago

Thx for this feedback, 2 things >

  1. For I don't know what reason, 2 lines were uncommented leading to loop call.
  2. The API/status targetStateCode need to be updated to targetHeatingCoolingState. You can update this in you /status feedback but I just pushed a workaround for it to work without changes from API side.

This will be better now ;)

PJCzx commented 7 years ago

PS: I updated npm if reeded :)

PJCzx commented 7 years ago

I may update currentHumidity and targetHumidity in the same occasion, but not now (unfortunatelly not enought time to dedicate)

paulkoene commented 7 years ago

Cool, it works now! Thanks!

PJCzx commented 7 years ago

I updated the code and the readme for an API the closest possible from HAP convention. this clarify some situations.

BTW, did you saw my repo Acova? It's an heating system brand I handle with a couple of electronic component. Maybe the code base could help you? At least the API (which do more than needed...)

Best ;)

paulkoene commented 7 years ago

Looks nice. You are doing things there that I am going to let homekits automation handle. My heating is a simple one that only understands on or off which I am steering with a relay based on the settings I am making with your plugin. The relay is interfaced with an Onion Omega + power dock + relay expansion which is similar to a raspberry pi solution. The temperature is coming from a wireless riot air sensor.

paulkoene commented 7 years ago

The heating system is actually due for a replacement so I will in time replace it with one that understands opentherm so I can control it better :)