We have moved at community.getvera.com

Author Topic: Guide for setting up a Siri Proxy server to control Vera  (Read 41218 times)

Offline Rusty2192

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #15 on: March 25, 2013, 09:32:32 pm »
I've used this SiriProxy build for the raspberry pi for a couple different installs

http://sourceforge.net/projects/siriproxyrpi/

I decided to pick up a Raspberry Pi instead of running a huge desktop 24/7.  I used this build and it is running and responds to the test.  The only problem is, I can't find the siriproxy-example.rb file  :o  I don't seem to have a ~/SiriProxy directory, but the file must be somewhere.

Edit: I found it.  Its located at /usr/local/rvm/gems/ruby-2.0.0-p0/gems/siriproxy-0.5.2/plugins/siriproxy-example/lib/siriproxy-example.rb 

Edit 2: Got it working.
« Last Edit: March 27, 2013, 08:09:14 pm by Rusty2192 »

Offline knewmania

  • Sr. Member
  • ****
  • Posts: 255
  • Karma: +0/-0
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #16 on: March 29, 2013, 11:16:48 am »
I have SiriProxy running and can control most of my devices (on/off, lock/unlock, etc) using simple open http TargetValue= commands in the siriproxy-example.rb file.

I figured out how to associate multiple voice commands for a single action by separating the Listen_for variable with a pipe. I did this so that my wife and I (mostly the wife) don't have to memorize the exact command required to activate a device.

example: (listen_for /Unlock Front Door|Unlock Patio|Unlock Foyer/i do).

I think I saw a video showing someone querying Siri for device status. Something like 'Is the front door locked?', to which Siri responded 'The front door is locked'. Anyone have any idea if this can be accomplished using the simple methods I currently use in the siriproxy-example.rb file?

Thanks in advance for any assistance.
Vera 2. UI 1.5.622 / Vera 3. UI 1.7.760

Offline MDoc

  • Jr. Member
  • **
  • Posts: 76
  • Karma: +3/-3
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #17 on: April 06, 2013, 10:52:31 pm »
Sorry @knewmania,  Lost track of this.

I think I saw a video showing someone querying Siri for device status. Something like 'Is the front door locked?', to which Siri responded 'The front door is locked'. Anyone have any idea if this can be accomplished using the simple methods I currently use in the siriproxy-example.rb file?

Here's what I used to check door status: (Remember to change your IP Address and Device Number)

   #### FRONT DOOR LOCK#####
   listen_for /\bfront door (locked|unlocked)/i do |state|
   response = open("http://Http://YOUR_IP_ADDRESS:3480/data_request?id=variableget&DeviceNum=18&serviceId=urn:micasaverde-com:serviceId:DoorLock1&Variable=Status")
   if(response.read[0] == "1")
      say "The Front door is locked."
   else
     response = ask "The front door is unlocked.  Would you like me to lock it for you?"
     if(response =~ /yes\b/i) #process their response
        open('http://YOUR_IP ADDDRESS:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget&newTargetValue=1&DeviceNum=18') 
        say "OK, I've locked the front door."
     else
       say "OK.  No problem!"
     end
   end   
  request_completed
  end

Offline knewmania

  • Sr. Member
  • ****
  • Posts: 255
  • Karma: +0/-0
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #18 on: April 06, 2013, 10:55:47 pm »
Sorry @knewmania,  Lost track of this.

No worries, and thank you very much for the help. I will give this a shot as soon as I get some time to tinker.

Vera 2. UI 1.5.622 / Vera 3. UI 1.7.760

Offline wseverino

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 854
  • Karma: +0/-0
  • Da Man, Da Myth, Da Legend - in his own mind!
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #19 on: April 18, 2013, 01:53:53 pm »
just got my model B Raspberry Pi, time to get SiriProxy up and running!
My ZWave Network: Too friggin big to list.....

Offline wseverino

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 854
  • Karma: +0/-0
  • Da Man, Da Myth, Da Legend - in his own mind!
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #20 on: April 19, 2013, 04:15:37 pm »
Code: [Select]
#### FRONT DOOR LOCK#####
   listen_for /is the front door locked/i do |state|
   response = open("http://192.168.x.x:3480/data_request?id=variableget&DeviceNum=40&serviceId=urn:micasaverde-com:serviceId:DoorLock1&Variable=Status")
   if(response.read[0] == "1")
      say "The Front door is locked."
   else
     response = ask "The front door is unlocked.  Would you like me to lock it for you?"
     if(response =~ /yes/i) #process their response
        open('http://192.168.x.x:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget&newTargetValue=1&DeviceNum=40') 
        say "OK, I've locked the front door."
     else
       say "OK.  No problem!"
     end
   end   
  request_completed
  end
