Core: Component Sense HAT won't install

Created on 28 Dec 2016  ·  23Comments  ·  Source: home-assistant/core

Home Assistant release (hass --version):
0.35.3

Python release (python3 --version):
Python 3.4.2

Component/platform:
Raspberry PI 3
RASPBIAN JESSIE LITE Version: November 2016 Release date: 2016-11-25

Description of problem:
When activating the sensor platform sensehat HASS reports:

_Invalid Config
The following components and platforms could not be set up:
• sensor.sensehat
Please check you config_

Expected:
a working sensehat without error

Problem-relevant configuration.yaml entries and steps to reproduce:

sensor:
[…]
  - platform: sensehat
    display_options:
      - temperature
      - humidity
      - pressure

Traceback (if applicable):
sudo systemctl status home-assistant@pi

gives

/srv/homeassistant/homeassistant_venv/bin/python3 -m pip install --quiet sense-hat==2.2.0 --upgrade --target /home/homeassistant/.homeassistant/deps
[…]
INFO:homeassistant.loader:Loaded sensor.sensehat from homeassistant.components.sensor.sense
INFO:homeassistant.util.package:Attempting install of sense-hat==2.2.0

When I try to install sense-hat by hand (without the above --quiet)
/srv/homeassistant/homeassistant_venv/bin/python3 -m pip install sense-hat==2.2.0 --upgrade --target /home/homeassistant/.homeassistant/deps
it fails with

running build_ext
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-cddrw_15/pillow/setup.py", line 753, in <module>
        zip_safe=not debug_build(), )
      File "/usr/lib/python3.4/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/lib/python3.4/distutils/dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/setuptools/command/install.py", line 61, in run
        return orig.install.run(self)
      File "/usr/lib/python3.4/distutils/command/install.py", line 583, in run
        self.run_command('build')
      File "/usr/lib/python3.4/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/usr/lib/python3.4/distutils/command/build.py", line 126, in run
        self.run_command(cmd_name)
      File "/usr/lib/python3.4/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/usr/lib/python3.4/distutils/command/build_ext.py", line 339, in run
        self.build_extensions()
      File "/tmp/pip-build-cddrw_15/pillow/setup.py", line 521, in build_extensions
        ' using --disable-%s, aborting' % (f, f))
    ValueError: jpeg is required unless explicitly disabled using --disable-jpeg, aborting

    ----------------------------------------
Command "/srv/homeassistant/homeassistant_venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-cddrw_15/pillow/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-gpk26luz-record/install-record.txt --single-version-externally-managed --compile --install-headers /srv/homeassistant/homeassistant_venv/include/site/python3.4/pillow --home=/tmp/tmp2gwi7ogu" failed with error code 1 in /tmp/pip-build-cddrw_15/pillow/

Additional info:

Most helpful comment

Here are the steps I took to make the _SenseHAT_ sensor work _successfully_ with the _All-In-One_ version of Home-Assistant. This solution retains the virtual enviroment and does not require us to grant any additional permissions.

The steps I took are listed below. (Sources and attributions afterwards).

This was tested on a clean install of:

and

Install SenseHAT package to _homeassistant_venv_

sudo su -s /bin/bash homeassistant

source /srv/homeassistant/homeassistant_venv/bin/activate

pip3 install sense-hat

(takes ages, time to go and grab a nice drink)

Install RTIMU lib

Install _RTIMU_ to your pi user environment.
We will add a link to this for _homeassistant_venv_ in the next step.

pip3 install rtimulib

Add symlink to RTIMU in _homeassistant_venv_

Unfortunately attempting to install _RTIMU lib_ to the _homeassistant_venv_ fails with the following error:

Could not find a version that satisfies the requirement rtimulib (from versions: )
No matching distribution found for rtimulib

The only other option is to create a symlink using the following command:

ln -s /usr/lib/python3/dist-packages/RTIMU.cpython-34m-arm-linux-gnueabihf.so /srv/homeassistant/homeassistant_venv/lib/python3.4/

This allows _homeassistant_venv_ to access _RTIMU_.
(The /srv/homeassistant/homeassistant_venv/lib/python3.4/ directory is full of symlinks)

Add _homeassistant_ user to the required groups

Access to _input_

sudo addgroup homeassistant input

Access to _i2c_

sudo addgroup homeassistant i2c

Reboot Raspberry Pi to apply changes

sudo reboot

Sources and attributions:

I will update the components/sensor.sensehat page with the additional information (until there is a better method).

Thanks

All 23 comments

@farminf perhaps you can help here.

I'm guessing...as pillow is a dep of sense-hat. You could try to install pillow with --disable-jpeg and then install sense-hat manually.

I guess you can run "sudo apt-get install libjpeg-dev" first and then what @fabaff just said.

Thanks. And that is what I did and it works.

sudo apt-get install libjpeg-dev
sudo /srv/homeassistant/homeassistant_venv/bin/python3 -m pip install --upgrade pillow
sudo /srv/homeassistant/homeassistant_venv/bin/python3 -m pip install sense-hat==2.2.0 --upgrade --target /home/homeassistant/.homeassistant/deps

