rhouse - home automation is ruby ?

62
r-house Fernand Galiana Friday, May 8, 2009

Upload: fernand-galiana

Post on 12-May-2015

7.902 views

Category:

Technology


0 download

DESCRIPTION

Home automation using ruby. Control various devices around your house, using your iphone and yes even twitter...

TRANSCRIPT

Page 1: Rhouse - Home automation is ruby ?

r-house

Fernand Galiana

Friday, May 8, 2009

Page 2: Rhouse - Home automation is ruby ?

r-house

Fernand Galiana

Friday, May 8, 2009

Page 3: Rhouse - Home automation is ruby ?

creditsrails

arrayfieldsbones

beanstalk-client

darkfish-rdoc

flexmocksinatra

logging

memcached

passenger

ruleby

twibot

system-timermain twitter4r

rake

id3lib-ruby

json

toholio-serialport

rackrfuzz

Friday, May 8, 2009

Page 4: Rhouse - Home automation is ruby ?

warning

Friday, May 8, 2009

Page 5: Rhouse - Home automation is ruby ?

Friday, May 8, 2009

Page 6: Rhouse - Home automation is ruby ?

Friday, May 8, 2009

Page 7: Rhouse - Home automation is ruby ?

groups.google.com/group/derailed

Friday, May 8, 2009

Page 8: Rhouse - Home automation is ruby ?

ZiYa

git://github.com/derailed/ziya.git

Friday, May 8, 2009

Page 9: Rhouse - Home automation is ruby ?

MOle

git://github.com/derailed/mole.git

Friday, May 8, 2009

Page 10: Rhouse - Home automation is ruby ?

?homeautomation

Friday, May 8, 2009

Page 11: Rhouse - Home automation is ruby ?

?homeautomation

Friday, May 8, 2009

Page 12: Rhouse - Home automation is ruby ?

telephonydigital mediaclimate

securityav-equipmentlighting

Friday, May 8, 2009

Page 13: Rhouse - Home automation is ruby ?

Friday, May 8, 2009

Page 14: Rhouse - Home automation is ruby ?

Appliance kWh / Year CostTv 240 $30

Fridge 500 $60Dw 168 $20

Lamp(60w) 130 $16MacBook

24hrs84 $10

Washer 26 $6Dryer 420 $50

Water Heater 2,832 $336Furnace 2,232 $264

Total 6,632 $785.24

Friday, May 8, 2009

Page 15: Rhouse - Home automation is ruby ?

opensource HA

openremotecontrol4linuxmcemrhousedomotigalinuxha

Friday, May 8, 2009

Page 16: Rhouse - Home automation is ruby ?

protocols

X10 - InsteonLonWorks/BatibusZigBee/Zwave

Friday, May 8, 2009

Page 17: Rhouse - Home automation is ruby ?

Friday, May 8, 2009

Page 18: Rhouse - Home automation is ruby ?

linuxmce

Friday, May 8, 2009

Page 19: Rhouse - Home automation is ruby ?

the gear

Friday, May 8, 2009

Page 20: Rhouse - Home automation is ruby ?

Asus EEE Box MCV Zwave dongle Panasonic IP Cam Monster Cable Zwave dimmer HomeSeer Zwave sensor Arduino ( Eventual furniture? )

Friday, May 8, 2009

Page 21: Rhouse - Home automation is ruby ?

> gem install derailed-rhousegit://github.com/derailed/rhouse.git

Friday, May 8, 2009

Page 22: Rhouse - Home automation is ruby ?

DCE router

Friday, May 8, 2009

Page 23: Rhouse - Home automation is ruby ?

DCE router0 28 1 184 76 "50"

Friday, May 8, 2009

Page 24: Rhouse - Home automation is ruby ?

DCE router0 28 1 184 76 "50"

Friday, May 8, 2009

Page 25: Rhouse - Home automation is ruby ?

DCE router0 28 1 184 76 "50"

Friday, May 8, 2009

Page 26: Rhouse - Home automation is ruby ?

