SmartThings Machine Learning Project

Thought I’d share in case anyone is interested.

I’ve got SmartThings (and other APIs) to begin some basic machine learning. Right now, it’s got it’s training wheels on and will only tell me what action it would like to do and with what confidence it believes it has in doing it. Once the machine and I agree at the good confidence level, I intend to give it control of the house.


How it works:
Every event that’s fired on SmartThings sends a HubCommand to my system to register that event. I interface with my system directly - and it sends a request to act on SmartThings (and Nest as well as other systems). My system has a single object that contains the “state of the world” - every device / subdevice state, what it is, when it was last activated, etc. Upon every meaningful action, there’s an artificial delay of 1 minute (configurable), then a snapshot of that state is captured and appended to an array of snapshots. The delay is so the stored state is what we want the world to be after a given event. This array is written to disc regularly and a new file created for every day. With my home, which has quite a few devices / events firing, the file is typically ~6mb / day.

Each day, the system looks for any files it has not already seen and processes the days events, categorizing them by type of day (weekday / weekend) and time of day (dawn, morning, afternoon, night). It creates a simple hash table for the type of events that are executed. This file is written to disc after every time files are processed. It it’s unlikely this file would exceed 1mb. If I turn my office light on in the morning, it will look at the average state of every other device that’s actionable by a quick lookup in the pre-processed hash table. If another device has a state that is, on average, beyond a given threshold, we can fire an intent against it. If that intent is not desired, I have the 1 minute to correct the action and the system can then learn from that change. Failing to correct the action will reinforce that action.

The code is pretty rudimentary, but it’s a personal project just for fun. Thought I’d share in case others were interested or had things to share that I may learn from.


I’m interested! Sounds amazing!


This is something i’ve wanted to work on for awhile but just haven’t had the time

Great idea! I think with the event logger to external api can really trains the machine and let it learn.

But have you coded in prime directives yet?

1 Like

Naw - everything should be fine without, right? Right?

I really want to install this onto my RPi, but with my own interface. Specifically, I have a floor plan image for my house that I would want to place all the devices/statuses on to…

Do you have any beginner level developer documentation if I wanted to dive in and tweak things?

I’m out of town for a while, but when I return, I can help you configure

The interface is made with simple html and css. You should have relatively
free reign to alter the aesthetics without issue.

I’m back in town now. Changing the interface shouldn’t be a big deal, depending on what you want done. I may have to add a bit of functionality to get what I believe you want, but nothing major. If you’re interested, the best first step is to install and configure the software, then reach out on the IRC channel I have set up for it - so we can keep the discussion on-topic for SmartThings here.

Awesome, thanks. I will do that this weekend. I had trouble setting up the app, but it may be just due to my lack of familiarity with the RPi system.

I’ve posted more about my machine learning experiment here if anyone is interested:

TL;DR: since it’s only acting on devices that are not already in their desired state - and the confidence required is relatively high, it just reinforces that state in which the user set things.