X

Contact Us

News

IoT Smart Home Devices, How Smart Are They?

DarrelPham
Senior Software/Hardware Engineer

Darrel Pham here. I am a Lead Software/Hardware Engineer and I’ve been with 219 Design for over 10 years. In that time, I’ve worked across medical device, surgical robotics, automotive, and consumer electronics industries developing an expertise in GUI development, test infrastructure, server backend, and so much more. You can’t leave this skill/curiosity at the office so I’ve been working on some things at home. Here’s a little bit about my latest project.

Part 1: My Story

I recently converted all of my light and fan switches to smart devices, and added connected cameras to my home. This adventure started out as just a way for me to command my home devices through Alexa, but I have discovered even more uses along the way. This blog is an overview of what’s I’ve done with Samsung SmartThings IDE. In this blog, I discover and learn the bare minimum to get more capabilities out of my devices. This is not a tutorial but, hopefully, inspiration for your own tinkering.

If you are looking for tutorials, Samsung has great examples and documentation you can view on their website.

Battling The Ceiling Fan

Last summer, I used Alexa to turn the ceiling fan on/off before going to bed. Saying “Alexa, turn on ceiling fan for 1 hour” doesn’t work. Adding a timer via the Smartthings app wasn’t a good option for me. I wanted the flexibility to use the ceiling fan both with and without a timer.

  • Using the virtual devices feature, I create a virtual device and named it “Ceiling Fan 60 Minutes” which runs a 60 minute timer. Then I also linked the turn on/off action of my original device “Ceiling Fan” to the virtual device on/off action.
  • When I say “Alexa, turn on ceiling fan”, my fan runs indefinitely.
  • When I say “Alex, turn on ceiling fan 60 minutes”, my virtual device run’s for 60 minutes, controlling my real fan and turning it off when the timer expires.

Light at Night

My master bath is controlled by an occupancy switch. The exhaust fan and light turn on by motion, which is convenient and awesome except at 1 am in the morning. I needed the ability to put this feature on a schedule so I decided to buy a smart occupancy switch. Unfortunately, a scheduling feature does not exist so I added it in it’s device handler.

  • After buying the smart switch, I found that it does not have official support so I could not find a generic driver for it. After a quick google search, I found an open source custom device handler.
  • The switch worked well with the custom handler I found, but it needed scheduling.
  • After reviewing the code and understanding the structure of the device handler, I found a way to add schedules.
  • I set the schedule so that the “occupancy” mode is set to “manual” from 12 pm – 6 am by adding a polling timer that compares the current timestamp and schedule time in the timer’s function handler. Then I used the provided functions to switch between the occupancy modes.
  • Using the SmartThing scenes, set it to change to “manual” mode when I activate certain scenes. For example, by saying “Alexa, good night”
  • Future improvements include using SmartThings sunrise/sunset triggers instead of time.

Leveraging Ring’s Motion Sensor

I wanted to use my Ring’s motion sensor to turn on my front lights at 100% brightness, but dim it slowly back to 30% after 5 minutes.

  • This provides 3 awesome things: saving energy and environment, a sense of security, and a semi cool factor.
  • I had to edit the device handler to expose the 30 second fade-in hardware feature for my front door dimmer switch. I also added a timer and a function handler to dim the device back to 30% after 5 minutes.

Part 2: Samsung SmartThings IDE (integrated development environment)

Why Does The Samsung SmartThings IDE exist?

The short answer, there are too many devices out there for everything to always work well together.

My experience started with wanting to make my home smarter. I went out and bought a Samsung SmartThings hub, some smart devices, and an Alexa device. You can add additional devices to your hub using the Samsung SmartThings App. In an ideal world all smart devices would be supported by the hub, adding them to the hub would be a piece of cake, and you’d get access to and control over every feature. But the world is not ideal and you find that, while it is easy to add most devices, some are not officially supported. In addition, some officially supported devices don’t have all of the features exposed and you have to configure the device manually. For example, you may have to physically hold the up button on a light switch for 15 seconds, wait for green light to blink 3 times, then press up again. This is frustrating if you have 30 devices to configure. Even after you get everything added to your hub and can configure your smart devices to do smart things in the app, you have a suspicious feeling that they can do more.

With the SmartThings IDE, you can make your device smarter than what is available out of the box.

What is SmartThings IDE?

  • An online portal that lets you manage and create handlers for your smart devices connected to the Samsung SmartThings Hub
  • An IDE so you can edit existing device handlers or add code to create custom device handlers
  • A SmartApp that can work with different devices or group of devices
  • A simulator so you can test and see the results.
  • A place to publish what you did so others can use it too!

Runs on Groovy

