openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.59k forks source link

[smartthings] Add SmartThings Binding #1694

Closed BobRak closed 3 years ago

BobRak commented 7 years ago

Hi:

I am interested in working on a Samsung Smartthings binding. has anyone else put any effort into it? I have a smartthings hub and a couple of devices that work with it. I am just completing an OpenHAB 2 binding for the cm11a so I am comfortable with binding development. I have read much of the smartthings developer documentation. I am struggling with how the OAuth integration works but I just connected IFTTT to both smartthings and OpenHAB so hopefully I can figure the rest of that out.

Do you think this would be a good addition to OpenHAB?

Are other interested in participating?

Thanks,

Bob Raker

kaikreuzer commented 7 years ago

I'm not aware of any efforts, so feel free to have a go!

I would be nice to have a local integration with it, but afaik, SmartThings does not offer this, right? So yes, a connection through the Cloud service through OAuth is the only option.

Another binding that is following this approach is Netatmo. Note that this uses many external libs, which is not ideal - so please try to find a way with as few external dependencies as possible.

DariBer commented 7 years ago

BobRak, are you working on a SmartThings binding, any progress?

BobRak commented 7 years ago

Yes there has been progress. I have the binding mostly working and am using it on my OpenHAB system. But, I also have a fairly long ToDo list.

It talks over the local LAN so I didn't need to use the OAuth and cloud service.

Here is the ToDo list:

  1. Implement discovery.
  2. Currently the Smartthing hub has to be configured with OpenHAB's IP, port and mac. I want to see if I can send this to Smartthings during discovery. That will simplify the setup
  3. Cleanup Smartthings code
  4. The xml config files in ESH-INF/binding need to be updated to include all possible Smartthing devices.
  5. I am getting a number of concurrent execution exceptions during shutdown - I need to figure out why and fix that.
  6. I also have a question posted in the community forum asking if the web server I am using is OK.

I am guessing that will take at least a month to find time to finish.

Bob

natn commented 7 years ago

If you are looking for someone to test the SmartThings OpenHAB binding I would be willing to sign up. I currently have 60+ devices on SmartThings, and am starting to configure an OpenHab instance. My goal is to move many of the devices to OpenHAB in the future.

BobRak commented 7 years ago

@natn: It would be great to have you test. I have just a few devices connected to my hub and it would be great to have someone with many devices testing to see what I have possibly missed. I suspect it will still be a few weeks before I am ready to put anything out for testing. I'll let you know when I have posted something to my repo.

andreasschraeder commented 7 years ago

Hi Bob, I'm interested in testing it as well. Also have about 60 things on SmartThings and currently use SmartThings, OpenHAB2 and HomeKit in combination. Would like to drop the HomeBridge, once the OpenHAB SmartThings binding works well.

BobRak commented 7 years ago

@andreasschraeder It would be great to have you test as well. I would really like to get this finished up but other things keep getting in the way. Realistically it is a month or so out. As soon as I get the things I am working on right now finished I'll post it in my github repo so people can start testing.

TexasSwede commented 7 years ago

I am in the process of setting up a OpenHab server (on a Rasberry Pi 3). I have a home with a SmartThings hub and around 55-60 devices: window/door sensors, multi sensors (temperatur, etc), motion sensors, lights (both dimmers and on/off), leak sensors, smoke alarms, sirens (two different types/brands), power strips/switches (both indoor and outddor modles, different manufacturers), a presence sensor, Sensibo devices to control air conditioners (who support infrared remote controls) and also the main A/C thermostat. Oh yeah, and (at the moment) 3 door locks, one with code lock. We also have a number of security cameras. Two are wireless Arlo cameras (from Netgear), then we have 5 or 6 PoE IP-based HD cameras who can do both streaming and still pictures (FTP upload).

So I would be very interested in testing and helping out. I am a software developer myself, so I have many good ideas and experience in designing applications. I may not have that much time to actually write code these days, but I am happy to help out in any way I can. One of my big interests is UI and UX design as well as integration of different systems.