DCE router0 28 1 184 76 "50"

Friday, May 8, 2009

Page 27: Rhouse - Home automation is ruby ?

DCE router0 28 1 184 76 "50"

Friday, May 8, 2009

Page 28: Rhouse - Home automation is ruby ?

DCE router0 28 1 184 76 "50"

Friday, May 8, 2009

Page 29: Rhouse - Home automation is ruby ?

DCE router0 28 1 184 76 "50"

Friday, May 8, 2009

Page 30: Rhouse - Home automation is ruby ?

dce

architecture

db

devices

Friday, May 8, 2009

Page 31: Rhouse - Home automation is ruby ?

dce

architecture

db

devices

Friday, May 8, 2009

Page 32: Rhouse - Home automation is ruby ?

dce

architecture

db

devices

Friday, May 8, 2009

Page 33: Rhouse - Home automation is ruby ?

dce

rh_interceptor

architecture

db

devices

Friday, May 8, 2009

Page 34: Rhouse - Home automation is ruby ?

dce

rh_interceptor

architecture

db

devices

Friday, May 8, 2009

Page 35: Rhouse - Home automation is ruby ?

dce

rh_interceptor

architecture

db

devicesrh_rhouse

Friday, May 8, 2009

Page 36: Rhouse - Home automation is ruby ?

dce

rh_interceptor

architecture

db

devicesrh_rhouse

Friday, May 8, 2009

Page 37: Rhouse - Home automation is ruby ?

dce

rh_interceptor

architecture

db

devicesrh_rhouse

Friday, May 8, 2009

Page 38: Rhouse - Home automation is ruby ?

rh_interceptor

architecture

Friday, May 8, 2009

Page 39: Rhouse - Home automation is ruby ?

rh_interceptor

beanstalk queue

architecture

Friday, May 8, 2009

Page 40: Rhouse - Home automation is ruby ?

rh_interceptor

beanstalk queue

worker rhouseapp

architecture

Friday, May 8, 2009

Page 41: Rhouse - Home automation is ruby ?

rh_interceptor

beanstalk queue

worker rhouseapp

architecture

rules engine

Friday, May 8, 2009

Page 42: Rhouse - Home automation is ruby ?

architecture

Friday, May 8, 2009

Page 43: Rhouse - Home automation is ruby ?

house_rules

architecture

Friday, May 8, 2009

Page 44: Rhouse - Home automation is ruby ?

house_rules

rh_rhouse

architecture

Friday, May 8, 2009

Page 45: Rhouse - Home automation is ruby ?

house_rules

rh_rhouse

architecture

Friday, May 8, 2009

Page 46: Rhouse - Home automation is ruby ?

house_rules

rh_rhouse

architecture

Friday, May 8, 2009

Page 47: Rhouse - Home automation is ruby ?

house_rules

rh_rhouse

architecture

Friday, May 8, 2009

Page 48: Rhouse - Home automation is ruby ?

@rhousse

Friday, May 8, 2009

Page 49: Rhouse - Home automation is ruby ?

demo

Friday, May 8, 2009

Page 50: Rhouse - Home automation is ruby ?

rh-interceptor

def initialize( opts={} ) logger.debug "Initializing Interceptor in `#{Rhouse.environment}" # check required args raise "No interceptor id specified" unless opts[:interceptor] config = YAML.load_file( Rhouse.confpath( "interceptor.yml" ) ) @settings = config[Rhouse.environment] @settings['interceptor'] = opts[:interceptor] @settings['host'] = opts[:router] if opts[:router] end

Friday, May 8, 2009

Page 51: Rhouse - Home automation is ruby ?

rh-interceptorcommon: &common port: 3450 dce_id: -1000 beanstalk_port: 7777 sleep_interval: 30 events: 140: 1 # Camera 73: 1 # Lighting 84: 2 # Security 83: 2 # Climate 13: 2 # Media Players development: *common host: rhousetest: *common host: localhostproduction: *common host: localhost

Friday, May 8, 2009

Page 52: Rhouse - Home automation is ruby ?

