Python 3 error

Posted on
Mon May 23, 2022 1:57 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Python 3 error

With the introduction of Indigo 2022.1, my key fobs have stopped working. The error message:
Script Error control page "0 Common" script error in file fDoorRFID OPEN.py:
Script Error No module named 'commands'
Script Error Exception Traceback (most recent call shown last):

fDoorRFID OPEN.py, line 12, at top level
fDoorRFID OPEN.py, line 38, in <module>
ModuleNotFoundError: No module named 'commands'


The script referred to has been purged of tabs, and there is no mention of 'commands'., but for the record, "fDoorRFID OPEN.py) follows:
Code: Select all
# opens fDoor if fDoor interlock variable is true; interlock true for 1 sec

import time
fDoorInterlock = indigo.variables[911502153].getValue(bool)
hseStatus = indigo.variables[1176596514].getValue(bool)

if hseStatus:
 indigo.variable.updateValue(911502153, value = "True") #set to true enabling operation of door latch
 fDoorInterlock = indigo.variables[911502153].getValue(bool)

if fDoorInterlock:
 exec(open("/Library/Application Support/Perceptive Automation/Scripts/RFID-Access-Control.py").read())
 fDoorInterlock = indigo.variables[911502153].getValue(bool)
 time.sleep(1)
 indigo.variable.updateValue(911502153, value = "False") #set to false


The script invoked, "RFID-Access-Control.py", has also been purged of tabs, and does mention "commands" on line 38:
Code: Select all
"""
This script requires the following Indigo variables:
lastTagRead, lastFrontDoorDeniedTime, lastFrontDoorEntryName,
lastFrontDoorEntryTag & lastFrontDoorEntryTime

In Indigo, you must create A Phidgets Standalone Controller device and
an Indigo Digital Output Device (on the 4 relay board) to control the
door solenoid.
"""

# Enter the name of the Phidgets RFID Reader device created in Indigo...
RFIDReaderDevice = "z fDoorRFID_Reader"

# ... and the name of the device that controls the front door latch.
doorLatchDevice = "1 fHallFdoorLatch"

# Solenoid close duration in seconds
solenoidCloseTime = 3

# path to tag and history files
rfidFilesPath = "/Users/rss/Documents/phidgets/"

# Tag file name
rfidTagFile = "690-RFID-tags.txt"

# History file name
rfidHistFile = "RFID-history.txt"

# Set debug to True if necessary for testing
debug = True

###################################################################
########      Do not change anything below this line       ########
###################################################################

import indigo
import datetime
import commands

lastTagRead = indigo.devices[RFIDReaderDevice].states["currentTag"]
now = datetime.datetime.now()
lastTime = now.strftime("%B %d, %H:%M:%S")
indigo.variable.updateValue("lastTagRead", lastTagRead)

if debug: indigo.server.speak('red a tag')

grepReturn = (commands.getstatusoutput("/usr/bin/grep " + lastTagRead + " " + rfidFilesPath + rfidTagFile))
grepResult = grepReturn[0]
if grepResult != 0:
    historyLine = lastTagRead + ", DENIED 0000000000: N/A," + lastTime
    indigo.server.log(u"UNKNOWN TAG %s read. Access Denied." % (lastTagRead), type="RFID Access", isError=True)
    indigo.variable.updateValue("lastFrontDoorDeniedTime", lastTime)
    if debug: indigo.server.speak("Unknown tag, red")

else:
    tagSearch = grepReturn[1]
    tagNum = tagSearch.split(':')[0]
    tagName = tagSearch.split(':')[1]
    tagDescr = tagSearch.split(':')[2]

    if debug: indigo.server.log(u"Tag Search: result code=%s" % (grepResult), type="RFID debug")
    indigo.server.log(u"Front door entry: name=%s, Descr=%s " % (tagName, tagDescr), type="RFID Access")
    if debug: indigo.server.speak("file red, and user name " + tagName + " found")

    indigo.device.turnOn(doorLatchDevice, duration=solenoidCloseTime)
    indigo.variable.updateValue("lastFrontDoorEntryName", tagName)
    indigo.variable.updateValue("lastFrontDoorEntryTag", tagDescr)
    indigo.variable.updateValue("lastFrontDoorEntryTime", lastTime)

    historyLine = lastTagRead + ", " + tagName + ": " + tagDescr + ", " + lastTime
   