My ZWave Network: Too friggin big to list.....

Offline knewmania

  • Sr. Member
  • ****
  • Posts: 255
  • Karma: +0/-0
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #21 on: April 19, 2013, 06:09:16 pm »
Thank you @MDoc & @wseverino. Works like a champ.
Vera 2. UI 1.5.622 / Vera 3. UI 1.7.760

Offline spudjr

  • Full Member
  • ***
  • Posts: 133
  • Karma: +2/-0
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #22 on: April 20, 2013, 12:19:14 am »
Added the following to my siriproxy-example.rb

 listen_for /Living room temperature/i do

  ltemp = HTTParty.get("http://192.168.100.53:49451/data_request?id=lu_variableget&DeviceNum=23&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature")
    say "Living Rouom temperature #{ltemp} degrees."
    request_completed
  end

Get an error message that the plugin crashed. Siriproxy output is

[Info - Plugin Manager] Processing 'Living room temperature'
[Info - Plugin Manager] Processing plugin Example
[Info - Plugin Manager] Matches (?i-mx:Living room temperature)
[Info - Plugin Manager] Applicable states:
[Info - Plugin Manager] Current state:
[Info - Plugin Manager] Matches, executing block
[Info - Plugin Manager] Plugin Crashed: uninitialized constant SiriProxy::Plugin::Example::HTTParty


any ideas whats causing the crash?

thanks

Offline jumper4000

  • Full Member
  • ***
  • Posts: 169
  • Karma: +18/-136
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #23 on: April 20, 2013, 05:56:29 am »
Added the following to my siriproxy-example.rb

 listen_for /Living room temperature/i do

  ltemp = HTTParty.get("http://192.168.100.53:49451/data_request?id=lu_variableget&DeviceNum=23&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature")
    say "Living Rouom temperature #{ltemp} degrees."
    request_completed
  end

Try this instead. works for me -

listen_for /\b(What is|give me)(?: the)? living room temperature?/i do |state|
  ltemp = open("http://192.168.100.53:49451/data_request?id=lu_variableget&DeviceNum=23&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature")
    say "The living Room temperature is #{ltemp.read} degrees."
    request_completed
  end

Offline spudjr

  • Full Member
  • ***
  • Posts: 133
  • Karma: +2/-0
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #24 on: April 20, 2013, 11:56:39 am »
That works great. thanks for the quick reply.

Offline wseverino

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 854
  • Karma: +0/-0
  • Da Man, Da Myth, Da Legend - in his own mind!
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #25 on: April 20, 2013, 01:42:57 pm »
Anyone have any examples for controlling the non-wifi thermostats such as the trane thermostat?
My ZWave Network: Too friggin big to list.....

Offline wseverino

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 854
  • Karma: +0/-0
  • Da Man, Da Myth, Da Legend - in his own mind!
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #26 on: April 30, 2013, 09:47:12 pm »
If Anyone is interested I figured out the themrostats. This allows you to use one routine for all your thermostats without having to do an entry for each one. Code is below:

Code: [Select]
require 'cora'
require 'siri_objects'
require 'pp'
require 'open-uri'

class SiriProxy::Plugin::Example < SiriProxy::Plugin
  def initialize(config)
    @url = "http://192.168.0.20:3480"
    @thermostats = {'bonus room' => '66', 'master bedroom' => '142', 'living room'=>'53'}
   end

Code: [Select]
  # Set Thermostat Cool

  listen_for /Set air.*(bonus room|master bedroom).*([0-9,].*[0-9])/i do | src, lvl|
    vera_SetAirTemp(src,lvl)
  end

  # Set Thermostat heat

  listen_for /Set heat.*(bonus room|master bedroom).*([0-9,].*[0-9])/i do | src, lvl|
    vera_SetHeatTemp(src,lvl)
  end

