[ANSWERED]How to access states from Python

Posted on
Mon Apr 21, 2014 4:12 pm
wikner offline
Posts: 177
Joined: Nov 02, 2003

[ANSWERED]How to access states from Python

I am trying to convert all my old applescripts to Python. I have a fairly complicated one which bases a decision about whether to water the lawn based on multiple pieces of weather data. I am also trying to transition from WeatherD to WeatherSnoop in the process. I am fairly new to Python programming.

I have searched the documentation in vain for how to access WeatherSnoop states directly from a Python script. Is there a method for doing so?

The workaround is to make a bunch of triggers in Indigo which set Indigo variables to the WeatherSnoop device states of interest when they change. Then I can just access the variables (which I DO know how to do). But how does one query the device states directly?

Posted on
Mon Apr 21, 2014 4:14 pm
wikner offline
Posts: 177
Joined: Nov 02, 2003

Re: How to access states from Python

P.S. I have looked into introspection to try to do this, but that has gotten me in way over my head, and so far, I haven't been able to discover the device states.

Posted on
Mon Apr 21, 2014 4:52 pm
wikner offline
Posts: 177
Joined: Nov 02, 2003

Re: How to access states from Python

I should have worked harder before asking. I found the answer. That others in my current state of ignorance might know, here it is.
Code: Select all
>>> ws = indigo.devices[1903713088] # "WeatherSnoop"
>>> wsStates = ws.states
>>> wsStates.__class__
<class 'indigo.Dict'>
>>> print(str(wsStates.keys()))
[u'absoluteBarometricPressure_cb', u'absoluteBarometricPressure_cb.ui', u'absoluteBarometricPressure_in', u'absoluteBarometricPressure_in.ui', u'absoluteBarometricPressure_mb', u'absoluteBarometricPressure_mb.ui', u'agent', u'agent.ui', u'barometricTrend', u'barometricTrend.ui', u'consoleBatteryVoltage', u'consoleBatteryVoltage.ui', u'dayEvapotranspiration_cm', u'dayEvapotranspiration_cm.ui', u'dayEvapotranspiration_in', u'dayEvapotranspiration_in.ui', u'dayEvapotranspiration_km', u'dayEvapotranspiration_km.ui', u'dayEvapotranspiration_mi', u'dayEvapotranspiration_mi.ui', u'dayEvapotranspiration_mm', u'dayEvapotranspiration_mm.ui', u'dayRain_cm', u'dayRain_cm.ui', u'dayRain_in', u'dayRain_in.ui', u'dayRain_km', u'dayRain_km.ui', u'dayRain_mi', u'dayRain_mi.ui', u'dayRain_mm', u'dayRain_mm.ui', u'elevation', u'elevation.ui', u'emc', u'emc.ui', u'extraHumidity1', u'extraHumidity1.ui', u'extraHumidity2', u'extraHumidity2.ui', u'extraHumidity3', u'extraHumidity3.ui', u'extraHumidity4', u'extraHumidity4.ui', u'extraHumidity5', u'extraHumidity5.ui', u'extraHumidity6', u'extraHumidity6.ui', u'extraHumidity7', u'extraHumidity7.ui', u'extraTemperature1_C', u'extraTemperature1_C.ui', u'extraTemperature1_F', u'extraTemperature1_F.ui', u'extraTemperature2_C', u'extraTemperature2_C.ui', u'extraTemperature2_F', u'extraTemperature2_F.ui', u'extraTemperature3_C', u'extraTemperature3_C.ui', u'extraTemperature3_F', u'extraTemperature3_F.ui', u'extraTemperature4_C', u'extraTemperature4_C.ui', u'extraTemperature4_F', u'extraTemperature4_F.ui', u'extraTemperature5_C', u'extraTemperature5_C.ui', u'extraTemperature5_F', u'extraTemperature5_F.ui', u'extraTemperature6_C', u'extraTemperature6_C.ui', u'extraTemperature6_F', u'extraTemperature6_F.ui', u'extraTemperature7_C', u'extraTemperature7_C.ui', u'extraTemperature7_F', u'extraTemperature7_F.ui', u'forecast', u'forecast.ui', u'indoorDewPoint_C', u'indoorDewPoint_C.ui', u'indoorDewPoint_F', u'indoorDewPoint_F.ui', u'indoorHeatIndex_C', u'indoorHeatIndex_C.ui', u'indoorHeatIndex_F', u'indoorHeatIndex_F.ui', u'indoorHumidity', u'indoorHumidity.ui', u'indoorTemperature_C', u'indoorTemperature_C.ui', u'indoorTemperature_F', u'indoorTemperature_F.ui', u'latitude', u'latitude.ui', u'leafTemperature1_C', u'leafTemperature1_C.ui', u'leafTemperature1_F', u'leafTemperature1_F.ui', u'leafTemperature2_C', u'leafTemperature2_C.ui', u'leafTemperature2_F', u'leafTemperature2_F.ui', u'leafTemperature3_C', u'leafTemperature3_C.ui', u'leafTemperature3_F', u'leafTemperature3_F.ui', u'leafTemperature4_C', u'leafTemperature4_C.ui', u'leafTemperature4_F', u'leafTemperature4_F.ui', u'leafWetness1_cb', u'leafWetness1_cb.ui', u'leafWetness1_in', u'leafWetness1_in.ui', u'leafWetness1_mb', u'leafWetness1_mb.ui', u'leafWetness2_cb', u'leafWetness2_cb.ui', u'leafWetness2_in', u'leafWetness2_in.ui', u'leafWetness2_mb', u'leafWetness2_mb.ui', u'leafWetness3_cb', u'leafWetness3_cb.ui', u'leafWetness3_in', u'leafWetness3_in.ui', u'leafWetness3_mb', u'leafWetness3_mb.ui', u'leafWetness4_cb', u'leafWetness4_cb.ui', u'leafWetness4_in', u'leafWetness4_in.ui', u'leafWetness4_mb', u'leafWetness4_mb.ui', u'location', u'location.ui', u'longitude', u'longitude.ui', u'monthEvapotranspiration_cm', u'monthEvapotranspiration_cm.ui', u'monthEvapotranspiration_in', u'monthEvapotranspiration_in.ui', u'monthEvapotranspiration_km', u'monthEvapotranspiration_km.ui', u'monthEvapotranspiration_mi', u'monthEvapotranspiration_mi.ui', u'monthEvapotranspiration_mm', u'monthEvapotranspiration_mm.ui', u'monthRain_cm', u'monthRain_cm.ui', u'monthRain_in', u'monthRain_in.ui', u'monthRain_km', u'monthRain_km.ui', u'monthRain_mi', u'monthRain_mi.ui', u'monthRain_mm', u'monthRain_mm.ui', u'name', u'name.ui', u'outdoorDewPoint_C', u'outdoorDewPoint_C.ui', u'outdoorDewPoint_F', u'outdoorDewPoint_F.ui', u'outdoorHeatIndex_C', u'outdoorHeatIndex_C.ui', u'outdoorHeatIndex_F', u'outdoorHeatIndex_F.ui', u'outdoorHumidity', u'outdoorHumidity.ui', u'outdoorTemperature_C', u'outdoorTemperature_C.ui', u'outdoorTemperature_F', u'outdoorTemperature_F.ui', u'rainRate_cm', u'rainRate_cm.ui', u'rainRate_in', u'rainRate_in.ui', u'rainRate_km', u'rainRate_km.ui', u'rainRate_mi', u'rainRate_mi.ui', u'rainRate_mm', u'rainRate_mm.ui', u'relativeBarometricPressure_cb', u'relativeBarometricPressure_cb.ui', u'relativeBarometricPressure_in', u'relativeBarometricPressure_in.ui', u'relativeBarometricPressure_mb', u'relativeBarometricPressure_mb.ui', u'soilMoisture1', u'soilMoisture1.ui', u'soilMoisture2', u'soilMoisture2.ui', u'soilMoisture3', u'soilMoisture3.ui', u'soilMoisture4', u'soilMoisture4.ui', u'soilTemperature1_C', u'soilTemperature1_C.ui', u'soilTemperature1_F', u'soilTemperature1_F.ui', u'soilTemperature2_C', u'soilTemperature2_C.ui', u'soilTemperature2_F', u'soilTemperature2_F.ui', u'soilTemperature3_C', u'soilTemperature3_C.ui', u'soilTemperature3_F', u'soilTemperature3_F.ui', u'soilTemperature4_C', u'soilTemperature4_C.ui', u'soilTemperature4_F', u'soilTemperature4_F.ui', u'solarRadiation', u'solarRadiation.ui', u'tenMinuteAverageWindSpeed_kn', u'tenMinuteAverageWindSpeed_kn.ui', u'tenMinuteAverageWindSpeed_kph', u'tenMinuteAverageWindSpeed_kph.ui', u'tenMinuteAverageWindSpeed_mph', u'tenMinuteAverageWindSpeed_mph.ui', u'tenMinuteAverageWindSpeed_mps', u'tenMinuteAverageWindSpeed_mps.ui', u'tenMinuteWindGustDirection', u'tenMinuteWindGustDirection.ui', u'tenMinuteWindGust_kn', u'tenMinuteWindGust_kn.ui', u'tenMinuteWindGust_kph', u'tenMinuteWindGust_kph.ui', u'tenMinuteWindGust_mph', u'tenMinuteWindGust_mph.ui', u'tenMinuteWindGust_mps', u'tenMinuteWindGust_mps.ui', u'thswIndex_C', u'thswIndex_C.ui', u'thswIndex_F', u'thswIndex_F.ui', u'transmitterBatteryStatus', u'transmitterBatteryStatus.ui', u'twoMinuteAverageWindSpeed_kn', u'twoMinuteAverageWindSpeed_kn.ui', u'twoMinuteAverageWindSpeed_kph', u'twoMinuteAverageWindSpeed_kph.ui', u'twoMinuteAverageWindSpeed_mph', u'twoMinuteAverageWindSpeed_mph.ui', u'twoMinuteAverageWindSpeed_mps', u'twoMinuteAverageWindSpeed_mps.ui', u'uri', u'uri.ui', u'uvIndex', u'uvIndex.ui', u'version', u'version.ui', u'windChill_C', u'windChill_C.ui', u'windChill_F', u'windChill_F.ui', u'windDirection', u'windDirection.ui', u'windSpeed_kn', u'windSpeed_kn.ui', u'windSpeed_kph', u'windSpeed_kph.ui', u'windSpeed_mph', u'windSpeed_mph.ui', u'windSpeed_mps', u'windSpeed_mps.ui', u'yearEvapotranspiration_cm', u'yearEvapotranspiration_cm.ui', u'yearEvapotranspiration_in', u'yearEvapotranspiration_in.ui', u'yearEvapotranspiration_km', u'yearEvapotranspiration_km.ui', u'yearEvapotranspiration_mi', u'yearEvapotranspiration_mi.ui', u'yearEvapotranspiration_mm', u'yearEvapotranspiration_mm.ui', u'yearRain_cm', u'yearRain_cm.ui', u'yearRain_in', u'yearRain_in.ui', u'yearRain_km', u'yearRain_km.ui', u'yearRain_mi', u'yearRain_mi.ui', u'yearRain_mm', u'yearRain_mm.ui']
>>> rain = wsStates["monthRain_in"]                           
>>> rain.__class__
<type 'float'>
>>> print rain
0.89
>>> rainUI = wsStates["monthRain_in.ui"]
>>> rainUI.__class__
<type 'unicode'>
>>> print rainUI
0.89 in

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest