Python Conversion?

Posted on
Mon Jul 02, 2018 5:58 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Python Conversion?

This script:
Code: Select all
state_value_as_float = float(indigo.devices[665976433].states[maxTempToday])
indigo.variable.updateValue(1796297015, value=str(int(state_value_as_float)))


Returns this error: global name "maxTempToday" is not defined

Missed something?

Thanks,

Carl

Posted on
Mon Jul 02, 2018 6:21 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python Conversion?

Strings in Python must be in quotes, so the state ID must be in quotes.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Jul 02, 2018 6:23 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Python Conversion?

Now get: global name 'state value' is not defined.
Code: Select all
state_value_as_float = float(indigo.devices[665976433].states["maxTempToday"])
indigo.variable.updateValue(1796297015, value=str(int(state_value)))

Thanks,

Carl

Posted on
Mon Jul 02, 2018 7:13 pm
FlyingDiver offline
User avatar
Posts: 7220
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python Conversion?

ckeyes888 wrote:
Now get: global name 'state value' is not defined.
Code: Select all
state_value_as_float = float(indigo.devices[665976433].states["maxTempToday"])
indigo.variable.updateValue(1796297015, value=str(int(state_value)))

Thanks,

Carl


Needs to be 'state_value_as_float' both places. Second line is 'state_value'. It's an error in Jay's original code.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jul 02, 2018 7:24 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Python Conversion?

Perfect, thanks a bunch. Should be able to get rid of another slew of AS.

Carl

Posted on
Tue Jul 03, 2018 8:31 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python Conversion?

FlyingDiver wrote:
Needs to be 'state_value_as_float' both places. Second line is 'state_value'. It's an error in Jay's original code.


Copy/paste error. Thus the "should be close" part... ;)

Fixed in my original code above. Carl, I highly recommend that you walk through one of the many intro to Python tutorials on the net - doing just that much would help you recognize simple errors like this one.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Who is online

Users browsing this forum: No registered users and 2 guests

cron