historyResult = (commands.getstatusoutput("/bin/echo " + historyLine + " >>" + rfidFilesPath + rfidHistFile))



This script was written for me, and is way beyond my very limited python skillls.
I'd be very grateful for any suggestions.
Bob

Posted on
Mon May 23, 2022 2:25 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python 3 error

Run this in Terminal:
Code: Select all
pip3 install commands

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

Posted on
Mon May 23, 2022 6:31 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python 3 error

In terminal, I upgraded to the current version of pip, and as instructed, I wrote "pip install commands", and the following message was returned:
Successfully installed pip-22.1.1
bSrvr1911:~ macMini1110$ pip3 install commands
ERROR: Could not find a version that satisfies the requirement commands (from versions: none)
ERROR: No matching distribution found for commands
bSrvr1911:~ macMini1110$

I'm afraid I need more direction.
As always, thank you for your patience and help.
Bob

Posted on
Mon May 23, 2022 6:34 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python 3 error

Do this and post the output.
Code: Select all
pip show commands

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

Posted on
Mon May 23, 2022 6:50 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python 3 error

clicking on "Select all" loads this support thread.
do I paste it somewhere, and then execute the 'pip show commands' in terminal? that doesn't make any sense.

Posted on
Mon May 23, 2022 6:51 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python 3 error

SMUSEBY wrote:
clicking on "Select all" loads this support thread.
do I paste it somewhere, and then execute the 'pip show commands' in terminal? that doesn't make any sense.


You run it in Terminal, just like the previous command I posted.

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

Posted on
Mon May 23, 2022 6:58 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python 3 error

Is this what you are asking for?

Last login: Mon May 23 17:55:32 on ttys000
bSrvr1911:~ macMini1110$ pip show commands
WARNING: Package(s) not found: commands
bSrvr1911:~ macMini1110$ Last login: Mon May 23 17:25:22 on ttys000
macMini1110 ttys000 Mon May 23 17:56 still logged in
macMini1110 ttys000 Mon May 23 17:55 - 17:55 (00:00)
macMini1110 ttys000 Mon May 23 17:45 - 17:45 (00:00)
macMini1110 ttys000 Mon May 23 17:25 - 17:25 (00:00)

