Using Ruby with MiOS from Mi Casa Verde

Vera LiteMi Casa Verde. You can read the specifications of the devices for yourself but I like them because they are inexpensive, have low-power requirements, are capable of interfacing with a number of different kind of home automation systems, and most importantly, have a documented JSON/XML API. Coincidentally, they also have a developer special program and lack a ruby gem, so another rainy day project is born!

The operating system these devices run is called MiOS which is essentially Linux/ARM and lots of glue. Mi Casa Verde operates a free VPN service that allows you to operate them remotely, and there are a number of free/paid smartphone apps available (though none struck me as particularly special). All of the interactions with MiOS work on a job queue basis. When a job is submitted, it’s status must be polled for success/failure. The Ruby library embraces this and allows jobs to be run synchronously or asynchronously.

Some snippets from the github page:

mios = MiOS::Interface.new('http://192.168.15.1:3480')
switch = mios.devices[0]
switch.off! { |obj|
  puts "The #{obj.name} is now off"
}
puts "This will get printed once the switch is off and the block has been executed"

switch.on!(true) { |obj|
  puts "The #{obj.name} is now on"
}
puts "This will output immediately"
sleep(5) # Sleep to wait for the thread to finish

Every device is supported by manually issuing commands as listed in the wiki and the devices that I currently use have nice wrappers around those for idiomatic usage (example).

Installation instructions and additional usage examples can be found on github under the ruby-mios project.

Enjoy!

Bookmark and Share

About Kelley Reynolds

A full-stack software engineer, an avid trail runner, and a bassoonist. Kelley occasionally writes about one of his many projects on this blog.

, , ,