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.