The SmartThings IDE uses Groovy to get things done.  Here are some high-level details of what Groovy is all about:

  • Object-oriented programming language for Java platform
  • Similar to Python, Ruby, Perl, and Smalltalk
  • According to the SmartThings website, “If you are familiar with languages like Java, C/C++, Python, Ruby, or JavaScript, you will see many similarities in Groovy.”
  • You can run 99% of Java code with Groovy

Samsung SmartThings IDE

The link to the IDE

The portal has pages with information on your locations, hubs, devices, SmartApps, device handlers, publication requests, and logging. My Locations contains a summary of all the locations/homes you have. You can drill down to find what hubs are connected to each location and drill down further and see what devices are connected to the hub. You can also view all of your hubs and devices under the My Hubs and My Devices pages. I will talk more about the SmartApps and the Device Handlers later, and the rest of the pages are yours to explore but I will not touch on them since they are self-explanatory.

Device Handlers (for individual devices)

A device handler is a “SmartThings” driver for your hardware. Some companies provide full feature device handlers, but a lot of companies do not. For most devices, you choose a category and a generic driver will be provided for you by Samsung. With generic drivers, only a subset of hardware capabilities are exposed. Some people write their own device handlers to improve on the generic driver and share them. You can find a lot of these custom device handlers on Github or the SmartThings community forum.

If you want to write your own device handler you can start a new blank page, but it is probably faster if you can start with a generic driver template and then add the missing functionality your device is capable of. There is structure to the device handler and there are functions that the platform expects you to implement. The first thing you will usually write is a metadata describing the features of your device. Your SmartThings phone app will use this metadata to display edit boxes, combo boxes, etc, to allow you to configure your device features. You can also add labels that show current states of your device. Next, you add your protocol handlers. These protocol handlers are specific to the protocol your device supports. These can be Wifi, Z-Wave, or Zigbee. You can expose your device’s configurable features and properties in these protocol handlers. One of the last things you write are your handlers for when the devices are installed or updated. In these handlers, you can add a timer for polling so you can implement your own schedule or create your own fade in/out algorithm for your dimmer.

These configurable parameters shown in the app for a Leviton DZ6HD Dimmer are exposed through Metadata:

You can find an example of a custom device handler for the Leviton DZHD Dimmer through these links: 

SmartThings.com Link

GitHub Link

With a generic driver, I got access to On, Off, and a dimming value. With a custom device handler I can set max and min dimming range, which is valuable for LED bulbs (with the exception for smart LED bulbs with built-in internal dimming circuitry; dimming capable LED bulbs can flicker if the max or min dimming range is exceeded). I can also set fading options, and the bulb type.

SmartApps (for a group of devices)

Device handlers work on devices but SmartApps can work on a group of devices. SmartApps let you connect devices together and use an event of one device to trigger an action on another device. There is a Marketplace where you can download smart apps from device companies or from any person that publishes their smart apps. Samsung has some SmartApps they created which are useful for using one device’s state as a trigger for another device’s action. I found a Vacation Lighting Director SmartApp that can be used when I go on Vacation. With this app, I can pick multiple devices I want to randomly turn on and off on a certain time schedule of the day. Another SmartApp lets you add a generic timer to a device to turn it off after the specified time. SmartApps are an additional tool you can use to make your home a bit smarter.

Simulator

You can test your device handlers through a simulation, print out debug messages, and view statuses. The simulator provides an “engineering” interface to configure or activate your device features. These sets of buttons depend on the capabilities you told SmartThings your device has. I found that your real hardware reacts to these “simulations” so if you turn on your device in the simulator, your real device will do the same and the logged events come from the real hardware.

Other Things

You can create a virtual device that does not exist in the real world. With a virtual device, you can use it as a proxy to control other things. This is what I used to control my ceiling fan. A timer was linked to the virtual device so that it would turn off in one hour. To turn on the ceiling fan indefinitely for other occasions, I used the virtual device as a trigger for my target device. However, the virtual device does not know anything about my target device, which is great because I can use this single virtual device to trigger the action of multiple devices.

You can add devices to a scene and tell them what state to be in. For example, I added a “Good Night” scene, and made it lock all my doors, turn off all of my lights, turn on my ambient lighting, turn off my occupancy switches, and turn on the front door light (if it’s not already on) and dim to 30%.

The Verdict

I really appreciate what the SmartThings IDE allows me to do. My home is a bit smarter with it and it was a fun experiment with real world results. Like many of life’s conveniences, it is not necessary but you will miss it once you are accustomed to it. There are still some things that the SmartThings platform needs to iron out. For example. I regularly see that some devices are offline even though I can still control them. Things still work so that doesn’t bother me, but it will be nice when the statuses are correct and the whole process becomes more user friendly.

Date published: 02/27/2019

Categories: Insights

Tags: ,