But now the RTIMUlib is missing. HASS reports:
ImportError: No module named 'RTIMU'

Seems that python-rtimulib is required too.

Yes, but how do I do that? A sudo pip3 install rtimulib works, but cannot be reached by HASS.
Anything like sudo /srv/homeassistant/homeassistant_venv/bin/python3 -m pip install rtimulib --upgrade --target /home/homeassistant/.homeassistant/deps or similar cannot be found and installed.

To be more specific: How do I install RTIMULib in a virtualenv like homeassistant_env?
PyPI (used by pip) does not know rtimulib or similar. And manually downloading from git and installing it:

[…]
cd RTIMULib2/Linux/python/
source /srv/homeassistant/homeassistant_venv/bin/activate
python3 setup.py build
sudo python3 setup.py install

Always installs in /usr/local/lib/python3.4/dist-packages instead of /home/homeassistant/.homeassistant/deps

I searched, read and tried a lot but found no solution.

Following a hint on gitter I created a symlink ln -s /usr/local/lib/python3.4/dist-packages/RTIMU.cpython-34m.so /home/homeassistant/.homeassistant/deps/ and RTIMULib can now be reached by HASS but now HASS reports PermissionError: [Errno 13] Permission denied: '/dev/input/event0'. I think this is because of sense-hat has a joystick on it.
Still no solution.

I have the same setup (Rpi3, Sensehat, etc.) and I can reproduce this error.

Mine is still working on my old setup.... let me fresh install everything and see what is the problem.

I just flashed my SD card on my pi (which has sensehat module) and installed latest Raspian, then only installed homeassistant (sudo pip3 install homeassistant) and added:

sensor:
platform: sensehat
display_options:
- temperature
- humidity
- pressure

to configarion file, it just worked actually for me without any problem...

@farminf seem particularly strange as many others have also reported issues - However I am using the All-in-one installer and saw issues where I had to start to install RTIMULib2 and saw the same issues as @enurist and then I had to install some other libs all of which need linking and in the end I simply gave up.
(Testing the simple Sense HAT example in python3 from Command line all work well)

