Placing the result of an http request into a variable?

Posted on
Fri Aug 26, 2016 1:16 am
mclass offline
Posts: 312
Joined: May 13, 2015
Location: Melbourne, Australia

Placing the result of an http request into a variable?

I am attempting to incorporate control of my Daikin air conditioner into Indigo.

Our ducted Daikin system is fitted with their proprietary "SkyFi" system that provides a wifi interface to Daikin's own iDevice app, that in turn can be remotely accessed via Daikin's server. The app interface is clunky, and response times are sloooow! As it appears that this interface is peculiar to Australia, it is unlikely that an Indigo plugin will be available anytime soon - and with my (non-existent) programming skills I am struggling!

With the help of others on the web, I have cracked their API, and am currently using a Python script in Action Groups to give basic Heat/Cool/Off control from an Indigo control page. A typical Heat On script looks like this:

Code: Select all
## Daikin SkyFi Heat On
import requests
url = "http://192.168.20.200:2000/set.cgi?pass=34799&p=1&t=21&m=2"
r = requests.get(url)


This methodology provides one-way control without any feedback as to the success or otherwise of the request. I have discovered that on receiving the command, the SkyFi responds with a status in the form:


Code: Select all
opmode=1&units=.&settemp=21.0&fanspeed=1&fanflags=3&acmode=2&tonact=0&toffact=0&prog=0&time=17:06&day=4&roomtemp=21&outsidetemp=11&louvre=0&zone=128&flt=0&test=0&errcode=&sensors=1



Is it possible to capture this response as an Indigo variable using additions to the current Python script? The next step would be to parse the response and set individual Indigo variables accordingly. I have searched the forums but have been unable to locate anything similar.

If anyone has an alternative approach, or snippets of code, I'd be keen to investigate. I did try Cynical Network, sending text, but although being able to connect, was unable to get SkyFi to react or respond.

Any/all assistance would be appreciated.

Regards

mclass

Posted on
Fri Aug 26, 2016 3:49 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Placing the result of an http request into a variable?

You might have a look at the requests module again to see if there's anything there that might help. Here's a nice guide.

To get the value of something into a variable is simple in Python (note that variable names are are strings, IDs are as numbers, and variable values are always strings):
Code: Select all
indigo.variable.updateValue('NameOfVariable', 'newValueGoesHere')

Once you have that working as you like we can work on the parsing.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Fri Aug 26, 2016 4:05 am
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Placing the result of an http request into a variable?

Here is a simple script to show one way to parse the response.

Code: Select all
import urlparse

response = "http://www.foo.com/?opmode=1&units=.&settemp=21.0&fanspeed=1&fanflags=3&acmode=2&tonact=0&toffact=0&prog=0&time=17:06&day=4&roomtemp=21&outsidetemp=11&louvre=0&zone=128&flt=0&test=0&errcode=&sensors=1"

parsed = urlparse.urlparse(response)

print parsed

print urlparse.parse_qs(parsed.query)['opmode'][0]
print urlparse.parse_qs(parsed.query)['units'][0]
print urlparse.parse_qs(parsed.query)['settemp'][0]

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Fri Aug 26, 2016 10:17 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Placing the result of an http request into a variable?

DaveL17 wrote:
Code: Select all
indigo.variable.updateValue('NameOfVariable', 'newValueGoesHere')


I'd recommend using the variable ID rather than the name - names can change which will break the script, but the ID is immutable... ;)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Aug 26, 2016 4:40 pm
mclass offline
Posts: 312
Joined: May 13, 2015
Location: Melbourne, Australia

Re: Placing the result of an http request into a variable?

Thanks for the input. I have now achieved getting the response into a variable - now to spend some time working on the parsing! Any coaching in this regard would be appreciated!

Mclass


Sent from my iPad using Tapatalk

Posted on
Sun Aug 28, 2016 4:24 pm
mclass offline
Posts: 312
Joined: May 13, 2015
Location: Melbourne, Australia

Re: Placing the result of an http request into a variable?

A few hours over the weekend, and a bit of "googling" has done wonders for my Python prowess :-).

Got the parsing sorted (I suspect in a fairly inelegant way!!) and can now display the Daikin's status on a prototype control page. With a little more finessing and further testing, I will post the outcome on the Daikin SkyFi post that's somewhere on this forum, so that others can be spared the time and frustration that I have experienced.

Thanks again for the coaching!

Mclass


Sent from my iPad using Tapatalk

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest