Remotely get variable value and execute a command
Remotely get variable value and execute a command
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!
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!
- 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
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.
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.
Re: Remotely get variable value and execute a command
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!
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!
Re: Remotely get variable value and execute a command
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.
Re: Remotely get variable value and execute a command
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.
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.
Re: Remotely get variable value and execute a command
.... and with some stupid applescript trickery; here it is all running via the app "Proximity" and it's ability to only fire off applescripts..
i hope this helps others to use ruby and applescript controlling a remote indigo server with a bluetooth proximity app on your local desktop.
Code: Select all
do shell script "~/.rvm/bin/ruby /scripts/bt_office_proximity-near.rb"
Last edited by defsquad on Tue May 29, 2012 9:14 pm, edited 1 time in total.
- 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
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.
Re: Remotely get variable value and execute a command
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.
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.
- 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
Code: Select all
tell application "IndigoServer"
set varValue to value of variable "isDaylight"
end tell
Code: Select all
tell application "IndigoServer" of machine "eppc://USERNAME:PASSWORD@IPADDRESS"
set varValue to value of variable "isDaylight"
end tell
Re: Remotely get variable value and execute a command
bwahaha, that's easy enough. *sigh* oh well, was still fun hacking around with applescript + ruby to make it happen