EDIT: Update - All code is posted here: https://github.com/msreynolds/siriproxy-violet/
If you can get SiriProxy running, you should be able to paste the code below into siriproxy-example.rb, rebuild the gem, re-bundle, and run siriproxy.
Modify the line:
indigoresturl="http://yourcomputer.local:8176/"
This plugin uses a few siriproxy custom phrase listeners and curl to call the restful api of Indigo. You should be able to easily tailor this example to suit your own needs. If anyone wants to help clean this up, keep adding functionality, and post the updates here, that would be great!
Enjoy!
Matt
- Code: Select all
######
# Mountain Labs, LLC
# mtnlabs.com
# Author: Matthew Reynolds
# matt at mtnlabs dot com
# SiriProxy plugin "Violet" for controlling your Indigo Home Automation server
######
require 'cora'
require 'siri_objects'
require 'pp'
require 'uri'
class SiriProxy::Plugin::Violet < SiriProxy::Plugin
indigoresturl="http://yourcomputer.local:8176/"
def initialize(config)
#if you have custom configuration options, process them here!
end
#get the user's location and display it in the logs
#filters are still in their early stages. Their interface may be modified
filter "SetRequestOrigin", direction: :from_iphone do |object|
puts "[Info - User Location] lat: #{object["properties"]["latitude"]}, long: #{object["properties"]["longitude"]}"
#Note about returns from filters:
# - Return false to stop the object from being forwarded
# - Return a Hash to substitute or update the object
# - Return nil (or anything not a Hash or false) to have the object forwarded (along with any
# modifications made to it)
end
listen_for /test siri proxy/i do
# test greeting
say "It's Siri Proxy in the house!"
request_completed
end
listen_for /set thermostat to ([0-9]*[0-9])/i do |degrees|
degrees.strip!
ack = ask "You want me to set the thermostat to "+degrees+" degrees, correct?"
if (ack =~ /yes/i or ack =~ /correct/i or ack =~ /that's right/i)
begin
url=indigoresturl+"devices/thermostat"
curlrequest="curl -X PUT -d setpointHeat=#{degrees} "+url
puts curlrequest
system(curlrequest)
rescue Exception=>e
puts e.exception
say "I was unable to complete your request"
else
say "Operation succeeded"
ensure
request_completed
end
else
say "Operation aborted"
request_completed
end
end
listen_for /set brightness of ([a-z 0-9]*)/i do |devicename|
devicename.strip!
brightness = ask "To what value?"
brightness.strip!
ack = ask "You want me to set the brightness of "+devicename+" to "+brightness+", correct?"
if (ack =~ /yes/i or ack =~ /correct/i or ack =~ /right/i or ack =~ /affirmative/i)
begin
devicename=URI::encode(devicename)
brightness=URI::encode(brightness)
url=indigoresturl+"devices/#{devicename}"
curlrequest="curl -X PUT -d brightness=#{brightness} "+url
puts curlrequest
system(curlrequest)
rescue Exception=>e
puts e.exception
say "I was unable to complete your request"
else
say "Operation succeeded"
ensure
request_completed
end
else
say "Operation aborted"
request_completed
end
end
#indigo native functions
listen_for /toggle ([a-z 1-9]*)/i do |devicename|
devicename.strip!
ack = ask "You want me to toggle "+devicename+", correct?"
if (ack =~ /yes/i or ack =~ /correct/i or ack =~ /that's right/i)
begin
devicename=URI::encode(devicename)
url=indigoresturl+"devices/#{devicename}"
curlrequest="curl -X PUT -d toggle=1 "+url
puts curlrequest
system(curlrequest)
rescue Exception=>e
puts e.exception
say "I was unable to complete your request"
else
say "Operation succeeded"
ensure
request_completed
end
else
say "Operation aborted"
request_completed
end
end
listen_for /turn on ([a-z 1-9]*)/i do |devicename|
devicename.strip!
ack = ask "You want me to turn on "+devicename+", correct?"
if (ack =~ /yes/i or ack =~ /correct/i or ack =~ /that's right/i)
begin
devicename=URI::encode(devicename)
url=indigoresturl+"devices/#{devicename}"
curlrequest="curl -X PUT -d isOn=1 "+url
puts curlrequest
system(curlrequest)
rescue Exception=>e
puts e.exception
say "I was unable to complete your request"
else
say "Operation succeeded"
ensure
request_completed
end
else
say "Operation aborted"
request_completed
end
end
listen_for /turn off ([a-z 0-9]*)/i do |devicename|
devicename.strip!
ack = ask "You want me to turn off "+devicename+", correct?"
if (ack =~ /yes/i or ack =~ /correct/i or ack =~ /that's right/i)
begin
devicename=URI::encode(devicename)
url=indigoresturl+"devices/#{devicename}"
curlrequest="curl -X PUT -d isOn=0 "+url
puts curlrequest
system(curlrequest)
rescue Exception=>e
puts e.exception
say "I was unable to complete your request"
else
say "Operation succeeded"
ensure
request_completed
end
else
say "Operation aborted"
request_completed
end
end
listen_for /execute ([a-z 0-9]*)/i do |actionname|
actionname.strip!
ack = ask "You want me to execute the action group: "+actionname+", correct?"
if (ack =~ /yes/i or ack =~ /correct/i or ack =~ /right/i)
begin
actionname=URI::encode(actionname)
url=indigoresturl+"actions/#{actionname}"
curlrequest="curl -X EXECUTE "+url
puts curlrequest
system(curlrequest)
rescue Exception=>e
puts e.exception
say "I was unable to complete your request"
else
say "Operation succeeded"
ensure
request_completed
end
else
say "Operation aborted"
request_completed
end
end
end