rh-interceptor

def connect @in_socket = Socket.new( AF_INET, SOCK_STREAM, 0 ) @out_socket = Socket.new( AF_INET, SOCK_STREAM, 0 )

in_socket.connect( Socket.pack_sockaddr_in( config(:port), config(:host) ) ) out_socket.connect( Socket.pack_sockaddr_in( config(:port), config(:host) ) ) in_socket.send( "COMMAND #{config(:interceptor)}\n", 0 ) check_ok_response( in_socket, "Setting up command channel" )

out_socket.send( "EVENT #{config(:interceptor)}\n", 0 ) check_ok_response( out_socket, "Setting up event channel" ) out_socket.send( "PLAIN_TEXT\n", 0 ) check_ok_response( out_socket, "Registering plain text messages" ) end

Friday, May 8, 2009

Page 53: Rhouse - Home automation is ruby ?

rh-interceptor

def register_events events = config( :events ) events.each_pair do |event_id, message_type| command = "#{config(:interceptor)} #{config(:dce_id)}” + “#{register_interceptor} 0 5 #{message_type} 4 #{event_id}" out_socket.send( "MESSAGET #{command.size}\n#{command}\n" , 0 ) check_ok_response( out_socket, "Registering #{event_id}" ) end end

Friday, May 8, 2009

Page 54: Rhouse - Home automation is ruby ?

rhouse-app

module MyRhouse class HouseRules < Rhouse::Worker # Fetch the yaml configuration file def configuration_file @config_file_name ||= MyRhouse.confpath( "#{config_file_name}.yml" ) end # Handle event on queue. Parse event and create an associated event object # for the rules engine to consume. def handle_event( event ) evt = Rhouse::EventParser.parse( event ) event_type = MyRhouse::Events::EventTypeFactory.create_event( evt )

# fire up rule engine engine.evaluate( event_type ) end endend

Friday, May 8, 2009

Page 55: Rhouse - Home automation is ruby ?

house-rules

module MyRhouse::Rules class HouseRuleBook < Ruleby::Rulebook def rules # Deal with music rule [MyRhouse::Events::Generic, :event, m.description =~ /.*Xine\sPlayer.*/] do |context| cmd = case context[:event].command_id when 12 : 'b' # Play Back Completed when 58 : 'g' # Start playing when 22 : 'r' # Stop playing end MyRhouse::Plugins::Arduino.new.blink_light( cmd ) logger.info "\n>>> [MATCH] Found Xine Event #{context[:event].device.Description}\n" end end ...

Friday, May 8, 2009

Page 56: Rhouse - Home automation is ruby ?

rhouse-ws

# Initializes Rhouseconfigure do Rhouse.initialize( :environment => ENV['RH_ENV'] || 'development', :requires_db => true, :log_level => :info,end

# -----------------------------------------------------------------------------# send a command to the dce router via a post commandpost '/cmd' do Rhouse::Command.send_raw( keys_to_symbols( params ) )end

Friday, May 8, 2009

Page 57: Rhouse - Home automation is ruby ?

ws-client

def send_cmd( command_hash ) params = command_hash.keys.map{ |k| "#{k}=#{command_hash[k]}" }.join("&") result = rhouse_service.post( '/cmd', :head => { "Content-type" => "application/x-www-form-urlencoded" }, :body => params ) unless result.http_status.index("2") == 0 text = result.http_reason raise "Error querying Rhouse web service: #{text}" end result.http_body rescue Errno::ECONNREFUSED raise "Could not contact the Rhouse web service" end

Friday, May 8, 2009

Page 58: Rhouse - Home automation is ruby ?

demo

Friday, May 8, 2009

Page 59: Rhouse - Home automation is ruby ?

references

linuxmce.orgz-wavealliance.orgmicasaverde.com

Friday, May 8, 2009

Page 61: Rhouse - Home automation is ruby ?

Thanks!

Friday, May 8, 2009

Page 62: Rhouse - Home automation is ruby ?

questions?

Friday, May 8, 2009