Hi @aequitas, first of all thanks for your effort for getting the dutch smart meter supported in Home Assistant.
I have installed HA in a virtual environment on a RPi using Ubuntu Jessie (and the RPi All-in-One installer), but have some issues getting your software running. It seems that HA is not able to access the GPIO pins to which the cable is connected:
16-11-27 21:49:15 homeassistant.components.sensor: Error while setting up platform dsmr
Traceback (most recent call last):
File "/home/hass/.homeassistant/deps/serial/serialposix.py", line 265, in open
self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
PermissionError: [Errno 13] Permission denied: '/dev/ttyAMA0'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 145, in _async_setup_platform
entity_platform.async_add_entities, discovery_info
File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/sensor/dsmr.py", line 109, in async_setup_platform
transport, _ = yield from hass.loop.create_task(dsmr)
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/asyncio/tasks.py", line 237, in _step
result = next(coro)
File "/usr/lib/python3.4/asyncio/coroutines.py", line 141, in coro
res = func(*args, **kw)
File "/home/hass/.homeassistant/deps/serial_asyncio/__init__.py", line 409, in create_serial_connection
ser = serial.serial_for_url(*args, **kwargs)
File "/home/hass/.homeassistant/deps/serial/__init__.py", line 88, in serial_for_url
instance.open()
File "/home/hass/.homeassistant/deps/serial/serialposix.py", line 268, in open
raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyAMA0: [Errno 13] Permission denied: '/dev/ttyAMA0'
My vritual port is owned by the group tty:
hass@raspberrypi:/home/pi$ ls -la /dev/ttyAMA0
crw--w---- 1 root tty 204, 64 Nov 27 18:58 /dev/ttyAMA0
My virtualenv user is added to the tty group (as well as the gpio and dialout):
hass@raspberrypi:/home/pi$ groups | grep tty
hass tty dialout gpio
If I try as a different user (also memeber of tty) it seems it does work, but only when I elevate using sudo I get dsmr_console to properly access the port and report the data from the datagram(s):
pi@raspberrypi:~ $ ls -la /dev/ttyAMA0
crw--w---- 1 root tty 204, 64 Nov 27 18:58 /dev/ttyAMA0
pi@raspberrypi:~ $ groups | grep tty
pi adm tty dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi
pi@raspberrypi:~ $ dsmr_console --help
usage: dsmr_console [-h] [--device DEVICE] [--version {2.2,4}] [-v]
[-p {N,E,O}] [-b {7,8}]
Output DSMR data to console.
optional arguments:
-h, --help show this help message and exit
--device DEVICE port to read DSMR data from
--version {2.2,4} DSMR version (2.2, 4)
-v, --verbose increase output verbosity
-p {N,E,O}, --parity {N,E,O}
Override serial parity setting.
-b {7,8}, --bytesize {7,8}
Override serial bytesize setting.
pi@raspberrypi:~ $ dsmr_console --device /dev/ttyAMA0 --version 2.2
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/serial/serialposix.py", line 265, in open
self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
PermissionError: [Errno 13] Permission denied: '/dev/ttyAMA0'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/dsmr_console", line 9, in <module>
load_entry_point('dsmr-parser==0.3', 'console_scripts', 'dsmr_console')()
File "/usr/local/lib/python3.4/dist-packages/dsmr_parser/__main__.py", line 63, in console
for telegram in serial_reader.read():
File "/usr/local/lib/python3.4/dist-packages/dsmr_parser/serial.py", line 63, in read
with serial.Serial(**self.serial_settings) as serial_handle:
File "/usr/local/lib/python3.4/dist-packages/serial/serialutil.py", line 236, in __init__
self.open()
File "/usr/local/lib/python3.4/dist-packages/serial/serialposix.py", line 268, in open
raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyAMA0: [Errno 13] Permission denied: '/dev/ttyAMA0'
pi@raspberrypi:~ $ sudo dsmr_console --device /dev/ttyAMA0 --version 2.2
Power Consumption (low) 5782.433 kWh
Power Consumption (normal) 4304.307 kWh
Power Consumption 0.18 kW
Power Tariff 0001 None
Power Production 0.00 kW
Power Production (low) 0.000 kWh
Power Production (normal) 0.000 kWh
Power Consumption (low) 5782.434 kWh
Power Consumption (normal) 4304.307 kWh
Power Consumption 0.20 kW
Power Tariff 0001 None
Power Production 0.00 kW
Power Production (low) 0.000 kWh
Power Production (normal) 0.000 kWh
^CTraceback (most recent call last):
File "/usr/local/bin/dsmr_console", line 9, in <module>
load_entry_point('dsmr-parser==0.3', 'console_scripts', 'dsmr_console')()
File "/usr/local/lib/python3.4/dist-packages/dsmr_parser/__main__.py", line 63, in console
for telegram in serial_reader.read():
File "/usr/local/lib/python3.4/dist-packages/dsmr_parser/serial.py", line 67, in read
line = serial_handle.readline()
File "/usr/local/lib/python3.4/dist-packages/serial/serialposix.py", line 472, in read
ready, _, _ = select.select([self.fd, self.pipe_abort_read_r], [], [], timeout.time_left())
KeyboardInterrupt
pi@raspberrypi:~ $
Do you have any clue what could by the issue and how to get HA to read the DSMR data from inside the virtualenv?