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
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.
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.
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
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.
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.
The SmartThings IDE uses Groovy to get things done. Here are some high-level details of what Groovy is all about:
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.
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:
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.
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.
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.
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%.
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.