Code: [Select]
########################################## TSTAT DEF ##########################################
   def vera_SetAirTemp(thermostat, command)
      begin
          signal = command
          service = "&serviceId=urn:upnp-org:serviceId:TemperatureSetpoint1_Cool&action=SetCurrentSetpoint&NewCurrentSetpoint"
          say "Setting your thermostat in " + thermostat + " to " + command + " degrees"
          open(@url + '/' + 'data_request?id=lu_action&DeviceNum' + '=' + @thermostats[thermostat] + service + '=' + signal)
        request_completed
      end
    end

    def vera_SetHeatTemp(thermostat, command)
      begin
          signal = command
          service = "&serviceId=urn:upnp-org:serviceId:TemperatureSetpoint1_Heat&action=SetCurrentSetpoint&NewCurrentSetpoint"
          say "Setting your thermostat in " + thermostat + " to " + command + " degrees"
          open(@url + '/' + 'data_request?id=lu_action&DeviceNum' + '=' + @thermostats[thermostat] + service + '=' + signal)
        request_completed
      end
    end
« Last Edit: April 30, 2013, 09:51:27 pm by wseverino »
My ZWave Network: Too friggin big to list.....

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #27 on: May 04, 2013, 05:52:58 pm »
OK, I now have a Raspberry PI set up and running Siri Proxy

I can say "Test Siri Proxy" and it reliably advises me that "Sire Proxy Is Up & Running"

However when I tried to copy Jumper4000's example to ( /usr/local/rvm/gems/ruby-2.0.0-p0/gems/siriproxy-0.5.2/plugins/siriproxy-example/lib/siriproxy-example.rb  ) for Siri to say a temperature reading - it did not work? I changed the port and I even tried to make it a bit simper - but no luck = any ideas ?

#Vera
  listen_for /What is Ben's room temperature/i do
  ltemp = open("http://192.168.1.234:3480/data_request?id=lu_variableget&DeviceNum=42&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature")
    say "Ben's Room is at #{ltemp.read} degrees."
    request_completed
  end

Also - have people completely cleaned out the siriproxy-example.rb or do people have more examples they can share ?

In fact anything i add to that file is not handled by Siri !!!!!
« Last Edit: May 04, 2013, 06:01:31 pm by parkerc »

Offline wseverino

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 854
  • Karma: +0/-0
  • Da Man, Da Myth, Da Legend - in his own mind!
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #28 on: May 04, 2013, 06:17:56 pm »
Parker - I use the /home/pi/SiriProxy/plugins/siriproxy-example/lib/siriproxy-example.rb

Below is the code I am using. I have control of the door locks, thermostats, alarm system, lights, and sprinkler system. just copy it into your siriproxy-example. make sure to add your ip address where you see xxx.xxx.xxx.xxx and change your device name and device ID numbers.

Code: [Select]
require 'cora'
require 'siri_objects'
require 'pp'
require 'open-uri'

########################################################
# Vera Voice Control plugin for Siri Proxy on Raspberry Pi
#
# Version: 0.0.1
# Date: 4/30/2013
# By: WSeverino
#
# ########################################################

class SiriProxy::Plugin::Example < SiriProxy::Plugin
  def initialize(config)
    @url = "http://xxx.xxx.xxx.xxx:3480"
    @switches =  {'backyard spot light'=>'21','porch light'=>'22','bonus room lamp A'=>'167','bonus room lamp B'=>'4'}
    @thermostats = {'bonus room' => '66', 'master bedroom' => '142', 'living room'=>'53'}
    @alarm = {'Alarm Panel' => '157'}
    @irrigation = {'sprinklers' => '153'}
    @scenes = {'living room lamps on' => '29', 'living room lamps off' => '30'}
   
  end
 
  listen_for /test home automation/i do
      say "Vera plugin for Siri Proxy is up and running!"
    request_completed
  end
  ######################################### scenes #########################################
  listen_for /(on|off).*(living room lamps on|living room lamps off)/i do |cmd, src|
    vera_scene(src,cmd)
  end

  def vera_scene(scene, command)
    begin
      case command
        when "on"
          say "Turning on your " + scene + " scene."
        when "off"
          say "Turning off your " + scene + " scene."
        else
          say "Sorry I didn't get that, could you repeat that?"
        end
      open(@url + '/' + 'data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum' + '=' + @scenes[scene])
      request_completed
     end
  end

  ######################################### Lights #########################################
  # Test if the Vera pugin for Siri Proxy is working
  # Turn on/off a device scenario A
  listen_for /(on|off).*(backyard spot light|porch light|bonus room lamp A|bonus room lamp B|bonus room overhead| bonus TV|foyer chandolier|foyer lamp|front porch|garage overhead|garage spot light|breakfast nook|bar lights|kitchen overhead|under cabinet|laundry room|downstairs hallway|master bath sconce|master bath overhead|Alexandra|Bill|master overhead|Nicholas overhead|Sophie overhead|Sophie lamp|Sophie closet|upstairs hallway|stairwell|updstairs hall lamp)/i do |cmd, src|
    vera_switch(src,cmd)
  end

  # Dim a device scenario A
  listen_for /(dim).*(bonus room overhead).*([0-9,].*[0-9])/i do |cmd, src, lvl|
    vera_switch(src,lvl)
  end

   def vera_switch(switch, command)
    begin
      case command
        when "on"
          signal = "1"
          service = "&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue"
          say "Turning on your " + switch + " light."
        when "off"
          signal = "0"
          service = "&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue"
          say "Turning off your " + switch + " light."
        else
          signal = command
          service = "&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget"
          say "Dimming your " + switch + " light to " + command + "%"
        end
        open(@url + '/' + 'data_request?id=lu_action&output_format=json&DeviceNum' + '=' + @switches[switch] + service + '=' + signal)
        request_completed
    end
  end

