DietPi/PiFace/Home Assistant help required Topic is solved

Having issues with your DietPi installation, or, found a bug? Post it here.
brianm
Posts: 7
Joined: Sun Jan 19, 2020 3:00 pm

DietPi/PiFace/Home Assistant help required

Post by brianm »

Hello forum!

I require some assistance with a problem I have been battling with for a few days now with no success.
In short I am trying to control my PiFace Digital II board from within HASS running on the latest version of DietPi.
First of all, I have previously installed the PiFace and Home Assistant on HASSBIAN and it worked like a charm (after changing SPI speed) so I have had this working before. I wanted to try DietPi out and I have installed Home Assistant (#157) and it is working. I have installed both the pifacecommon and pifacedigitalio requirements for PiFace and I am able to control the PiFace board (simple python scripts) outside of the Home Assistant environment (pyenv) but it does not work within it.
Last night I had an inspiration based on the description for Home Assistant "Customise Python environment:".

If you need to install additional Python modules into this pyenv environment, update Python itself or similar, you need to open a shell as user homeassistant and activate the pyenv environment:
sudo -u homeassistant bash
. /home/homeassistant/pyenv-activate.sh
pip3 install <module> # Or whichever install/update you need to do

I followed the procedure indicated above but when I tried
pip3 install pifacecommon
pip3 install pifacedigitalio

it returned the following
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password for homeassistant:

Unfortunately I do not have the password for the user homeassistant as I did not create it. Note that if anyone knows the password then please let me (and others) know as that is necessary to install other python modules into pyenv?
So I just finished adding the user homeassistant into the sudo group to try and get around the issue with the password and was able to install the pifacecommon and pifacedigitalio libraries but unfortunately still, I am not able to talk to the PiFace from within HASS.

Here is a test I just ran and I think it is the same error I am getting from within HASS. Almost as if the SPI is not enabled but outside of HASS (pyenv) it works so the SPI must be enabled. Any help would be greatly appreciated and thank you in advance.

[email protected]:/root$ . /home/homeassistant/pyenv-activate.sh
[email protected]:~$ pip3 install pifacecommon
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pifacecommon in ./.pyenv/versions/3.8.0/lib/python3.8/site-packages (4.2.2)
[email protected]:~$ pip3 install pifacedigitalio
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pifacedigitalio in ./.pyenv/versions/3.8.0/lib/python3.8/site-packages (3.0.5)
[email protected]:~$ python3
Python 3.8.0 (default, Jan 7 2020, 18:53:06)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pifacedigitalio
>>> pifacedigital = pifacedigitalio.PiFaceDigital()
Traceback (most recent call last):
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacecommon/spi.py", line 41, in open_fd
self.fd = posix.open(spi_device, posix.O_RDWR)
PermissionError: [Errno 13] Permission denied: '/dev/spidev0.0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacedigitalio/core.py", line 53, in __init__
super(PiFaceDigital, self).__init__(hardware_addr, bus, chip_select)
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacecommon/mcp23s17.py", line 91, in __init__
super(MCP23S17, self).__init__(bus, chip_select, speed_hz=speed_hz)
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacecommon/spi.py", line 33, in __init__
self.open_fd(spi_device)
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacecommon/spi.py", line 43, in open_fd
raise SPIInitError(
pifacecommon.spi.SPIInitError: I can't see /dev/spidev0.0. Have you enabled the SPI module? (http://piface.github.io/pifacecommon/in ... spi-module)
>>>
----------------------------

011920: Added - config.txt file located in DietPi folder
#-------I²C-------------
dtparam=i2c_arm=on
dtparam=i2c1=on

#-------SPI-------------
#dtparam=spi=off
dtparam=spi=on

#-------Serial/UART-----
# NB: Enabled for 1st run only, if you want to keep this setting, please set CONFIG_SERIAL_CONSOLE_ENABLE=1 in /DietPi/dietpi.txt.
#core_freq=400
enable_uart=1

User avatar
Joulinar
Posts: 1575
Joined: Fri Nov 15, 2019 11:49 pm

Re: DietPi/PiFace/Home Assistant help required

Post by Joulinar »

Hi,
many tanks for your report.

Hmm looks like your have issues to access /dev/spidev0.0. Pls can you check what the file system permissions are?
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team

brianm
Posts: 7
Joined: Sun Jan 19, 2020 3:00 pm

Re: DietPi/PiFace/Home Assistant help required

Post by brianm »

Hi and thanks for getting back to me. The original permissions of spidev0.0 were octal 660. I changed it to 770 but still the same results.

[email protected]:~# cd /dev
[email protected]:/dev# ls -l spidev0.0
crwxrwx--- 1 root spi 153, 0 Jan 19 07:48 spidev0.0
[email protected]:/dev# ls -l spidev0.1
crwxrwx--- 1 root spi 153, 1 Jan 19 07:48 spidev0.1
[email protected]:/dev#
-----------
Note that it did import the pifacedigitalio library but failed after that.

[email protected]:/root$ . /home/homeassistant/pyenv-activate.sh
[email protected]:~$ python3
Python 3.8.0 (default, Jan 7 2020, 18:53:06)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pifacedigitalio
>>> pifacedigital = pifacedigitalio.PiFaceDigital()
Traceback (most recent call last):
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacecommon/spi.py", line 41, in open_fd
self.fd = posix.open(spi_device, posix.O_RDWR)
PermissionError: [Errno 13] Permission denied: '/dev/spidev0.0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacedigitalio/core.py", line 53, in __init__
super(PiFaceDigital, self).__init__(hardware_addr, bus, chip_select)
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacecommon/mcp23s17.py", line 91, in __init__
super(MCP23S17, self).__init__(bus, chip_select, speed_hz=speed_hz)
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacecommon/spi.py", line 33, in __init__
self.open_fd(spi_device)
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacecommon/spi.py", line 43, in open_fd
raise SPIInitError(
pifacecommon.spi.SPIInitError: I can't see /dev/spidev0.0. Have you enabled the SPI module? (http://piface.github.io/pifacecommon/in ... spi-module)
>>>

User avatar
Joulinar
Posts: 1575
Joined: Fri Nov 15, 2019 11:49 pm

Re: DietPi/PiFace/Home Assistant help required

Post by Joulinar »

can you change it to 777 for /dev/spidev0.0? You still have Permission denied
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team

brianm
Posts: 7
Joined: Sun Jan 19, 2020 3:00 pm

Re: DietPi/PiFace/Home Assistant help required

Post by brianm »

Ok, just did some experimentation and although I changed the permission to octal 777 for both spidev0.0 and spidev0.1, I noticed after a reboot that the permission went back to 660. In any case I did not reboot after a change and as below, it appears now that although spidev0.0 appears to work, there are now permission errors on /sys/class/gpio/gpio25/...
thx again for sticking with it.

[email protected]:/dev$ ls -l spi*
crwxrwxrwx 1 root spi 153, 0 Jan 19 12:46 spidev0.0
crwxrwxrwx 1 root spi 153, 1 Jan 19 12:46 spidev0.1
[email protected]:/dev$ . /home/homeassistant/pyenv-activate.sh
[email protected]:~$ cd /dev
[email protected]:/dev$ ls -l spi*
crwxrwxrwx 1 root spi 153, 0 Jan 19 12:46 spidev0.0
crwxrwxrwx 1 root spi 153, 1 Jan 19 12:46 spidev0.1
[email protected]:/dev$ cd ~
[email protected]:~$ python3
Python 3.8.0 (default, Jan 7 2020, 18:53:06)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pifacedigitalio
>>> pifacedigital = pifacedigitalio.PiFaceDigital()
Traceback (most recent call last):
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacecommon/interrupts.py", line 385, in bring_gpio_interrupt_into_userspace
with open(GPIO_INTERRUPT_DEVICE_VALUE):
PermissionError: [Errno 13] Permission denied: '/sys/class/gpio/gpio25/value'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacedigitalio/core.py", line 82, in __init__
self.init_board()
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacedigitalio/core.py", line 114, in init_board
self.enable_interrupts()
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacedigitalio/core.py", line 86, in enable_interrupts
self.gpio_interrupts_enable()
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacecommon/interrupts.py", line 232, in gpio_interrupts_enable
bring_gpio_interrupt_into_userspace()
File "/home/homeassistant/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pifacecommon/interrupts.py", line 389, in bring_gpio_interrupt_into_userspace
with open(GPIO_EXPORT_FILE, 'w') as export_file:
PermissionError: [Errno 13] Permission denied: '/sys/class/gpio/export'
>>>

User avatar
Joulinar
Posts: 1575
Joined: Fri Nov 15, 2019 11:49 pm

Re: DietPi/PiFace/Home Assistant help required

Post by Joulinar »

probably you would need to change permission for these files as well. Your challenge is that your commands are executed with user homeassistant but this user did not have the appropriate right. You could try to have the user added to the needed groups. Maybe that will fix the access issues.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team

brianm
Posts: 7
Joined: Sun Jan 19, 2020 3:00 pm

Re: DietPi/PiFace/Home Assistant help required

Post by brianm »

You are correct in that it does appear to be a "permissions issue" in regards to user homeassistant as the same works perfectly under user root.
I will need to think about this some more but if anyone has some input/experience on how to add that within pyenv/homeassistant that would be great. Although I am getting better by the day, I am still learning by the minute.

thx

User avatar
Joulinar
Posts: 1575
Joined: Fri Nov 15, 2019 11:49 pm

Re: DietPi/PiFace/Home Assistant help required

Post by Joulinar »

Probably this could help how to mange groups on Linux based environments

https://www.howtogeek.com/50787/add-a-u ... -on-linux/

To display the group of user homeassistant, just run

Code: Select all

groups homeassistant 
However you would need to find out what groups you would need to add to the user homeassistant
If you know that, it can be done as follow

Code: Select all

usermod -a -G examplegroup exampleusername
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team

brianm
Posts: 7
Joined: Sun Jan 19, 2020 3:00 pm

Re: DietPi/PiFace/Home Assistant help required

Post by brianm »

Interesting to note that there were no issues experienced when using HASSBIAN (which has been retired out) so with that I do wonder if user permissions have been addressed with the install of HASS under DietPi? Both use the pyenv environment which creates its own Python instance. As you mention (and thanks again) I will need to explore deeper into homeassistant group permissions. I might need to resurrect the old HASSBIAN build and compare.

User avatar
Joulinar
Posts: 1575
Joined: Fri Nov 15, 2019 11:49 pm

Re: DietPi/PiFace/Home Assistant help required

Post by Joulinar »

Hi,
I don't think it has anything to do with pyenv environment. It's more a question of pure Linux file system permissions and authorization.

how did you setup HASS on your DietPi device?
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team

Post Reply