tonesto7 / homebridge-smartthings

SmartThings Homebridge Plugin
383 stars 767 forks source link

Window Shade Capability unknown #121

Closed walksonair closed 7 years ago

walksonair commented 7 years ago

Trying to figure out how to keep my window shades that are ZWave from showing up as light dimmers but rather as truly window shade. I am using this code currently https://github.com/A5HRAJ/SmartThings/blob/master/somfy_shades.groovy and it shows as a light dimmer.

Now, conversely, I used to use another code that showed up properly as a window shade and that code was https://github.com/imnotbob/SmartThings-1/blob/Develop/somfy_shades.groovy

Any ideas on what can be done to have the device show up in homebridge as a window shade instead of a dimmable light?

These are what the output shows:

[12/1/2016, 8:39:23 PM] [SmartThings] Unknown Capabilities: ["Smoke Detector","Tamper Alert","Window Shade","Carbon Monoxide Detector","Water Sensor","Health Check","Relay Switch"]

regfixit commented 7 years ago

I am quite new to this kind of programming, but have been playing with a custom device handler to send commands to a raspberry pi to open and close my curtains. I used the capability "windowShade", but it didn't appear in homebridge as a selectable device. I then also added Refresh and Switch and now it shows up. However, what I think is missing is something in /accessories/smartthings.js to handle the windowshade capability - at present there is some coding that interprets "Switch Level" as being a window shade so I am thinking to copy and adapt that to "windowShade". This is the bit I am thinking to copy and adapt in my version if (device.capabilities["Switch Level"] !== undefined) { 57 if (device.commands.levelOpenClose) { 58 //This is a Window Shade 59 this.deviceGroup = "shades" 60

61 thisCharacteristic = this.getaddService(Service.WindowCovering).getCharacteristic(Characteristic.TargetPosition) 62 thisCharacteristic.on('get', function(callback) { callback(null, parseInt(that.device.attributes.level)); }); 63 thisCharacteristic.on('set', function(value, callback) { that.platform.api.runCommand(callback, that.deviceid, "setLevel", { value1: value }); }); 64 that.platform.addAttributeUsage("level", this.deviceid, thisCharacteristic); 65

66 thisCharacteristic = this.getaddService(Service.WindowCovering).getCharacteristic(Characteristic.CurrentPosition) 67 thisCharacteristic.on('get', function(callback) { callback(null, parseInt(that.device.attributes.level)); }); 68 that.platform.addAttributeUsage("level", this.deviceid, thisCharacteristic);

Also in index.js to add this as a knowncapability in this section of code: this.knownCapabilities = ["Switch","Color Control","Battery","Polling","Lock","Refresh","Lock Codes","Sensor","Actuator", "Configuration","Switch Level","Temperature Measurement","Motion Sensor","Color Temperature", "Contact Sensor","Three Axis","Acceleration Sensor","Momentary","Door Control","Garage Door Control", "Relative Humidity Measurement","Presence Sensor","Thermostat", "Energy Meter", "Power Meter", "Thermostat Cooling Setpoint","Thermostat Mode","Thermostat Fan Mode","Thermostat Operating State", "Thermostat Heating Setpoint","Thermostat Setpoint","Indicator"];

walksonair commented 7 years ago

I think the smartthings.js does handle window shades...at least it did for the second code that I had pasted in my original post. Based off your reply, I have a doubt as to whether it's the order of capabilities? If the window shade was listed first, would that get HomeBridge to tag the device as a shade before being tagged as a light switch? I'm just conjecturing here...

walksonair commented 7 years ago

Just to further illustrate, I added a dummy device with the second code (imnotbob/SmartThings-1/blob/Develop/somfy_shades.groovy) and it shows up as a shade in HomeKit. I circled the first group that uses the first code as well as the test shade. Here's a snapshot of my terminal:

screenshot 2016-12-20 10 04 08

regfixit commented 7 years ago

I think it's only working because you have used capability Switch Level and command levelOpenClose. If you comment either of those out I don't think it would work.

walksonair commented 7 years ago

screenshot 2016-12-20 12 35 49