BobRak commented 7 years ago

@natn @andreasschraeder @TexasSwede A TEST Smartthings binding is now available for those of you that are interested in testing. It is located Here in my GitHub Repo.

As I've already said I have a limited number of devices and I already know enhancements will be needed to support some of the devices. I am willing to make enhancements if you are willing to test and work together. Please raise issues in my Repo, not in an OpenHAB repo, since it currently only exists in my repo. I have included a troubleshooting document that will hopefully help you diagnose issues and let you know what information I need to resolve issues.

Bob

anthonygillet commented 7 years ago

@BobRak - I just wanted to let you know I tested your binding and it seems to work great for the one device that I have, a Monoprice 15902 Multi-sensor / zooZ 4-in-1-Sensor ZSE40.

I am using the following device handler for this device: https://github.com/robertvandervoort/SmartThings/blob/master/zooZ-4-in-1-Sensor-ZSE40/device_type-zooZ-4-in-1-Sensor-ZSE40_v1.2)

After I installed your binding, here is how I configured it in OpenHab2:

Things file

Bridge smartthings:smartthings:Home    [ smartthingsIp="x.x.x.x", smartthingsPort=39500 ] {
    Thing motionSensors           MediaRoomMotionSensor          [ smartthingsName="Media Room Motion and Temp Sensor" ]
    Thing temperatureMeasurement  MediaRoomTemperatureSensor     [ smartthingsName="Media Room Motion and Temp Sensor" ]
    Thing humiditySensor          MediaRoomHumiditySensor        [ smartthingsName="Media Room Motion and Temp Sensor" ]
    Thing illuminanceMeasurement  MediaRoomIlluminanceSensor     [ smartthingsName="Media Room Motion and Temp Sensor" ]
    Thing accelerationSensor      MediaRoomAccelerationSensor    [ smartthingsName="Media Room Motion and Temp Sensor" ]
    Thing battery                 MediaRoomSensorBattery         [ smartthingsName="Media Room Motion and Temp Sensor" ]
}

Items file

Contact media_room_motion_sensor "Media Room Motion Sensor [MAP(contact.map):%s]" <motion> { channel="smartthings:motionSensors:Home:MediaRoomMotionSensor:motion" }  
Number  media_room_temp_sensor "Media Room Temperature [%.2f °F]" <temperature> { channel="smartthings:temperatureMeasurement:Home:MediaRoomTemperatureSensor:temperature" }  
Number  media_room_humidity_sensor "Media Room Humidity [%.2f%%]" <humidity> { channel="smartthings:humiditySensor:Home:MediaRoomHumiditySensor:humidity" }  
Number  media_room_illuminance_sensor "Media Room Illuminance [%.2f lux]" <dimmablelight> { channel="smartthings:illuminanceMeasurement:Home:MediaRoomIlluminanceSensor:illuminance" }  
Contact media_room_acceleration_sensor "Media Room Acceleration Sensor [MAP(contact.map):%s]" <motion> { channel="smartthings:accelerationSensor:Home:MediaRoomAccelerationSensor:acceleration" }  
Number  media_room_sensor_battery "Media Room Sensor Battery [%.1f%%]" <battery> { channel="smartthings:battery:Home:MediaRoomSensorBattery:battery" }  

Sitemap

  Frame label="Media Room Sensors"
  {
    Text item=media_room_motion_sensor
    Text item=media_room_temp_sensor
    Text item=media_room_humidity_sensor
    Text item=media_room_illuminance_sensor  
    Text item=media_room_acceleration_sensor  
    Text item=media_room_sensor_battery  
  }

contact.map

OPEN=open
CLOSED=closed
active=open
inactive=closed
=unknown
-=unknown
NULL=unknown

This works great! The motion status, battery, temperature, humidity, and illuminance are all reported properly and reflect the same values as the ST website. The binding works flawlessly, the only issues I have are with this particular device:

  1. The Acceleration Sensor does not appear to work properly in this device, it's never reported anything other than "inactive". I don't think this is a binding issue, the ST website reflects the same.
  2. The device itself sometimes takes a few seconds to wakeup after detecting motion. You can tell because the LED does not flash right away. However, almost instantly after the LED flashes, the binding receives the event and the OH item state is updated.

