url return Get/POST to python/indigo variables

Posted on
Tue Nov 15, 2016 11:56 am
Albatros offline
Posts: 132
Joined: Feb 07, 2015

url return Get/POST to python/indigo variables

I am trying to get values from my Daikin Airco into Indigo variables. I know how code this with a json return but result from the open url is not json I believe:

Url
http://192.168.1.XX/aircon/get_sensor_info

Result
ret=OK,htemp=23.0,hhum=-,otemp=13.0,err=0,cmpfreq=22

I tried this:

import urllib2

response = urllib2.urlopen('http://192.168.1.XX/aircon/get_sensor_info')
html = response.read()
ret = {'ret' : [0]}

indigo.variable.updateValue(1262870391,value=ret)

Any ideas?

Posted on
Tue Nov 15, 2016 8:34 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: url return Get/POST to python/indigo variables

That's definitely not JSON. Check out python's split() function.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Dec 23, 2016 4:23 am
Albatros offline
Posts: 132
Joined: Feb 07, 2015

Re: url return Get/POST to python/indigo variables

Thanks much for the pointers. With the help from DaveL17. Not as shell but inside Indigo.

viewtopic.php?f=148&t=15137&start=90

Got HTML response into Indigo variable working with this script in Indigo. Now I can use a script to automate the heating based upon the daikin info.

Use Case: automating heating my house with my Daikin Airco (Heatpump). Result: using the heatpump results in decrease in energy spending of 700 euro's a year.


==========================================================================

#get data in HTMl Response from Daikin HVAC

import urllib2

urlReturned = urllib2.urlopen('http://XX.XXX.X.XX/aircon/get_sensor_info')

data_getStatus = urlReturned.read()


#transform HTMl Response in JSON format
# Split the result into bits
split_response = data_getStatus.split(',')
print(split_response)

# Split the bits into variable/value pairs
new_list = []
for element in split_response:
new_list.append(element.split('='))
print(new_list)

# Convert the variable/value pairs into something json-y
new_dict = {}
for element in new_list:
new_dict[element[0]] = element[1]
print(new_dict)


#get new json string variables to python variables

htemp=str(new_dict['htemp'])
otemp=str(new_dict['otemp'])


#update indigo variables
indigo.variable.updateValue(1262870391, ((htemp)))
indigo.variable.updateValue(1460457655, ((otemp)))

Posted on
Fri Dec 23, 2016 5:10 am
DaveL17 offline
User avatar
Posts: 6758
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: url return Get/POST to python/indigo variables

Glad to hear that you got it working. If you want to see any information reported in the Indigo log, you should change the print statements to indigo.server.log() statements; otherwise, you can delete or comment out those lines.

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

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 8 guests