Making smart homes learn with craft ai & Busit

Smarthome appliances are popping all around the place with great features and new usages. When you stick to that one brand you love, you can benefit from an ecosystem of things that truly makes your day. Quickly, the question of "more" arises and different vendors, protocols, and interactions turn it into a rather inexplicable complex thing. This is where Busit comes into play. First and above all, Busit is a realtime data aggregator engine; sounds harsh... because it is. In other words, it is able to understand any device and make them talk to each other. On top of this, you can manage your devices in an intuitive way in order to create rules, analytics and discover new possibilities. In the end, every actor fit in a seamless integrated environment: manufacturers design great objects, Busit handles the communication, and you decide how to enjoy it most.

However, as easy as can be, if you must configure and create rules for dozens of devices, services, social media and such, it may alter your overall experience. What if just by using your stuff naturally, rules could be discovered automagically?

That’s where craft ai comes into the picture. craft ai provides AI-as-a-service through a simple API with a single goal: learn about how users interact with a system, say a smarthome, to adapt how the system will respond: automate recurring tasks, make proactive recommendations or detect anomalies. Basically craft ai can learn rules from the end user instead of having a developer, or even the end user himself, manually write them. This approach is applicable to part of the full service logic which makes it a good complement to Busit’s: where you know exactly what should be done you write a workflow with Busit, where you want something adapted to every user, you rely on craft ai.

Now that we have established why it is a good idea to integrate craft ai in Busit, let’s see how it is done in practice.

The Busit application model allows for very easy integration of any service or API based on the natural data flow actors: producers, consumers and transformers. BusApps are composed of a declarative configuration file in JSON and a single code file in PHP. Once validated, the application is injected in the Busit ecosystem and is directly compatible with all other applications in order to build event-driven workflows. The craft ai application is considered as a data transformer because it will absorb data for its learning phase and respond with the most appropriate action to take based on the current context. Therefore, it has two data channels:

{
    "channels":
    {
        "learn":
        {
            "pattern": "transformer",
            "direction": "input"
        },
        "decide":
        {
            "pattern": "transformer",
            "direction": "output"
        }
    }
}

Behind the scenes, the BusApp will call the craft ai API and create agents based on the incoming data, then push the message content as a new context, and finally take a decision.

class craft_ai extends App implements Tansformer
{
	public function transform($message, $in, $out)
	{
			$context = $message->content();
			
			$agent = $this->getAgent($context);
			$this->pushContext($context, $agent);
			$value = $this->takeDecision($context, $agent);
			
			if( $value != null )
			{
				$context[$this->config('outputField')] = $value;
				return $message;
			}
			else
				return null;
	}

    [...]
}

Final code and config files

When using the craft ai BusApp, users will specify the name of the variant to predict, the time quantum, and the minimum level of confidence of the decision; Then they may connect their devices from and to craft ai. That’s it, really !




Lighting Ambiance:
Learn & Decide about a comforting warm white or a vivid cold white depending on the current indoor temperature and the daily weather forecast.

At the next stage, when using the combined power of Busit and craft ai in a larger environment such as a complete smart building or even an entire smart city, then it becomes possible to learn the best actions to apply at a micro-level in order to optimize the overall experience depending on the criteria: improve well-being, spare resources or reduce costs. As such, it may be more convenient to start your thermostat one hour later because your neighbor wakes up early in the morning and that is sufficient to provide the desired heat in your own apartment. Or we may lower the public lighting in front of your windows when you are asleep as there is no one passing by.
All those interactions are possible and can be derived from everyday usage, learnt by craft ai and orchestrated by Busit.