johnlemonse / homebridge-telldus

36 stars 22 forks source link

Support for Windows Blinds in homebridge-telldus #33

Closed krfr closed 7 years ago

krfr commented 7 years ago

Would like to be able to control my window blinds with Siri. Do you think it is possible to integrate this function?

As I understand there is only support for "selflearning-switch, selflearning-dimmer, codeswitch, temperature and temperaturehumidity" today and I wonder if it is possible to add "windows_covering" with up / down commands.

mifi commented 7 years ago

If both telldus and apple homekit supports blinds, then it shouldn't be too hard

krfr commented 7 years ago

Telldus supports it and I believe that Homekit supports it as well.

mifi commented 7 years ago

Looking at the HomeKit Accessory Simulator, it seems it supports something called Window Covering

screen shot 2016-12-03 at 12 47 15

HAP nodejs says:

  // Required Characteristics
  this.addCharacteristic(Characteristic.CurrentPosition);
  this.addCharacteristic(Characteristic.TargetPosition);
  this.addCharacteristic(Characteristic.PositionState);

  // Optional Characteristics
  this.addOptionalCharacteristic(Characteristic.HoldPosition);
  this.addOptionalCharacteristic(Characteristic.TargetHorizontalTiltAngle);
  this.addOptionalCharacteristic(Characteristic.TargetVerticalTiltAngle);
  this.addOptionalCharacteristic(Characteristic.CurrentHorizontalTiltAngle);
  this.addOptionalCharacteristic(Characteristic.CurrentVerticalTiltAngle);
  this.addOptionalCharacteristic(Characteristic.ObstructionDetected);
  this.addOptionalCharacteristic(Characteristic.Name);

And the required characteristics:

Characteristic.CurrentPosition = function() {
  Characteristic.call(this, 'Current Position', '0000006D-0000-1000-8000-0026BB765291');
  this.setProps({
    format: Characteristic.Formats.UINT8,
    unit: Characteristic.Units.PERCENTAGE,
    maxValue: 100,
    minValue: 0,
    minStep: 1,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
  });
  this.value = this.getDefaultValue();
};
Characteristic.TargetPosition = function() {
  Characteristic.call(this, 'Target Position', '0000007C-0000-1000-8000-0026BB765291');
  this.setProps({
    format: Characteristic.Formats.UINT8,
    unit: Characteristic.Units.PERCENTAGE,
    maxValue: 100,
    minValue: 0,
    minStep: 1,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
  });
  this.value = this.getDefaultValue();
};
Characteristic.PositionState = function() {
  Characteristic.call(this, 'Position State', '00000072-0000-1000-8000-0026BB765291');
  this.setProps({
    format: Characteristic.Formats.UINT8,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
  });
  this.value = this.getDefaultValue();
};

So if telldus has a possibility for reading CurrentPosition / Position State and writing TargetPosition, then it should be possible. Or it might be possible to simplify/fake these values. Need to know more on how blinds work in telldus.

https://github.com/KhaosT/HAP-NodeJS/blob/master/lib/gen/HomeKitTypes.js

krfr commented 7 years ago

In my case i use Telldus Znet Lite V1 which only supports transmission at 433 MHz and can not read the status of devices through 433 protocol.

I really do not know how it works. When I log on api.telldus.com I can send down, up and stop commands to my devices.

mifi commented 7 years ago

Even though its tx only, telldus will store the beleived state of the device. The issue is to find Out what the different state values in telldus mean, and which function to call with which values on telldus api to lower/raise the blinds

mifi commented 7 years ago

You could try to set it as a switch and see if it automatically works with on/off

krfr commented 7 years ago

Tried to put it as a switch, nothing happens, unfortunately,

mifi commented 7 years ago

If you can provide provide http://api.telldus.com/explore/device/info responses for each of the states of your blinds, then maybe I can use that.

krfr commented 7 years ago

No't sure if i'm doing it right.. Get same responce in every case:

before running http://api.telldus.com/explore/device/up Responce: {"id":"1209120","name":"persienn","state":"0","statevalue":null,"methods":"0","type":"device","client":"202305","protocol":"433","model":"n\/a","online":"1","editable":1,"parameter":[]}

after running http://api.telldus.com/explore/device/up - before blinds stop moving Responce: {"id":"1209120","name":"persienn","state":"0","statevalue":null,"methods":"0","type":"device","client":"202305","protocol":"433","model":"n\/a","online":"1","editable":1,"parameter":[]}

after blinds stop moving Responce: {"id":"1209120","name":"persienn","state":"0","statevalue":null,"methods":"0","type":"device","client":"202305","protocol":"433","model":"n\/a","online":"1","editable":1,"parameter":[]}

after running http://api.telldus.com/explore/device/down - before blinds stop moving Responce: {"id":"1209120","name":"persienn","state":"0","statevalue":null,"methods":"0","type":"device","client":"202305","protocol":"433","model":"n\/a","online":"1","editable":1,"parameter":[]}

after blinds stop moving Responce: {"id":"1209120","name":"persienn","state":"0","statevalue":null,"methods":"0","type":"device","client":"202305","protocol":"433","model":"n\/a","online":"1","editable":1,"parameter":[]}

mifi commented 7 years ago

Thats odd. Response is from device/info, right? Maybe you can try some other functions in the explorer and find if some values change when you alternate up/down

krfr commented 7 years ago

Yes, from device/info. Checked for other functions in API explorer without any luck.

Probably Telldus don't store a "believed state" at all for this kind of devices and therefor responce is same?

mifi commented 7 years ago

Maybe. what about the web GUI in telldus live, does it show any difference between up/down/moving?

krfr commented 7 years ago

The look is static, so you see no difference if the blinds are up, down or moving.

krfr commented 7 years ago

I looked at https://github.com/TheThingSystem/node-telldus-live/blob/master/telldus-live.js and saw that they have functions for up / down. Perhaps this is something that can be useful?

TelldusAPI.prototype.upDownDevice = function(device, upP, callback) { return this.roundtrip('PUT', '/device/' + (upP ? 'up' : 'down') + '?'

mifi commented 7 years ago

Yea we can use that, but apple Home needs to know the current state of the blinds too. Im not sure if it has a stateless button

mifi commented 7 years ago

I made a simple hack for controlling blinds. You can try it here: npm install -g git+https://github.com/mifi/homebridge-telldus.git

You have to use the model "stateless-updown"

krfr commented 7 years ago

It seems to be working :-) Let me test for a while and I will get back with feedback

krfr commented 7 years ago

Tested up and down several times and it works perfectly. It was difficult to learn which commands that worked with Siri. I also had to test different names on my devices (window blinds) before Siri did what I wanted. Swedish-talking Siri is not as smart as the English version;-)

Siri works as intended, and buttons in home app works as well. Good work!

mifi commented 7 years ago

Cool :) I have merged to master and released now, #35, v0.0.8 in npm. NB! Ichanged the model to "window-covering" so you need to change your config