Error: Invalid literal for int() with base 10:

Posted on
Thu Nov 12, 2020 8:09 am
roquej offline
User avatar
Posts: 608
Joined: Jan 04, 2015
Location: South Florida, USA

Error: Invalid literal for int() with base 10:

I am getting this error:

Variable Devices Error exception in deviceStartComm(Temperature (Master-AWAir)): invalid literal for int() with base 10: ''
Variable Devices Error Error in plugin execution ServerReplacedElem:
Traceback (most recent call last):
File "plugin.py", line 150, in variableUpdated
ValueError: invalid literal for int() with base 10: ''

The variable is a temperature reading (example 75.6). The variable name is "awair_Master_0_temp"

Ideas?

Thank you!

JP

Posted on
Thu Nov 12, 2020 9:06 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Error: Invalid literal for int() with base 10:

Something is trying to convert an empty string to an integer. Which doesn't work. Are you sure that variable has an appropriate value in it?

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

Posted on
Thu Nov 12, 2020 10:04 am
roquej offline
User avatar
Posts: 608
Joined: Jan 04, 2015
Location: South Florida, USA

Re: Error: Invalid literal for int() with base 10:

I think so. See image.
Attachments
Screen Shot 2020-11-12 at 11.02.18 AM.png
Screen Shot 2020-11-12 at 11.02.18 AM.png (185.04 KiB) Viewed 3579 times

Posted on
Thu Nov 12, 2020 10:09 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Error: Invalid literal for int() with base 10:

How is that variable getting set? Is there a script that's possibly clearing it first, then setting the new value?

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

Posted on
Thu Nov 12, 2020 10:18 am
roquej offline
User avatar
Posts: 608
Joined: Jan 04, 2015
Location: South Florida, USA

Re: Error: Invalid literal for int() with base 10:

Yes, I am using a script. This is the code I am suing to set the value:

varValue = round( float(indigo.devices[awairDevice].states["data_0_sensors_0_value"]) ,1)
indigo.variable.updateValue(awairVarID, value= str(varValue))

awairDevice is a GhostXML feed.
awairVarID is the variable I set and trying to use with Variable Device

Makes sense?

JP

Posted on
Thu Nov 12, 2020 10:26 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Error: Invalid literal for int() with base 10:

Yeah, that should work. Any particular reason you're doing a two step device -> variable -> device? I think you could probably use the Masquerade plugin to do it in one step. And maybe avoid this error.

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

Posted on
Thu Nov 12, 2020 10:35 am
roquej offline
User avatar
Posts: 608
Joined: Jan 04, 2015
Location: South Florida, USA

Re: Error: Invalid literal for int() with base 10:

Because the "interesting folks" at AWAir have an API that changes its orders list as you check for changes in data. That means I must search the values provided for "temp", in the index, then use that value.

This is the full code:

Code: Select all
#type of value
lookValue = "temp"
# define variable ID
awairVarID = "awair_Master_0_temp"

try:
   index0 = str( indigo.devices[awairDevice].states["data_0_sensors_0_comp"] )
   index1 = str( indigo.devices[awairDevice].states["data_0_sensors_1_comp"] )
   index2 = str( indigo.devices[awairDevice].states["data_0_sensors_2_comp"] )
   index3 = str( indigo.devices[awairDevice].states["data_0_sensors_3_comp"] )
   index4 = str( indigo.devices[awairDevice].states["data_0_sensors_4_comp"] )
except:
   indigo.variable.updateValue("awair_Master_status", value="Could not retreive Master temperature data")
   indigo.server.log ("awair_Master_status = " + "Could not retrive Master temperature data")
   exit(0)

if (index0 == lookValue):
   varValue = round( float(indigo.devices[awairDevice].states["data_0_sensors_0_value"]) ,1)
     indigo.variable.updateValue(awairVarID, value= str(varValue))
elif (index1 == lookValue):
   varValue = round( float(indigo.devices[awairDevice].states["data_0_sensors_1_value"]) ,1)
     indigo.variable.updateValue(awairVarID, value= str(varValue))
elif (index2 == lookValue):
   varValue = round( float(indigo.devices[awairDevice].states["data_0_sensors_2_value"]) ,1)
     indigo.variable.updateValue(awairVarID, value= str(varValue))
elif (index3 == lookValue):
   varValue = round( float(indigo.devices[awairDevice].states["data_0_sensors_3_value"]) ,1)
     indigo.variable.updateValue(awairVarID, value= str(varValue))