wtmp begins Wed Dec 15 18:52
bSrvr1911:~ macMini1110$ bSrvr1911:~ macMini1110$ pip show commands
-bash: bSrvr1911:~: command not found
bSrvr1911:~ macMini1110$ WARNING: Package(s) not found: commands
-bash: syntax error near unexpected token `('
bSrvr1911:~ macMini1110$ bSrvr1911:~ macMini1110$ Successfully installed pip-22.1.1
-bash: bSrvr1911:~: command not found
bSrvr1911:~ macMini1110$ -bash: Successfully: command not found
-bash: -bash:: command not found
bSrvr1911:~ macMini1110$ bSrvr1911:~ macMini1110$ bSrvr1911:~ macMini1110$ pip3 install commands
-bash: bSrvr1911:~: command not found
bSrvr1911:~ macMini1110$ -bash: bSrvr1911:~: command not found
-bash: -bash:: command not found
bSrvr1911:~ macMini1110$ bSrvr1911:~ macMini1110$ ERROR: Could not find a version that satisfies the requirement commands (from versions: none)
-bash: syntax error near unexpected token `('
bSrvr1911:~ macMini1110$ -bash: syntax error near unexpected token `('
> bSrvr1911:~ macMini1110$ ERROR: No matching distribution found for commands
> -bash: ERROR:: command not found
> bSrvr1911:~ macMini1110$ bSrvr1911:~ macMini1110$
> -bash: bSrvr1911:~: command not found

Posted on
Mon May 23, 2022 7:05 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python 3 error

What the heck is all that other junk you posted? The WARNING line should have been the end of it. I have no idea what all that other stuff is.

You said someone else wrote this script for you? You need to get them to fix it. There's a module called "commands" which the script uses, which was installed somewhere in your Python 2 install. But it's not a standard package and it doesn't exist for Python3. So you're stuck.

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

Posted on
Mon May 23, 2022 7:28 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python 3 error

Even though it made no sense, I did what I understood your direction to be: in terminal, I typed 'pip show commands' and pressed enter; next I clicked on 'select all' next to code in this thread, pasted it in terminal, and pressed enter; finally, in terminal, cmd A, cmd C, and back to this thread, cmd V.
If you don't see an obvious solution, I'm afraid I'm screwed: it was written by berkinet, and he seems to have disappeared.

Posted on
Tue May 24, 2022 4:00 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Python 3 error

I think there is/was a bug with Select All - I had a problem as well.

Anyway, all that aside, we can add looking at this script to the pile and see if anyone can update it for you.


Sent from my iPhone using Tapatalk Pro

Posted on
Tue May 24, 2022 6:25 am
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python 3 error

Found it. https://docs.python.org/2.7/library/com ... e-commands

That module was deprecated in Python 2.6. No wonder I've never seen it in 2.7 or later.

Change "commands" on lines 38, 47, and 73 to "subprocess", like:

Code: Select all
"""
This script requires the following Indigo variables:
lastTagRead, lastFrontDoorDeniedTime, lastFrontDoorEntryName,
lastFrontDoorEntryTag & lastFrontDoorEntryTime

In Indigo, you must create A Phidgets Standalone Controller device and
an Indigo Digital Output Device (on the 4 relay board) to control the
door solenoid.
"""

# Enter the name of the Phidgets RFID Reader device created in Indigo...
RFIDReaderDevice = "z fDoorRFID_Reader"

# ... and the name of the device that controls the front door latch.
doorLatchDevice = "1 fHallFdoorLatch"

# Solenoid close duration in seconds
solenoidCloseTime = 3

# path to tag and history files
rfidFilesPath = "/Users/rss/Documents/phidgets/"

# Tag file name
rfidTagFile = "690-RFID-tags.txt"

# History file name
rfidHistFile = "RFID-history.txt"

# Set debug to True if necessary for testing
debug = True

###################################################################
########      Do not change anything below this line       ########
###################################################################

import indigo
import datetime
import subprocess

lastTagRead = indigo.devices[RFIDReaderDevice].states["currentTag"]
now = datetime.datetime.now()
lastTime = now.strftime("%B %d, %H:%M:%S")
indigo.variable.updateValue("lastTagRead", lastTagRead)

if debug: indigo.server.speak('red a tag')

grepReturn = (subprocess.getstatusoutput("/usr/bin/grep " + lastTagRead + " " + rfidFilesPath + rfidTagFile))
grepResult = grepReturn[0]
if grepResult != 0:
    historyLine = lastTagRead + ", DENIED 0000000000: N/A," + lastTime
    indigo.server.log(u"UNKNOWN TAG %s read. Access Denied." % (lastTagRead), type="RFID Access", isError=True)
    indigo.variable.updateValue("lastFrontDoorDeniedTime", lastTime)
    if debug: indigo.server.speak("Unknown tag, red")

else:
    tagSearch = grepReturn[1]
    tagNum = tagSearch.split(':')[0]
    tagName = tagSearch.split(':')[1]
    tagDescr = tagSearch.split(':')[2]

    if debug: indigo.server.log(u"Tag Search: result code=%s" % (grepResult), type="RFID debug")
    indigo.server.log(u"Front door entry: name=%s, Descr=%s " % (tagName, tagDescr), type="RFID Access")
    if debug: indigo.server.speak("file red, and user name " + tagName + " found")

    indigo.device.turnOn(doorLatchDevice, duration=solenoidCloseTime)
    indigo.variable.updateValue("lastFrontDoorEntryName", tagName)
    indigo.variable.updateValue("lastFrontDoorEntryTag", tagDescr)
    indigo.variable.updateValue("lastFrontDoorEntryTime", lastTime)

    historyLine = lastTagRead + ", " + tagName + ": " + tagDescr + ", " + lastTime
   

historyResult = (subprocess.getstatusoutput("/bin/echo " + historyLine + " >>" + rfidFilesPath + rfidHistFile))

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

Posted on
Tue May 24, 2022 7:50 am
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Python 3 error

Wow. Nice job Joe.

+1

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

[My Plugins] - [My Forums]

Posted on
Tue May 24, 2022 10:44 am
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python 3 error

I can get back into my house - how nice is that? I've been transformed from despair to elation.
It's not at all clear to me why I'm so fortunate to have your assistance.
Thank you!
Bob

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests