Author Topic: Does VoxCommando have an API?  (Read 3615 times)

0 Members and 3 Guests are viewing this topic.

macrho

  • $upporter
  • Contributor
  • *****
  • Posts: 75
  • Karma: 0
    • View Profile
Does VoxCommando have an API?
« on: January 20, 2014, 08:03:58 PM »
I can use VoxCommando to control a bunch of different programs: Vera, XBMC, EventGhost but.. is there a way for me to control VoxCommando from another program? I have Vera for a home automation controller, I'd like to trigger VoxCommand off of a scene on Vera. I'm watching TV and a trigger fires on Vera, say sunset and VC announces this to me or my camera sensor is tripped and Vera sends a request to VC to announce someone is outside..

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Does VoxCommando have an API?
« Reply #1 on: January 20, 2014, 08:34:34 PM »
VoxCommando will trigger an event any time a scene is activated in Vera and any time the status of a device changes.

If that is not enough for you then yes.  You can send commands to VoxCommando by many different methods.  UDP, TCP, HTTP, or command line.  To use TCP or HTTP you need to enable and configure the TCP plugin.

From  Vera the simplest method is to use UDP, but if you just want to have VC do something when a Vera Scene is triggered, it makes more sense to use the Vera events that are already being triggered by the Vera plugin.

If you want to send a UDP message to VC from Vera Lite here's how you can do it.  Go to Vera, Apps, Develop Apps, Edit Startup LUA.  Put this function in there:

Code: [Select]
function sendVC(strMessage)
   local socket = require "socket"
   local udp = socket.try(socket.udp())
   broadcast_ip = '255.255.255.255'
   assert(udp:setoption("broadcast", true))   
   socket.try(udp:sendto(strMessage, '255.255.255.255', 33000))
end -- sendVC

If you want to change the port you can but VC listens on port 33000 by default.  If you want to target a specific PC instead of doing a UDP broadcast, then change the 255.255.255.255 to the IP of your PC.

Now from a scene in vera, or in a trigger, or anywhere you can enter luup or lua you can send a message to VC like this:

Code: [Select]
sendVC("tts.speak&&hello there")
You can send any action to VC using the format

Code: [Select]
action&&param1&&parm2&&param3
you can trigger an event using

Code: [Select]
event&&eventname&&payload1&&payload2
and you can trigger a voice command like this:

Code: [Select]
vc.tellvox&&pay attention
If you are using another method of sending messages to VC the format is the same, it is only the delivery method that changes.

EASY!  :yay

WIKI DOCUMENTATION ON VC API: http://voxcommando.com/mediawiki/index.php?title=API_Application_Programming_Interface
« Last Edit: February 04, 2015, 09:38:00 AM by nime5ter »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Does VoxCommando have an API?
« Reply #2 on: January 20, 2014, 09:46:46 PM »
I'm watching TV and a trigger fires on Vera, say sunset and VC announces this to me or my camera sensor is tripped and Vera sends a request to VC to announce someone is outside..

James mentions above the concept of events, which are exactly what you're referring to -- events that occur in other programs or hardware devices, that can trigger VC commands (http://voxcommando.com/mediawiki/index.php?title=Events).

If you haven't yet used Vera (whether it's a scene or a device event) to trigger VC commands, I  recommend watching Fireside Chat #3:


It's pretty goofy, but I still think that it covers a lot of functionality that even long-time VC users sometimes haven't discovered.

(If you have a really short attention span, you can jump to around the six-minute mark where we start to build the "intruder alert" command, but it may make more sense to start at the beginning.)

... Still, cool to learn about all these ways to communicate with VC. Always something to learn around here.
« Last Edit: January 20, 2014, 10:32:06 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

macrho

  • $upporter
  • Contributor
  • *****
  • Posts: 75
  • Karma: 0
    • View Profile
Re: Does VoxCommando have an API?
« Reply #3 on: January 21, 2014, 06:42:24 AM »
Thank you both for the very detailed response and awesome examples!
I'll be working through some scenarios this coming weekend.
I have Vera  3now turning on my receiver/tv upon arrival home and depending on mood either playing a smart playlist on XBMC (music I rated as a 4 or 5; just love the XBMC visualization for music and lyrics/artwork) or switching to a news channel. Now a third scene will be having VC read some information to me: weather, temperatures via my netatmo, etc

VC keeps getting better and better!