If I add more devices, I'll try them out as well. In the meantime, I have some feedback:

After getting everything configured, it's worked flawlessly for a few hours now. I'll keep an eye on it. Great work, thanks so much for putting this together!

BobRak commented 7 years ago

@anthonygillet Thank you very much for the feedback. I have incorporated your feedback and pushed an new release to GitHub. I wrote the *.md files using Eclipse and there they looked fine and linked worked. But not on GitHub. I'll keep that in mind and make sure they also work as expected once I push to GitHub. I also corrected the name of the motionSensor. Thanks again for the feedback. Bob

anthonygillet commented 7 years ago

@BobRak, thanks for the quick fix! Unfortunately I'm not able to get motion sensors working after this update. Here's the log showing the failure:

2017-05-01 17:13:09.551 [DEBUG] [rtthings.internal.SmartthingsServlet] - Smartthings servlet service() called with: x.x.x.x: POST /smartthings/state
2017-05-01 17:13:09.553 [DEBUG] [rtthings.internal.SmartthingsServlet] - Smartthing servlet function requested: state with Method: POST
2017-05-01 17:13:09.554 [DEBUG] [rtthings.internal.SmartthingsServlet] - Smartthing servlet processing "state" request. data: {"deviceDisplayName":"Kitchen Motion and Temp Sensor","value":"inactive","capabilityAttribute":"motion"}
2017-05-01 17:13:09.555 [DEBUG] [s.internal.SmartthingsHandlerFactory] - Event received on topic: org/openhab/binding/smartthings/state
2017-05-01 17:13:09.556 [DEBUG] [ngs.handler.SmartthingsBridgeHandler] - received message from Smartthings hub
2017-05-01 17:13:09.557 [INFO ] [ngs.handler.SmartthingsBridgeHandler] - Could not map the message from the Smartthings hub: capabilityKey="null" with device name="Kitchen Motion and Temp Sensor", capabilityAttribute="motion", into an OpenHAB thing/channel, maybe this isn't configured in OpenHAB

I updated my motion sensor Thing & item definitions as such:

Thing motionSensor            KitchenMotionSensor           [ smartthingsName="Kitchen Motion and Temp Sensor" ]
Contact kitchen_motion_sensor "Kitchen Motion Sensor [MAP(contact.map):%s]" <motion> { channel="smartthings:motionSensor:Home:KitchenMotionSensor:motion" }  

I did a quick search of the repo, I found one remaining instance of "motionSensors" in SmartthingsBindingConstants.java, could that be it?

anthonygillet commented 7 years ago

I may have discovered one other usability issue with the binding. I will preface this by saying I am just guessing what is going on.

For the accelerationSensor and motionSensor types, the SmartThings binding may need to provide some translation to be compatible with OpenHab. SmartThings uses "active" and "inactive" as the types for these sensors, whereas in OpenHab, these will map to the Contact item type which uses "open" and "closed".

