NECH2004 / smartmeter_austria

Home Assistant integration for Austrian Smart Meter using the M-BUS interface
MIT License
10 stars 3 forks source link

Error while setup: "Unable to connect, please check serial port and electrical connection" #2

Closed sebi-alt closed 6 months ago

sebi-alt commented 1 year ago

System Health details

System Information

version core-2023.5.4
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.10.11
os_name Linux
os_version 6.1.21-v8
arch aarch64
timezone Europe/[redacted]
config_dir /config
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 10.1 -- | -- update_channel | stable supervisor_version | supervisor-2023.06.2 agent_version | 1.5.1 docker_version | 23.0.3 disk_total | 219.4 GB disk_used | 10.3 GB healthy | true supported | true board | rpi4-64 supervisor_api | ok version_api | ok installed_addons | ESPHome (dev) (dev), Samba share (10.0.0), Terminal & SSH (9.7.0), Studio Code Server (5.5.6), FTP (4.7.0)
Dashboards dashboards | 1 -- | -- resources | 0 views | 4 mode | storage
Recorder oldest_recorder_run | May 29, 2023 at 12:02 -- | -- current_recorder_run | June 18, 2023 at 16:41 estimated_db_size | 84.33 MiB database_engine | sqlite database_version | 3.40.1

Checklist

Describe the issue

Thank you for providing this integration. I am running into some issues during setup and would be very thankful for any help.

During setup, the integration UI fails with the prompt "Unable to connect, please check serial port and electrical connection". According to smartmeter_austria_energy/src/smartmeter_austria_energy/exceptions.py this is due to an unexpected byte stream.

What I did for troubleshooting:

I am using this MBUS to USB converter. Unfortunately, the images of the amazon page did not match with the delivered product, so there are some images of the actual device.

I installed the addon by copying the contents of custom_components (not via hacs)

As far as I am concerned, I got a bad USB dongle. Is there anything I missed? Thanks for any help!

Reproduction steps

  1. Install the integration by adding copying all contents of custom_components to your custom_components directory
  2. Enable the customer interface of your smartmeter and get your encryption key via the website of your energy supplier
  3. Purchase this USB to MBUS dongle
  4. Add the integration

Debug logs

This error originated from a custom integration.

Logger: custom_components.smartmeter_austria.config_flow
Source: custom_components/smartmeter_austria/config_flow.py:52
Integration: Smart Meter Austria (documentation, issues)

Could not connect to device=/dev/ttyUSB0

Diagnostics dump

No response

NECH2004 commented 1 year ago

Hello sebi-alt, it seems that Homeassistant is able to find your dongle. If you look into your hardware configuration (http://homeassistant.local:8123/config/hardware) you should be able to find your dongle. It should be your Prolific converter. Normally the error occurs if opening the data stream is possible but decoding the data is not possible. This could happen if your key is wrong and decoding returns garbage or your stream is not as supposed. Mind that copy/paste sometimes changes characters (eg. quotation marks).

Reading from the adapter can only be done from one instance, perhaps an other program uses the device?. Can HA really read from the device?. I'm running HA-OS in a Proxmox environment, the VM runs privileged.

Also possible that your provider has changed its protocol. Which provider/smart meter do you use?

A simple way to find your problems would be to test your USB-device on your desktop PC. My implementation repo (https://github.com/NECH2004/smartmeter_austria_energy) that mainly is based on Stefan's code would be a good starting point. It contains all functions that are used by HA.

Just setup a Python development environment and connect your M-Bus dongle into your (windows) PC. The sample should show how to connect, debugging the Smartmeter class and the read() method should be quite easy.

Hope this helps.

sebi-alt commented 1 year ago

Hello NECH2004, thank you for this fast response and sorry for not responding for a while.

The key is definitely correct and homeassistant labels the dongle as an usb-Prolific_Technology_Inc._USB-Serial_Controller_CPEGb118D16-if00-port0. My only instance is running on a Raspberry 4 using HA-OS. The smartmeter is of type Honeywell DM515.

On my Windows PC the basic script in the readme of the implementation repo raises an error in smartmeter.py: SmartmeterTimeoutException in line 138 caused by SmartmeterException in line 148. What could be the reason for this timeout issue?

Any ideas on how to proceed? Again, thank you for your fast and excellent response

NECH2004 commented 1 year ago

Hello Sebi, sorry for the delay (vacation)...

Here is a python test file doing some calls against the serial MBUS adapter and helps to debug your problem. The test file sometimes fails executing test step no. 6 if executed on one of my Windows PC leading to the same error. It seems that the default wait interval of 1 s could be critical. Perhaps the reading intervals of the Smart Meters are inaccurate or the timing between the Smart Meter types is different.. If step 1 to 5 are OK, you can try to add the additional parameter 'interval' to the SmartMeter constructor. A value of 2 (max 5) seconds fixes (my) timeout problem. Hope it helps.

test.zip

sebi-alt commented 1 year ago

I hope you had a great vacation and thank you for coming back to me with such excellent help After finding all significant start bytes with the test file I was sure that my hardware was working as expected. The read operation took up to 10 seconds so the TimeOutException was justified. After removing this else-statement I was able to get the data from my smartmeter. Raising the interval to 2 did not work, so I decided to try it with interval=4 which solved it.

I locally changed it in the homeassistant component here. The integration works smoothly now.

Thank you very much for your help

sebi-alt commented 6 months ago

After I changed my setup, I re-added the integration and it worked fine after a few attempts.