More python parsing assistance
Posted: Sat Jan 07, 2017 1:43 pm
Hi guys,
Pardon my ignorance as I am relatively new to python; I have managed to connect EG to MySQL, so far mainly for displaying info on the web interface from the media center as well as storing program/device statuses, however I have what I hope is a relatively simple question for you smart people.
Similar but slightly different to the one in this thread:
viewtopic.php?f=10&t=9118
Using the Philips Hue plugin I'm trying to retrieve the current temp from the Hue motion sensor so that I can display that on the web interface as well as to control an electric heater in the bedroom due to a temperature differential with the living room (where the thermostat is located). There is an action within the plugin to get this however it is returned with a lot of other information that I am not interested in, like this:-
I'm only interested in the number after '{u'temperature':' in this case '2110'
I've tried a few things in order to get only this number but am met by various errors. When I use the following script I get the output from above printed in the log:
When I try to cut only certain characters from the output as an example:
results in 'TypeError: unhashable type'
when I try to use the .split() function as mentioned here:
http://gis.stackexchange.com/questions/ ... rse-string
using this code:
results in AttributeError: 'dict' object has no attribute 'split'
I realise that I have probably embarrased myself with myself with my poor coding but I did say that I am a newbie, there seems to be a bewildering number of ways to achieve what I'm trying to do, I really want to do this in the simplest way possible.
Can anyone help?
Pardon my ignorance as I am relatively new to python; I have managed to connect EG to MySQL, so far mainly for displaying info on the web interface from the media center as well as storing program/device statuses, however I have what I hope is a relatively simple question for you smart people.
Similar but slightly different to the one in this thread:
viewtopic.php?f=10&t=9118
Using the Philips Hue plugin I'm trying to retrieve the current temp from the Hue motion sensor so that I can display that on the web interface as well as to control an electric heater in the bedroom due to a temperature differential with the living room (where the thermostat is located). There is an action within the plugin to get this however it is returned with a lot of other information that I am not interested in, like this:-
Code: Select all
{u'name': u'Hue temperature sensor 1', u'uniqueid': u'00:17:88:01:02:02:b8:70-02-0402', u'config': {u'on': True, u'battery': 100, u'ledindication': False, u'alert': u'none', u'reachable': True, u'usertest': False, u'pending': []}, u'swversion': u'6.1.0.18912', u'state': {u'temperature': 2110, u'lastupdated': u'2017-01-07T12:26:23'}, u'manufacturername': u'Philips', u'type': u'ZLLTemperature', u'modelid': u'SML001'}I've tried a few things in order to get only this number but am met by various errors. When I use the following script I get the output from above printed in the log:
Code: Select all
eg.globals.temp = eg.plugins.PhilipsHue.getSensorStatus(u'03 - Hue temperature sensor 1')
print eg.globals.temp
Code: Select all
eg.globals.temp = eg.plugins.PhilipsHue.getSensorStatus(u'03 - Hue temperature sensor 1')
print eg.globals.temp[110:200]when I try to use the .split() function as mentioned here:
http://gis.stackexchange.com/questions/ ... rse-string
using this code:
Code: Select all
eg.globals.temp = eg.plugins.PhilipsHue.getSensorStatus(u'03 - Hue temperature sensor 1').split(':')
x = eg.globals.temp [0]
print xI realise that I have probably embarrased myself with myself with my poor coding but I did say that I am a newbie, there seems to be a bewildering number of ways to achieve what I'm trying to do, I really want to do this in the simplest way possible.
Can anyone help?