Well, that was a brilliant piece of advice - I added the command levelOpenClose to the code that I wanted to use (the one that showed up as a Dimmable Light) and it is now showing up as Shades...just as I want. Thanks very much for the nudge!

regfixit commented 7 years ago

No Problem !

nmelanson75 commented 6 years ago

I have this same issue, where do you add the "command levelOpenClose"

regfixit commented 6 years ago

It's a while since I looked at all this so trying to remember how it all integrates. I think in Smarthings IDE you create device handler and in that code you specify what capabilities and commands your device supports. One of the commands being levelOpenClose. In the homebrige code on the Pi you have smartthings.js (e.g. in my Pi it's at /usr/local/lib/node_modules/homebridge-smartthings/accessories/smarthings.js) which decides on the type of device based on its capabilities and supported commands. So the following coding decides that if it has capability Switch Level and supports command levelOPenClose then the device group is shades: ... if (device.capabilities["Switch Level"] !== undefined) { if (device.commands.levelOpenClose) { //This is a Window Shade this.deviceGroup = "shades"

regfixit commented 6 years ago

so to answer the question - in your device handler metadata sections include the command levelOpenClose. Eg from https://github.com/ericvitale/ST-Shady/blob/master/devicetypes/ericvitale/shady-group.src/shady-group.groovy

metadata { 28 definition (name: "Shady Group", namespace: "ericvitale", author: "ericvitale@gmail.com") { 29 capability "Switch Level" 30 capability "Actuator" 31 capability "Switch" 32 capability "Polling" 33 capability "Refresh" 34 capability "Sensor" 35 capability "Window Shade" 36
37 command "sceneOne" 38 command "sceneTwo" 39 command "sceneThree" 40 command "sceneFour" 41 command "sceneFive" 42 command "alignTop" 43 command "alignBottom" 44 command "stagger" 45 command "levelOpenClose" 46
47 attribute "sceneOne", "string" 48 }

nmelanson75 commented 6 years ago

Can you share your custom handler with me, the https://github.com/ericvitale/ST-Shady/blob/master/devicetypes/ericvitale/shady-group.src/shady-group.groovy one does not work as the blind does not do anything. Only if I use the Springfashions Device type will it work for the Somfy motors. I am a bit green at custom handlers so I might be doing something wrong.

nmelanson75 commented 6 years ago

The error I get in live logging where it shows the shade as a switch is

cf132972-5e28-440f-a03c-7c32f5f36b0f 2:02:52 PM: info postEventToEndpoint: event successfully posted. cf132972-5e28-440f-a03c-7c32f5f36b0f 2:02:51 PM: warn Device type 'blind' unknown. Mapping to 'OTHER' instead. cf132972-5e28-440f-a03c-7c32f5f36b0f 2:02:51 PM: warn Device type 'blind' unknown. Mapping to 'OTHER' instead.

regfixit commented 6 years ago

I'm a bit green at it too I'm afraid. Not really sure how to use GitHub even. I cut my teeth on a ZX81 programming BASIC then machine code. All this web type stuff is rather new - "consuming" API's and all that. It's been a couple of years since I looked into this then I got caught up in a divorce so still trying to get my head around it all again as the dust has settled a bit and time to focus again on this kind of stuff. In my setup I have a raspberry Pi that I connected to the motor switch contacts to simulate pressing the buttons. I then have a device handler that calls shell script commands on my Pi which run Python commands to alter the GPIO pins to switch a transistor to make the motor think I've pressed a button. The device driver I use is from https://github.com/JZ-SmartThings/SmartThings/blob/master/Devices/Generic%20HTTP%20Device/GenericHTTPDevice.groovy

There is then a file index.php that I put in /var/www/html directory on the Pi. My understanding is that the device handler from smarthings uses HTTP to invoke commands in the index.php file. These commands then call my python scripts. E.g. if (isset($_POST['CurtainsClose'])) { shell_exec("/home/pi/close_lounge.sh"); $rpi = $rpi + array("CurtainsClose" => "Success"); }

In your setup I'm not sure if you're using a Pi. Or you have already a Z wave device that you are trying to control from smartthings by using a custom handler.