script for polling sma webbox - help getting variables

Posted on
Sat Jul 15, 2017 6:55 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

script for polling sma webbox - help getting variables

hi all. i'm trying to get variables from a script into indigo, anyone have a moment to help with this? i'm sure it's simple, i just don't know it!

the link below is the post with the script, the return, and the question --- thanks so much in advance!


viewtopic.php?p=141479#p141479

Posted on
Sat Jul 15, 2017 7:03 pm
DaveL17 offline
User avatar
Posts: 6755
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: script for polling sma webbox - help getting variables

See my reply in the other thread and let me know if you have any questions.

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

[My Plugins] - [My Forums]

Posted on
Sat Jul 15, 2017 7:14 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: script for polling sma webbox - help getting variables

(reposted from other forum, will move discussion here)


great dave! thanks

i've got that part, the python variables for indigo, so, the syntax for setting a value string from the script to indigo var is:

for Pac:
#indigo.variables[1958563501] # "PV_Pac"


something like, but correctly done??:

indigo.variable.updateValue(1958563501, Pac)

? will this work? or is the syntax different. i'm trying it..

thanks again!

Posted on
Sat Jul 15, 2017 7:21 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: script for polling sma webbox - help getting variables

so that gets me this when i run the script in indigo:


Schedule sma webbox update
Action Group sma webbox poll
Script Error webbox_poll.py: global name 'Pac' is not defined
Script Error Exception Traceback (most recent call shown last):

webbox_poll.py, line 217, at top level
NameError: global name 'Pac' is not defined


how do i set an indigo variable to the value of a variable that is a result of the script and not a string?


thanks!

Posted on
Sat Jul 15, 2017 7:26 pm
DaveL17 offline
User avatar
Posts: 6755
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: script for polling sma webbox - help getting variables

Need to see your work. :D

Sounds like Python is telling you that the script doesn't have access to the value where you're asking for it. Likely a small problem.

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

[My Plugins] - [My Forums]

Posted on
Sat Jul 15, 2017 7:29 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: script for polling sma webbox - help getting variables

yes. not sure how to get the variable that results Pac from the script into an indigo var. does it need to be more the form of:

Code: Select all
indigo.variable.updateValue(1958563501, (value of variable "Pac" as string))

the section i'm using is this, but none of it working yet:


Code: Select all
#     indigo.variables[1822257245] # "PV_EToday"
#   indigo.variables[1469286291] # "PV_ETotal"
#   indigo.variables[789149473] # "PV_Mode"
#     indigo.variables[1958563501] # "PV_Pac"
               
               
indigo.variable.updateValue(1958563501, (value of variable "Pac" as string))
indigo.variable.updateValue(789149473, Mode)
indigo.variable.updateValue(1469286291, GriEgyTot)
indigo.variable.updateValue(1822257245, GriEgyTdy)
               
# indigo.server.log("The variable had a value of 'true'")

Posted on
Sat Jul 15, 2017 7:35 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: script for polling sma webbox - help getting variables

the values i'm looking for are part of the GetPlantOverview, and GetProcessData calls. not sure how to parse them to access as individual variable values.

Posted on
Sat Jul 15, 2017 7:44 pm
DaveL17 offline
User avatar
Posts: 6755
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: script for polling sma webbox - help getting variables

You can turn something into a string by recasting it. There are things that can't be recast, but you're probably okay here.
Code: Select all
string_value = str(value)

indigo.variable.updateValue(1958563501, str(value of variable "Pac" as string))

But that doesn't address your global value issue. This is an example of where that' can occur:

Code: Select all
x = 2

def thing():
    y = x * 2

Python wants variables inside functions to be local to the function. You can get around that by declaring them as global.
Code: Select all
x = 2

def thing():
    global x
    y = x * 2

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

[My Plugins] - [My Forums]

Posted on
Sat Jul 15, 2017 8:04 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: script for polling sma webbox - help getting variables

i global-ed, and tried, but:

Code: Select all
Script Error                    webbox_poll.py: invalid syntax
   Script Error                    around line 222 - "indigo.variable.updateValue(1958563501, str(value of variable "Pac" as string))"


it doesn't like that either. i keep digging around the python scripting hints in the wiki, but can't quite figure it....


Code: Select all
 Script Error                    webbox_poll.py: global name 'Pac' is not defined
   Script Error                    Exception Traceback (most recent call shown last):

     webbox_poll.py, line 219, at top level
NameError: global name 'Pac' is not defined


got that with trying (Pac) without the 'value of variable' ... still throwing error.


thanks a lot for the help dave.

Posted on
Sun Jul 16, 2017 1:53 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: script for polling sma webbox - help getting variables

Screen Shot 2017-07-16 at 12.41.57 PM.jpg
Screen Shot 2017-07-16 at 12.41.57 PM.jpg (246.34 KiB) Viewed 2747 times
thanks a lot for the help everyone.

finally after years of not doing it i've got the solar array current power and daily total on the main control page - much needed !

power in yellow in pool, daily total at bottom left of page.

thanks again, much appreciated.

Posted on
Sun Jul 16, 2017 1:56 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: script for polling sma webbox - help getting variables

sorry about the image scale. i downrezzed to allow for upload but i guess the size is still huge. at any rate. there we are.

Posted on
Mon Jul 17, 2017 12:14 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: script for polling sma webbox - help getting variables

Sorry dtitch, never saw this thread which is why I kept responding in the other one.

It's worth leaving it in Dave's plugin forum but I'll see if Jay can mod it once I've asked Dave.


Sent from my iPhone using Tapatalk Pro

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 16 guests