help request - debug python script

Posted on
Thu Oct 03, 2019 2:52 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: help request - debug python script

SMUSEBY wrote:
I see - the value is either in the variable definition or the test.
Thanks.


A better way to think about it is, do I want the variable reference, or do I want the variable value? And proceed from there. I would recommend getting the value right up front, unless you need the reference later (like to do an update to that variable).

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

Posted on
Thu Oct 03, 2019 3:45 pm
SMUSEBY offline
Posts: 505
Joined: Sep 16, 2009
Location: California

Re: help request - debug python script

The following works, but it doesn't seem to be obeying the indentation rules, as I understand them:

Code: Select all
BypassValve = indigo.variables[1371508015].value
if BypassValve == "closed":
   indigo.device.turnOn(1437097498)
   theSubject = "Text..."
   theBody = "text...."
   indigo.server.sendEmailTo("bob@smuseby.net",subject=theSubject, body=theBody)


Actually, as I paste it above, it looks correct. In the Indigo embedded python script window, the last line is not indented, and I am unable to indent it. Even retyping the entire line, starting indented, it ends up not indented.

Posted on
Thu Oct 03, 2019 3:47 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: help request - debug python script

SMUSEBY wrote:
The following works, but it doesn't seem to be obeying the indentation rules, as I understand them:

Code: Select all
BypassValve = indigo.variables[1371508015].value
if BypassValve == "closed":
   indigo.device.turnOn(1437097498)
   theSubject = "Text..."
   theBody = "text...."
   indigo.server.sendEmailTo("bob@smuseby.net",subject=theSubject, body=theBody)


Actually, as I paste it above, it looks correct. In the Indigo embedded python script window, the last line is not indented, and I am unable to indent it. Even retyping the entire line, starting indented, it ends up not indented.


Python indentation can be tricky. I recommend using a decent programming editor, like BBEdit, and then pasting the code into Indigo.

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

Posted on
Thu Oct 03, 2019 3:57 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: help request - debug python script

You can have tabs and spaces. They at not the same

So 4 spaces look like one tab. But python will complain.


Sent from my iPhone using Tapatalk

Posted on
Thu Oct 03, 2019 5:42 pm
SMUSEBY offline
Posts: 505
Joined: Sep 16, 2009
Location: California

Re: help request - debug python script

I guessed that. Definitely using Tab. When I pasted it, it reflected the Tab.
It was also doing something weird - when I attempted to delete a particular line, it grabbed lines above what I had selected.
Anyway, I actually have several Python scripts running - very satisfying. Lots to go, but having models helps a lot.
I'm very much obliged for your help.
Bob

Posted on
Mon Nov 25, 2019 6:04 pm
SMUSEBY offline
Posts: 505
Joined: Sep 16, 2009
Location: California

Re: help request - debug python script

I just returned to this thread, and I don't understand the distinction between the two variables. Both are strings, but season does not require '.value' but valve does? What is the distinction between them?
This snippet works - I just don't understand why.

Code: Select all
season = indigo.variables[325456157]
Valve = indigo.variables[1371508015].value
if Valve.value == "closed":
   if season.value != "summer": #does not equal
      indigo.device.turnOn(1437097498)

Posted on
Mon Nov 25, 2019 6:07 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

help request - debug python script

You can do .value when you get the variable or when you use it

Season.value here is the second case.

But apply it only once. I guess that is done wrong with valve


Sent from my iPhone using Tapatalk

Posted on
Mon Nov 25, 2019 6:29 pm
SMUSEBY offline
Posts: 505
Joined: Sep 16, 2009
Location: California

Re: help request - debug python script

That makes sense. Thank you.

Posted on
Tue Jul 27, 2021 8:54 am
Bildhauer offline
Posts: 160
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Re: help request - debug python script

What's wrong here?

Code: Select all
from time import sleep
import datetime as dt
start_time = dt.datetime.now()
vSuchTyp ='Open/Close Valve'
vWartezeitSekunden = indigo.variables[954340795].getValue(float)*60
vRasenbewaesserungStatus = indigo.variables[1727212894].getValue(bool)
# LogMessage=u"vRasenbewaesserungStatus hat den WErt {})!".format(unicode(vRasenbewaesserungStatus)
# indigo.server.log(LogMessage)
# indigo.variables[954340795] # "vDauerBerechnungMinuten"
ignoreFolderId = indigo.devices.folders.getId("unbenutzt")
ScanFolderId = indigo.devices.folders.getId("Aussenbereich")
for dev in indigo.devices.iter("indigo.zwave"):
   vRasenbewaesserungStatus = indigo.variables[1727212894].getValue(bool)
   if dev.enabled and dev.folderId != ignoreFolderId and dev.model == vSuchTyp :
      if vRasenbewaesserungStatus == false :
         now = dt.datetime.now()
         LogMessage=u"Die Beregnung (gestartet um {})wurde um {} manuell abgebrochen!".format(unicode(start_time),unicode(now))
         break
      indigo.device.turnOn(dev.id)
      vWartezeitMinuten=indigo.variables[954340795].getValue(float)
      # indigo.server.log("Wartezeit: "+str(vWartezeitSekunden) + " Sprenger "+dev.name +" ("+ str(dev.id) +") läuft!")
      LogMessage=u"Beregnung für: {} Minuten. Aktiver Sprenger: {} (Device-ID: {}) läuft!".format(unicode(vWartezeitMinuten), dev.name, unicode(dev.id))
      indigo.server.log(LogMessage)
      sleep(vWartezeitSekunden)
      indigo.device.turnOff(dev.id)
      sleep(2)
now = dt.datetime.now()
LogMessage=u"Beregnung (gestartet um {}) um {}  abgeschlossen!".format(unicode(start_time),unicode(now))
# time.strftime("%H:%M:%S", time.gmtime(diff))
# time.strftime("%H:%M:%S", time.gmtime(now))
# LogMessage=u"Beregnung (gestartet um {}) um {}  abgeschlossen!".format(unicode(start_time), time.strftime("%H:%M:%S", time.gmtime(now)))
indigo.server.log(LogMessage)

#timestampStr = dateTimeObj.strftime("%H:%M:%S.%f - %b %d %Y")
#print (now.strftime("%Y-%m-%d %H:%M:%S"))


The scripts shows the error

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

     Gartenbewaesserung_variabel.py, line 15, at top level
NameError: global name 'false' is not defined



Thx in advance for helping me!

Posted on
Tue Jul 27, 2021 9:02 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: help request - debug python script

It is False not false

Or
If xxx != yyy:

If not (xxx == yyy):


Sent from my iPhone using Tapatalk

Posted on
Tue Jul 27, 2021 9:20 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: help request - debug python script

Another option since your variable is a boolean:

Code: Select all
 if not vRasenbewaesserungStatus:

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Jul 27, 2021 10:17 am
Bildhauer offline
Posts: 160
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Re: help request - debug python script

Okay; I'll try!


Thanks

Posted on
Thu Jul 29, 2021 3:42 pm
Bildhauer offline
Posts: 160
Joined: Sep 30, 2019
Location: 22113 Oststeinbek (near Hamburg), Germany

Re: help request - debug python script

It's working-

Thx

Bildhauer

Who is online

Users browsing this forum: No registered users and 3 guests