######################################### Irrigation System#####################################
  listen_for /(on|off).*(sprinklers)/i do |cmd, src|
    vera_sprinkler(src,cmd)
  end

  def vera_sprinkler(sprinkler, command)
    begin
      case command
        when "on"
          signal = "1"
          service = "&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue"
          say "Turning on your " + sprinkler
        when "off"
          signal = "0"
          service = "&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue"
          say "Turning off your " + sprinkler
        else
          say "Unexpected Error! - Plugin Crash"
        end
        open(@url + '/' + 'data_request?id=lu_action&output_format=json&DeviceNum' + '=' + @irrigation[sprinkler] + service + '=' + signal)
        request_completed
      end
  end
######################################### Alarm System #########################################
listen_for /(Arm|Disarm|Stay).*(Alarm Panel)/i do |cmd, src|
    vera_alarm(src,cmd)
end

def vera_alarm(alarm, command)
  begin
    case command
      when "Arm"
          signal = "Armed"
          service = "&serviceId=urn:micasaverde-com:serviceId:AlarmPartition2&action=RequestArmMode&State"
          say "Arming your " + alarm
        when "Stay"
          signal = "Stay"
     service = "&serviceId=urn:micasaverde-com:serviceId:AlarmPartition2&action=RequestArmMode&State"
          say "Placing your  " + alarm + " in stay mode."
        else
          signal = "Disarmed"
          service = "&serviceId=urn:micasaverde-com:serviceId:AlarmPartition2&action=RequestArmMode&State"
          say "Disarming your " + alarm
        end
        open(@url + '/' + 'data_request?id=lu_action&output_format=json&DeviceNum=157' + service + '=' + signal + '&PINCode=6514')
        request_completed
  end
end

######################################### Door Loccks #########################################
   listen_for /is the front door locked/i do |state|
   response = open("http://xxx.xxx.xxx.xxx:3480/data_request?id=variableget&DeviceNum=40&serviceId=urn:micasaverde-com:serviceId:DoorLock1&Variable=Status")
   if(response.read[0] == "1")
      say "The Front door is locked."
   else
     response = ask "The front door is unlocked.  Would you like me to lock it for you?"
     if(response =~ /yes/i) #process their response
        open('http://xxx.xxx.xxx.xxx:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget&newTargetValue=1&DeviceNum=40') 
        say "OK, I've locked the front door."
     else
       say "OK.  No problem!"
     end
   end   
  request_completed
  end

###Unlock Foyer Deadbolt
  listen_for /Unlock Front door/i do
      open("http://xxx.xxx.xxx.xxx:3480/data_request?id=lu_action&output_format=xml&DeviceNum=40&serviceId=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget&newTargetValue=0")
    request_completed #always complete your request! Otherwise the phone will "spin" at the user!
  end