Here is a copy of my stack trace:

ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform sensehat
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 151, in _async_setup_platform
    entity_platform.add_entities, discovery_info
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/sensehat.py", line 64, in setup_platform
    dev.append(SenseHatSensor(data, variable))
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/sensehat.py", line 79, in __init__
    self.update()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/sensehat.py", line 98, in update
    self.data.update()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/util/__init__.py", line 296, in wrapper
    result = method(*args, **kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/sensehat.py", line 124, in update
    sense = SenseHat()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/sense_hat/sense_hat.py", line 92, in __init__
    self._stick = SenseStick()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/sense_hat/stick.py", line 57, in __init__
    self._stick_file = io.open(self._stick_device(), 'rb', buffering=0)
PermissionError: [Errno 13] Permission denied: '/dev/input/event0'

mmm, strange... ok so I'll test it also with your setup to see the problem.

Hi guys, i've been having the same issue, and i think i found a (somewhat) more proper way to go around it than doing a symbolic link, altough i'm not sure of its repercussions.

Problem numero 1 is that (at least it seems), if you install a library with an OS package after the virtualenv has been created, it doesn't get updated and doesn't see it, because the OS-wide system site packages are excluded.

I modified that by editing the pyenv.cfg file in the root of the home-assistant installation to have:

include-system-site-packages = true

And the library is properly included, but it might cause issues (i haven't fiddled enough with home-assistant to know what could go wrong).

Problem 2 is the permissions on /dev/input/event0.

I added the following to /etc/udev/rules.d/99-com.rules:

KERNEL=="event0" , SUBSYSTEM=="input", MODE="0777"

Which will set the permissions of /dev/input/event0 to 777(kinda unsafe, it might be a better idea to do 770 and add the homeassisttant user to the proper group) upon boot.

Aaand it works!

PS: version 0.37.1 on the hassbian image(i think, the one that has everthing in /srv/homeassistant).

I too have been following this thread, I do not feel that @sofixa 's approach is the best one, however, I am also relatively new to Python & Virtual Environments.

A Google search showed something along the same lines:
https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=173380

So, the steps I took were:

  1. Login to Raspberry Pi ssh pi@your_raspberry_pi_ip
  2. Add homeassistant to our input _group_ → sudo addgroup homeassistant input
  3. Restart the Raspberry Pi sudo reboot

then once rebooted:

  1. Login to Raspberry Pi ssh pi@your_raspberry_pi_ip
  2. Change to homeassistant user sudo su -s /bin/bash homeassistant
  3. Change to virtual enviroment source /srv/homeassistant/homeassistant_venv/bin/activate
  4. Enter Python3: python3
  5. Import the SenseHat: from sense_hat import SenseHat
  6. Assign a variable sense = SenseHat()
  7. continue with commands →sense.show_message("Hello world!")
  8. LED's start printing 👍

I should point out that earlier in my detective work I did enter, but do not think it affected this:

sudo apt-get install virtualenv python-dev python-pip libjpeg-dev sense-hat
sudo pip install pillow

However, Home-Assistant is still showing errors, but they are no longer a → PermissionError

17-02-08 22:51:15 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform sensehat
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 151, in _async_setup_platform
    entity_platform.add_entities, discovery_info
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/sensehat.py", line 64, in setup_platform
    dev.append(SenseHatSensor(data, variable))
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/sensehat.py", line 79, in __init__
    self.update()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/sensehat.py", line 98, in update
    self.data.update()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/util/__init__.py", line 296, in wrapper
    result = method(*args, **kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/sensehat.py", line 125, in update
    temp_from_h = sense.get_temperature_from_humidity()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/sense_hat/sense_hat.py", line 582, in get_temperature_from_humidity
    self._init_humidity()  # Ensure humidity sensor is initialised
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/sense_hat/sense_hat.py", line 549, in _init_humidity
    raise OSError('Humidity Init Failed')
OSError: Humidity Init Failed

@nodinosaur Yeah, as i said, adding the home asistant user to the group is a better idea than my 777, but personally i don't care if every user on the dedicated RPi can read the input from the joystick :)

As for your issue, have you tried running the get_temperature_from_humidity() function manually in an interactive python (running python3 and then doing stuff)?

@sofixa you mean like this?

pi@raspberrypi:/home/homeassistant/.homeassistant $ python3
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sense_hat import SenseHat
>>> sense = SenseHat()
>>> sense.show_message("Hello world!")
>>> print("Temperature: %s C" % sense.get_temperature_from_humidity())
Temperature: 35.25962829589844 C
>>> print("Humidity: %s %%rH" % sense.get_humidity())
Humidity: 19.28223991394043 %rH
>>> 

and then what should I try?

Try it in the homeassistant virtualenv (by soing source /srv/homeassistant/bin/activate (or wherever the root of your installation is)), it might be another library problem.

@sofixa OK, yes, typically, I didn't test for that sensor earlier.

So,

  1. Change to homeassistant user sudo su -s /bin/bash homeassistant
  2. Change to virtual enviroment source /srv/homeassistant/homeassistant_venv/bin/activate
  3. Start Python3: python3
  4. entering the following program
>>> from sense_hat import SenseHat
>>> sense = SenseHat()
>>> sense.set_rotation(270)
>>> sense.show_message("Hi!", text_colour=(255, 0, 0))
>>> temp_frm_hmdty = sense.get_temperature_from_humidity()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/sense_hat/sense_hat.py", line 582, in get_temperature_from_humidity
    self._init_humidity()  # Ensure humidity sensor is initialised
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/sense_hat/sense_hat.py", line 549, in _init_humidity
    raise OSError('Humidity Init Failed')
OSError: Humidity Init Failed
>>> 

So it's a venv problem, a lib or something doesn't get imported into the venv.

Have you tried doing my potentially ugly hack of setting

include-system-site-packages = true

In the pyenv.cfg file in the root of your install?

Have it working in a relatively _clean_ way - will test in a fresh install & document

Here are the steps I took to make the _SenseHAT_ sensor work _successfully_ with the _All-In-One_ version of Home-Assistant. This solution retains the virtual enviroment and does not require us to grant any additional permissions.

The steps I took are listed below. (Sources and attributions afterwards).

This was tested on a clean install of:

and

Install SenseHAT package to _homeassistant_venv_

sudo su -s /bin/bash homeassistant

source /srv/homeassistant/homeassistant_venv/bin/activate

pip3 install sense-hat

(takes ages, time to go and grab a nice drink)

Install RTIMU lib

Install _RTIMU_ to your pi user environment.
We will add a link to this for _homeassistant_venv_ in the next step.

pip3 install rtimulib

Add symlink to RTIMU in _homeassistant_venv_

Unfortunately attempting to install _RTIMU lib_ to the _homeassistant_venv_ fails with the following error:

Could not find a version that satisfies the requirement rtimulib (from versions: )
No matching distribution found for rtimulib

The only other option is to create a symlink using the following command:

ln -s /usr/lib/python3/dist-packages/RTIMU.cpython-34m-arm-linux-gnueabihf.so /srv/homeassistant/homeassistant_venv/lib/python3.4/

This allows _homeassistant_venv_ to access _RTIMU_.
(The /srv/homeassistant/homeassistant_venv/lib/python3.4/ directory is full of symlinks)

Add _homeassistant_ user to the required groups

Access to _input_

sudo addgroup homeassistant input

Access to _i2c_

sudo addgroup homeassistant i2c

Reboot Raspberry Pi to apply changes

sudo reboot

Sources and attributions:

I will update the components/sensor.sensehat page with the additional information (until there is a better method).

Thanks

Great, it works. Thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

McGiverGim picture McGiverGim  ·  124Comments

nodkan picture nodkan  ·  161Comments

ariel-madril picture ariel-madril  ·  451Comments

sagilo picture sagilo  ·  130Comments

Bergasha picture Bergasha  ·  176Comments