Unless I am doing something wrong, I see this issue with Contact items that subscribe to accelerationSensor binding channels. (I can't test motion sensors right now.) They never get updated to anything other than NULL. However, if I use a String item type instead of Contact, they are updated to "inactive" or "active".

BobRak commented 7 years ago

@anthonygillet You are correct about the SmartthingsBindingConstants.java needing to be changed to motionSensor. Sorry about missing that. I have updated and redepolyed.

With regards to the usability issue. I have a Smartthings multipurpose sensor and it includes acceleration and contact. With this update the motionSensor should be fine (I think). My thing and items definitions for this are: Thing: contactSensor MainGarageDoor [ smartthingsName="Garage Door Open Sensor" ]

Item: Contact MainGarageDoor "Garage door status [%s]" { channel="smartthings:contactSensor:Home:MainGarageDoor:contact" }

Sitemap: Text item=MainGarageDoor

For the accelerationSensor I defined it as a String type since I didn't equate that to a contact type sensor (in my mind). Here are my definitions and they do work:

Thing: accelerationSensor MainGarageAcceleration [ smartthingsName="Garage Door Open Sensor" ]

Item: String MainGarageAcceleration "Garage acceleration [%s]" { channel="smartthings:accelerationSensor:Home:MainGarageAcceleration:acceleration" }

Sitemap: Text item=MainGarageAcceleration

Do your think this is OK or is there a reason that the accelerationSensor could be translated to a Contact sensor using "open" and "closed"

anthonygillet commented 7 years ago

I can confirm that motion sensors are now updating properly after the fix. Thanks!

To follow up on the Contact vs String discussion, as you note, currently motion sensors and acceleration sensors only work properly when defined as String items in OH. If you define a ST motionSensor item as a String, it switches values between "active" and "inactive". But if you define a ST motionSensor item as a Contact, it remains NULL (since there is no mapping).

In your case, you are using a ST contactSensor, for which SmartThings returns "open" and "closed", which happens to map properly with the OpenHab Contact item paradigm, and hence works when defined as a Contact item.

Generally, it seems that other bindings seem to map sensors like this (especially motion sensors) to a Contact item rather than a String, since that makes it easier to manipulate, group, and inspect in OH. Here are a couple threads that are somewhat related to binary sensors like this in the Z-wave binding:

https://community.openhab.org/t/map-transform-for-zwave-items/8349/32 https://community.openhab.org/t/on-off-vs-open-close-contact-item-cannot-get-it-to-work/11322/16

Basically, the item only has two possible states - "inactive" or "active" so I believe it makes sense to map it to a native OH item type like Contact rather than String.

You could also achieve this by providing multiple Thing channels for these types, i.e. one channel that produces a String type and one that produces a Contact type. However, this may not be as straightforward, since it seems you may be auto-generating the types and channels from the ST capabilities.

At the end of the day it's up to you as the binding creator what types of channels you want to support. Just a suggestion that Contact types may be more user-friendly than String types.

Let's get some other testers in here! :)

BobRak commented 7 years ago

@anthonygillet I wish I was auto generating the types and channels from the Smartthings reference, but I am not. I like you idea of supporting both a string type and a contactType for motion and acceleration sensors (and maybe some others). That will give users a choice. When I get a chance I'll try implementing that and see if it will work with what I am able to get back from Smartthings.

anthonygillet commented 7 years ago

This binding is still working great for me! What's next as far as getting this into the official distribution?

Question / feature request. Is it possible to have the binding also control and report the state of the Smart Home Monitor? I am attempting to use ST as an alarm system and that would make OH integration easy. It would be ideal to have access to view and change both the current "mode" (home/away/night) and the arm status (armed-home/armed-away/disarmed). Not sure if this is doable in the ST API.

martinvw commented 7 years ago

This binding is still working great for me! What's next as far as getting this into the official distribution?

Creating a PR or is it already there?

BobRak commented 7 years ago

Anthony:
I posted a status update in my repo. You can see it here.

I have looked into using the Smart Home Monitor a little. From what I've found it seems possible although there is no official API at this point. I want to finish up what is in progress now before taking on anything more. If you want me to look at it further please raise an issue in my repo (where the status update has been posted). I'll look into it as soon as I am able to post an updated bining in my repo for people to start testing with.

Also please post any further comments / issues in my repo so I have one place to track things that need to be addresses

martinvw - It is not ready for a PR yet

Bob

dpackham commented 6 years ago

Does this binding allow you to see and control devices FROM the ST hub as well or only from the OH2 interface control ST devices?

installed this and on the ST app I can see the ST devices but not the OH2

BobRak commented 6 years ago

I see you posted the same question on my github account and have closed it. Please post any questions about this binding on my github (bobrak) account since it is not part of openHAB at this time. Thanks.

BobRak commented 3 years ago

A new issue was created because this went on for so long. The Smartthings binding has been merged. This should be closed.