Voice-Controlled Lamp Using Ninja Blocks + MacBook

Here’s a video of my latest quick weekend hack, using voice to switch a lamp on and off:

Ok, so it’s actually a combination of Watts Clever + Ninja Blocks + Node.js + Automator + Speakable Items. Speakable Items takes the voice commands via MacBook’s internal microphone, then calls the Automator applications, which then runs a Node.js script (which output gets spoken by Automator applications), which then tells Ninja Blocks to actuate Watts Clever power socket.

Here’s how I set it up:

Configure Watts Clever remote RF signals on Ninja Blocks dashboard (/hattip: @james and @Jeremy over at the forum).

Create this simple Node.js script file. I saved it as rf433.js .

var ninjaBlocks = require('ninja-blocks'),
  app = ninjaBlocks.app({
    user_access_token: 'your-ninjablocks-token'
  });

app.devices({ device_type: 'rf433' }, function (err, devices) {
  var subDevices = app.utils.findSubDevice({ shortName: process.argv[2] }, devices);
  console.log('Switching ' + name);
  Object.keys(subDevices).forEach(function (key) {
    var subDevice = subDevices[key];
    app.device(subDevice.guid).actuate(subDevice.data)
  });
});

Create two Automator applications, one called ‘Lamp on’, the other ‘Lamp off’, each containing:

  • Run Shell Script, which is used to run rf433.js .

  • Speak Text, which is used to notify when device#actuate is about to be called (that’s the console.log('Switching ' + name); line from the above Node.js script).

These applications must be available from ~/Library/Speech/Speakable Items/ .

Configure the Mac’s System Preferences -> Accessibility -> Speakable Items on Lion and Mountain Lion, or System Preferences -> Speech on Snow Leopard.

Done.

Overall, this is just an experiment to prove that it can be done. Speakable Items is obviously not Siri, so you can’t expect the same quality of speech recognition. And having to open a MacBook every time I want to use this is obviously too troublesome.

It would be awesome for Ninja Blocks to have / work with something like Ubi. Every home automation solution needs at least a voice or gesture based input mechanism :).

Note to self: I’m totally looking forward to the future where every single thing in the house is powered by renewable energy-based wireless electricity, each running a tiny low-powered Node.js server which talks to one another via HTTP. Life would be much more efficient!

Update (14/12/2014): Ninja Blocks’ Dan Friedman showed a demo video of Ubi integration with Ninja Sphere. W00t w00t!

Share Comments
comments powered by Disqus