Remotely get variable value and execute a command

Discussion of the extending and hacking of the various Indigo components.
defsquad
Posts: 7
Joined: Sun Nov 13, 2011 6:35 pm

Remotely get variable value and execute a command

Post by defsquad »

Hi there,

Just starting to toy around with Indigo's RESTful API, and some basic scripting with Applescript right now (would like to do more Ruby scripting instead). Anyway, I'm also playing around with the following:

Both of these are on the same wired gigabit network:
HTPC -- running Indigo
Office PC -- running Proximity.app

When I walk into the office, Proximity.app recognizes my iPhone as being near, and fires off an Applescript, that right now is simply firing a curl command to Indigo to turn on the lamplinc in the office. Now, this is great, and works flawlessly, however, I'd like to get the isDaylight variable's current variable back and if it's false (e.g. it's dark outside), turn on the lamplinc, otherwise, leave the lamplinc off.

I did some searching it looks like there isn't a way to readily get the value back, other than visiting the variable's page (looking at the Indigo RESTful API docs); I'm thinking I could just use Ruby to screen scrape the value I need and return that back to my apple script to then determine whether or not to t urn on the lamp when I walk in the office with my iPhone.

Is this my only option, or are there other cleaner options for remotely getting variable values?

Thanks! I can't wait to start trying to integrate arduinos, rfid, supermechanical's twine (supermechanical.com), a pebble watch (getpebble.com), and HOPEFULLY a couple LEAP's (leapmotion.com) into the mix!
User avatar
matt (support)
Site Admin
Posts: 21476
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Remotely get variable value and execute a command

Post by matt (support) »

You can get access to the Variable's attributes either in text form:

http://127.0.0.1:8176/variables/isDaylight.txt

Or as XML:

http://127.0.0.1:8176/variables/isDaylight.xml

Another option would be to have the AppleScript remotely target your Indigo Mac. That can be a bit buggy though -- I've seen problems with it if the OS X versions running on each Mac aren't the same. I think it was just a major version difference, like OS X 10.5 not working well with 10.6.
Image
defsquad
Posts: 7
Joined: Sun Nov 13, 2011 6:35 pm

Re: Remotely get variable value and execute a command

Post by defsquad »

thanks matt, do you recommend one way over another for remotely getting the value from that returned text (e.g. applescript, ruby, python, perl, php, good ole shell scripting, other)?

i tried it with ruby, but am having a heck of a time because of the digest authorization; finding the right ruby gem combination for authorizing remotely to the indigo web server to get that variable.txt has been a pain.

here's where i ran into issues using ruby (granted, not directly related to indigo, but related to digest authorization)..
http://stackoverflow.com/questions/1077 ... igest-auth

the crazy thing is, i can use curl just fine to set the device on/off states, with that --digest flag.

anyway, thanks for any help you can provide!
defsquad
Posts: 7
Joined: Sun Nov 13, 2011 6:35 pm

Re: Remotely get variable value and execute a command

Post by defsquad »

any additional thoughts on this one matt? do you have any personal recommendations for coding the GET of the variable html file and parsing it? thanks much.
defsquad
Posts: 7
Joined: Sun Nov 13, 2011 6:35 pm

Re: Remotely get variable value and execute a command

Post by defsquad »

managed to get it working; landed on the httpclient ruby gem; much easier to integrate working digest auth compared to the other gem i was using.

the next issue is getting my applescript to run the ruby file... which it does, however the problem is that for some reason my rubygem environment won't see the fact that i've installed the gems i need globally. *sigh*

oh well, that's not an indigo issue, just updating this post. if anyone needs the updated ruby code, it's available at the SO link i originally posted above.
defsquad
Posts: 7
Joined: Sun Nov 13, 2011 6:35 pm

Re: Remotely get variable value and execute a command

Post by defsquad »

.... and with some stupid applescript trickery; here it is all running via the app "Proximity" and it's ability to only fire off applescripts..

Code: Select all

do shell script "~/.rvm/bin/ruby /scripts/bt_office_proximity-near.rb"
i hope this helps others to use ruby and applescript controlling a remote indigo server with a bluetooth proximity app on your local desktop. :D
Last edited by defsquad on Tue May 29, 2012 9:14 pm, edited 1 time in total.
User avatar
matt (support)
Site Admin
Posts: 21476
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Remotely get variable value and execute a command

Post by matt (support) »

I might not be understanding the problem requirements fully, but note that you can use the RESTful APIs to execute an Action Group as well. So you could have it just execute an Action Group which then contains the AppleScript (or better yet, python) embedded script that actually has the logic you want.
Image
defsquad
Posts: 7
Joined: Sun Nov 13, 2011 6:35 pm

Re: Remotely get variable value and execute a command

Post by defsquad »

Good morning Matt,

Thanks for the response. Yeah, I may not have painted the whole picture of what I was after. The problem is that the bluetooth proximity application I'm using on my office computer can only launch applescripts, however I couldn't seem to get the isDaylight variable via an applescript, only from parsing it via a ruby script. So basically I'm executing the ruby script via terminal via an applescript. *whew*

Very convoluted way to do what I'm wanting to do. I'll definitely investigate action pages (I'm only scratching the surface of what Indigo offers, as I'm slowly building out my home automation setup).

I definitely appreciate the active interaction and support with the community; i also appreciate the fact that other apps and devices can interact with Indigo, not just supported Insteon and x10 devices.

Regards.
User avatar
jay (support)
Site Admin
Posts: 18420
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Remotely get variable value and execute a command

Post by jay (support) »

Code: Select all

tell application "IndigoServer"
    set varValue to value of variable "isDaylight"
end tell
If your Indigo server is on a remote machine:

Code: Select all

tell application "IndigoServer" of machine "eppc://USERNAME:PASSWORD@IPADDRESS"
    set varValue to value of variable "isDaylight"
end tell
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
defsquad
Posts: 7
Joined: Sun Nov 13, 2011 6:35 pm

Re: Remotely get variable value and execute a command

Post by defsquad »

bwahaha, that's easy enough. *sigh* oh well, was still fun hacking around with applescript + ruby to make it happen :D
Post Reply

Return to “Hacking”