Hey guys,
I wanted to write a custom sensor to receive data, sent from my self constructed remote sensor via 433MHZ. The problem I currently have is that I’m not able to import packages installed with pip3. To import local files I had to add the folder to the path but that doesn’t work for pip packages. Can anyone tell me what I’ve done wrong?
2019-01-19 13:01:44 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.sensor.rfm69-temperature. Make sure all dependencies are installed
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/loader.py", line 92, in get_component
module = importlib.import_module(path)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 673, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/etc/homeassistant/custom_components/sensor/rfm69-temperature.py", line 7, in <module>
import RFM69
File "/etc/homeassistant/custom_components/sensor/RFM69.py", line 4, in <module>
import spidev
ImportError: No module named 'spidev'
Thats my sensor class. PS does it work when the update is blocking?
import os
import sys
sys.path.append(os.path.dirname(__file__))
#sys.path.append('/usr/local/lib/python3.5')
from homeassistant.helpers.entity import Entity
import RFM69
from RFM69registers import *
import time
import re
import spidev
KEYS = {
'v': 'volt',
't': 'temperature',
'h': 'humidity'
}
REQUIREMENTS = ['spidev==3.2', 'RPi.GPIO']
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup rfm sensor"""
add_devices([Rfm69TemperatureSensor(22, 100)])
class Rfm69TemperatureSensor(Entity):
"""RFM69 Temperature and humidity sensor"""
def __init__(self, nodeId, networkId):
"""Initialize the sensor"""
self.state = {}
self.listener = RFM69.RFM69(RF69_433MHZ, nodeId, networkId, False)
self.listener.rcCalibration()
self.listener.setHighPower(True)
@property
def name(self):
"""Get name for this sensor"""
return 'RFM69 Temperature Sensor'
@property
def state(self):
return self.state
@property
def unit_of_measurement(self):
"""Get unit of measurement"""
return 'C'
@property
def device_state_attributes(self):
return {
'volt': 'Volt',
'temperature': '°',
'humidity': '%'
}
def update(self):
"""Wait for update from sensor"""
self.listener.receiveBegin()
while not self.listener.receiveDone():
time.sleep(.1)
msg = ''.join([chr(letter) for letter in self.listener.DATA])
for pair in msg.split('&'):
key, value = pair.split('=')
self.state[KEYS[key]] = value
if self.listener.ACKRequested():
self.listener.sendACK()
Thanks in advance for help
Best
FragSalat