else:
   varValue = round(float(indigo.devices[awairDevice].states["data_0_sensors_4_value"]) ,1)
     indigo.variable.updateValue(awairVarID, value= str(varValue))

I am not a programmer, so I am sure this code could be much more efficient (if you have any suggestions, it would be appreciated!), but it seems to work. Not sure how to make this work with the Masquerade plugin in this use case.

Any idea what could be causing the problem?

JP

Posted on
Thu Nov 12, 2020 10:51 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Error: Invalid literal for int() with base 10:

Depending on the input conditions, that script could fail silently. Try this:

Code: Select all
#type of value
lookValue = "temp"
# define variable ID
awairVarID = "awair_Master_0_temp"

try:
    index0 = str( indigo.devices[awairDevice].states["data_0_sensors_0_comp"] )
    index1 = str( indigo.devices[awairDevice].states["data_0_sensors_1_comp"] )
    index2 = str( indigo.devices[awairDevice].states["data_0_sensors_2_comp"] )
    index3 = str( indigo.devices[awairDevice].states["data_0_sensors_3_comp"] )
    index4 = str( indigo.devices[awairDevice].states["data_0_sensors_4_comp"] )
except:
    indigo.variable.updateValue("awair_Master_status", value="Could not retrieve Master temperature data")
    indigo.variable.updateValue(awairVarID, value="0.0")
    indigo.server.log ("awair_Master_status = " + "Could not retrieve Master temperature data")
exit(0)

if (index0 == lookValue):
    varValue = round( float(indigo.devices[awairDevice].states["data_0_sensors_0_value"]) ,1)
elif (index1 == lookValue):
    varValue = round( float(indigo.devices[awairDevice].states["data_0_sensors_1_value"]) ,1)
elif (index2 == lookValue):
    varValue = round( float(indigo.devices[awairDevice].states["data_0_sensors_2_value"]) ,1)
elif (index3 == lookValue):
    varValue = round( float(indigo.devices[awairDevice].states["data_0_sensors_3_value"]) ,1)
elif (index4 == lookValue):
    varValue = round( float(indigo.devices[awairDevice].states["data_0_sensors_4_value"]) ,1)
else:
    indigo.variable.updateValue("awair_Master_status", value="lookValue not found")
    indigo.server.log ("awair_Master_status = " + "lookValue not found")
    varValue = 0.0

indigo.variable.updateValue(awairVarID, value= str(varValue))


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

Posted on
Thu Nov 12, 2020 10:54 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Error: Invalid literal for int() with base 10:

That's still not how I would write it if I were starting from scratch, but it's better. Honestly, given that the data returned doesn't work well with GhostXML, you're probably better off just doing the whole thing in a single Python script and not using the plugin at all.

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

Posted on
Thu Nov 12, 2020 11:22 am
roquej offline
User avatar
Posts: 608
Joined: Jan 04, 2015
Location: South Florida, USA

Re: Error: Invalid literal for int() with base 10:

Thank you for the code suggestion!

Let me try, as that was the first way I tried to address the problem. However, I stopped because had not realized the ordered list kept changing and I thought the incorrect values were my code.

Will report if that takes care of the Variable Device issues.

Again, thank you for all the help and plugins.

JP

Posted on
Thu Nov 12, 2020 2:53 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Error: Invalid literal for int() with base 10:

roquej wrote:
I am getting this error:

Variable Devices Error exception in deviceStartComm(Temperature (Master-AWAir)): invalid literal for int() with base 10: ''
Variable Devices Error Error in plugin execution ServerReplacedElem:
Traceback (most recent call last):
File "plugin.py", line 150, in variableUpdated
ValueError: invalid literal for int() with base 10: ''

Actually, that error is nothing to do with your script (although everything Joe has said is correct).

In your "Variable Device" device, you need to select a valid variable in the "State to display: " box. I suspect it's either blank or an old variable, as my code is returning '' which is the (bad choice of) default value.

I'll fix the plugin to default to 0 instead of '' so that line of code doesn't fail.

Peter

Posted on
Thu Nov 12, 2020 3:09 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Error: Invalid literal for int() with base 10:


Posted on
Thu Nov 12, 2020 7:10 pm
roquej offline
User avatar
Posts: 608
Joined: Jan 04, 2015
Location: South Florida, USA

Re: Error: Invalid literal for int() with base 10:

First, I converted everything to using a script and that works great.

Second, I installed 1.05 and the problem solved

Thank all!

JP


Sent from my iPad using Tapatalk Pro

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests