luc-ass / homebridge-evohome

Homebridge plugin for Honeywell Evohome
29 stars 16 forks source link

Set temperature #3

Closed luc-ass closed 8 years ago

luc-ass commented 8 years ago

Hey guys,

until now the plugin can only read temperatures. This is cool but my log-term plan was to make it Change values. I use the node-homebridge to read the vales but am not sure wether it can also write values. If any of you can help extending the functionality I would be so happy ;)

any other ideas?

zizzex commented 8 years ago

Hi, I will try to give a look on how to set temperature but I'm not very familiar with Node. I have installed homebridge and this plugin works fine with my Evohome! :-) Thanks for the work done so far!

luc-ass commented 8 years ago

Sounds great! Let me know if you have any questions! I have already done some work on this but I can't get a legit answer from the server. Doing PUT or POST using "request" results in an invalid answer while the same address with the same parameters (Header, Session) work just fine using curl.

luc-ass commented 8 years ago

Have you gotten anywhere?

zizzex commented 8 years ago

Haven't had the chance to work on it yet, I probably will have time in the next few days. If you could send me the curl would be a good starting point!

luc-ass commented 8 years ago

http://www.automatedhome.co.uk/vbulletin/showthread.php?3863-Decoded-EvoHome-API-access-to-control-remotely

This is a GREAT starting-point :)

zizzex commented 8 years ago

Thanks a lot, I remembered to have found something like this in the past, I will try to see what I can do!

zizzex commented 8 years ago

Hi, I have good news! After a few attempts with Postman, Fiddler and at last with Node, I am now able to set the heat setpoint for a thermostat. Tonight I'll try to put the pieces in place in the plugin and give it a try from Siri. I keep you updated! :)

luc-ass commented 8 years ago

AWESOME! Can't wait to see it :)

Am 06.04.2016 um 18:50 schrieb Andrea notifications@github.com:

Hi, I have good news! After a few attempts with Postman, Fiddler and at last with Node, I am now able to set the heat setpoint for a thermostat. Tonight (in a few hours in Italy), I'll try to put the pieces in place in the plugin and give it a try from Siri. I keep you updated! :)

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub

zizzex commented 8 years ago

It works!!! Since it's a bit late and I am not too confident with branches, forks and pull requests on GitHub (and dont't have authorization to commit) I will start by pasting here the code I have changed.

in index.js

setTargetTemperature: function(value, callback) {
    var that = this;

    that.log("Setting target temperature for", this.name, "to", value + "°");
    var minutes = 10; // The number of minutes the new target temperature will be effective
    // TODO:
    // get configuration from the right place
    // verify that the task did succeed

    that.log("!!!INSERT CREDENTIALS!!!");
    var username = "USERNAME";
    var password = "PASSWORD";
    var appID = "91db1612-73fd-4500-91b2-e63b069b185c";
    evohome.login(username, password, appID).then(function (session) {
                                                  session.setHeatSetpoint(that.serial, value, minutes).then(function (taskId) {
                                                                                                            that.log(taskId); // The request returns a taskId that should be used to retrieve an object containing the status of the task, start time and finish time (not implemented )
                                                                                                            callback(null, Number(1));
                                                                                                            });
                                                  }).fail(function (err) {
                                                          that.log('Evohome Failed:', err);
                                                          callback(null, Number(0));
                                                          });
    callback(null, Number(0));
}

The credentials at the moment must be set also in the method, I left up to you how to retrieve them in a better way from the config file.

and in session.js of the evohome module I have added:

Session.prototype.setHeatSetpoint = function (deviceId, targetTemperature, minutes) {
    var deferred = Q.defer();
    var url = "https://rs.alarmnet.com/TotalConnectComfort/WebAPI/api/devices/" + deviceId + "/thermostat/changeableValues/heatSetpoint";
    var now = new Date();
    var timezoneOffsetInMinutes = now.getTimezoneOffset();

    var endDate = new Date(now);
    endDate.setMinutes(endDate.getMinutes() - timezoneOffsetInMinutes + minutes);
    endDate.setSeconds(0);
    endDate.setMilliseconds(0);

    var body = JSON.stringify({
                              Value: targetTemperature,
                              Status: "Temporary", // Temporary, Hold, Scheduled
                              NextTime: endDate
                              });

    request({
            method: 'PUT',
            url: url,
            headers: {
            'Content-Type': 'application/json',
            'sessionId': this.sessionId
            },
            body: body
            }, function (err, response) {
            if (err) {
            deferred.reject(err);
            } else {
            deferred.resolve(JSON.parse(response.body));
            }
            });
    return deferred.promise;
}

I used the link you suggested and this one I have found: http://dirkgroenen.nl/projects/2016-01-15/honeywell-API-endpoints-documentation which has also been veeery useful!

At the moment, the target temperature is set for just ten minutes.

luc-ass commented 8 years ago

Cool stuff! I will implement it as soon as possible. Needs to be implemented into "node-evohome" so this could eventually take a few days... I'll let you know!

zizzex commented 8 years ago

Ok, thanks! It would probably be a good idea to set the new temperature till the end of the current schedule or to be able to config the length of the change, but I think this is a good starting point. I have also read that is possible to trigger the Evohome actions, so it would be possible to configure and use with Siri On, Off and Away maybe!

luc-ass commented 8 years ago

I somehow can not get it to work. I'll try some more the following days. Perhaps I can work something out...

zizzex commented 8 years ago

I can send you the folders with the files already modified so you just have to replace those. I have been using the plugin installed on my Mac and setting the temperature through both Siri and HomeKit Catalog Example App from Apple. To make it work I had to configure the thermostats in the App and specify to HomeKit in which room they where placed.

luc-ass commented 8 years ago

I'll try my best to implement it into production this Weekend. As part of this I will be copying node-evohome into this repo so we can make changes much quicker...

luc-ass commented 8 years ago

Never mind. It works now. My fault.

luc-ass commented 8 years ago

It worked. Just updated everything... ready for NPM ;)