#### Laudry Room DOOR LOCK#####
   listen_for /is the laundry room door locked/i do |state|
   response = open("http://xxx.xxx.xxx.xxx:3480/data_request?id=variableget&DeviceNum=41&serviceId=urn:micasaverde-com:serviceId:DoorLock1&Variable=Status")
   if(response.read[0] == "1")
      say "The Laundry Room door is locked."
   else
     response = ask "The Laundry Room door is unlocked.  Would you like me to lock it for you?"
     if(response =~ /yes/i) #process their response
        open('http://xxx.xxx.xxx.xxx:3480/data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget&newTargetValue=1&DeviceNum=41') 
        say "OK, I've locked the Laundry Room door."
     else
       say "OK.  No problem!"
     end
   end   
  request_completed
  end

#### Back DOOR LOCK#####
   listen_for /is the Back door locked/i do |state|
   response = open("http://xxx.xxx.xxx.xxx:3480/data_request?id=variableget&DeviceNum=42&serviceId=urn:micasaverde-com:serviceId:DoorLock1&Variable=Status")
   if(response.read[0] == "1")
      say "The Back door is locked."
   else
     response = ask "The back door is unlocked. You need to get off your butt and lock it."
    end   
  request_completed
  end
########################################## Thermostats #########################################
  # Set Thermostat Cool

  listen_for /Set air.*(bonus room|master bedroom).*([0-9,].*[0-9])/i do | src, lvl|
    vera_SetAirTemp(src,lvl)
  end

  listen_for /Set heat.*(bonus room|master bedroom).*([0-9,].*[0-9])/i do | src, lvl|
    vera_SetHeatTemp(src,lvl)
  end

  def vera_SetAirTemp(thermostat, command)
      begin
          signal = command
          service = "&serviceId=urn:upnp-org:serviceId:TemperatureSetpoint1_Cool&action=SetCurrentSetpoint&NewCurrentSetpoint"
          say "Setting your thermostat in " + thermostat + " to " + command + " degrees"
          open(@url + '/' + 'data_request?id=lu_action&DeviceNum' + '=' + @thermostats[thermostat] + service + '=' + signal)
        request_completed
      end
  end

  def vera_SetHeatTemp(thermostat, command)
      begin
          signal = command
          service = "&serviceId=urn:upnp-org:serviceId:TemperatureSetpoint1_Heat&action=SetCurrentSetpoint&NewCurrentSetpoint"
          say "Setting your thermostat in " + thermostat + " to " + command + " degrees"
          open(@url + '/' + 'data_request?id=lu_action&DeviceNum' + '=' + @thermostats[thermostat] + service + '=' + signal)
        request_completed
      end
  end
  ###################################################################################################
end
« Last Edit: May 06, 2013, 12:04:15 pm by wseverino »
My ZWave Network: Too friggin big to list.....

Offline spudjr

  • Full Member
  • ***
  • Posts: 133
  • Karma: +2/-0
Re: Guide for setting up a Siri Proxy server to control Vera
« Reply #29 on: May 04, 2013, 07:26:10 pm »
Parkerc

You may want to try something simple like this

 listen_for /Fireplace on|turn fireplace on|set living room thermostat heat/i do
    say "I will rub the sticks and heat up the living room"

  open('http://192.168.100.53:3480/data_request?id=lu_action&output_format=xml&DeviceNum=23&serviceId=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=HeatOn')
    request_completed
  end

  listen_for /Fireplace off|turn fireplace off|Set living room thermostat off/i do
    say "Putting out the fire"

  open('http://192.168.100.53:3480/data_request?id=lu_action&output_format=xml&DeviceNum=23&serviceId=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=Off')
    request_completed
  end

#Set FirePlace Temperature
  listen_for /Set living room heat temperature to ([0-9,]*[0-9])%/i do |temp|
    say "Setting fireplace flame to: #{temp} degrees."

  open("http://192.168.100.53:3480/data_request?id=lu_action&output_format=xml&DeviceNum=23&serviceId=urn:upnp-org:serviceId:TemperatureSetpoint1_Heat&action=SetCurrentSetpoint&NewCurrentSetpoint=#{temp}")
    request_completed
  end

#To get the Fireplace Thermostate Present Temperature
  listen_for /\b(What is|give me)(?: the)? temperature of living room thermostat?/i do |state|

    ltemp = open("http://192.168.100.53:49451/data_request?id=lu_variableget&DeviceNum=23&serviceId=urn:upnp-org:serviceId:TemperatureSensor1&Variable=CurrentTemperature")

    say "Living Room temperature #{ltemp.read} degrees."
    request_completed
  end

Adjust your IP address to match your controller