home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.16k stars 29.84k forks source link

Modbus not working in 2023.2.0b4 #86882

Closed johanschelin closed 1 year ago

johanschelin commented 1 year ago

The problem

Modbus stops working and HA cannot restart.

Removing modbus from configuration.yaml makes restart working.

What version of Home Assistant Core has the issue?

2023.2.0b4

What was the last working version of Home Assistant Core?

2023.1.x

What type of installation are you running?

Home Assistant OS

Integration causing the issue

modbus

Link to integration documentation on our website

https://www.home-assistant.io/integrations/modbus/

Diagnostics information

No response

Example YAML snippet

modbus:
  - name: "Nibe"
    type: tcp
    host: 192.168.1.93
    port: 502
    sensors:
      - name: "Til­lufts­fläkt hastighet 4"
        address: 1038
        slave: 1
        input_type: holding
        scan_interval: 303
        data_type: int16
      - name: "Til­lufts­fläkt hastighet 3"
        address: 1039
        slave: 1
        input_type: holding
        scan_interval: 303
        data_type: int16
      - name: "Til­lufts­fläkt hastighet 2"
        address: 1040
        slave: 1
        input_type: holding
        scan_interval: 303
        data_type: int16
      - name: "Til­lufts­fläkt hastighet 1"
        address: 1041
        slave: 1
        input_type: holding
        scan_interval: 303
        data_type: int16
      - name: "Til­lufts­fläkt hastighet Normal"
        address: 1042
        slave: 1
        input_type: holding
        scan_interval: 303
        data_type: int16
      - name: "ERS S10 - Ventilationsläge"
        address: 104
        slave: 1
        input_type: holding
        scan_interval: 16
        data_type: int16
      - name: "FranluftBT20"
        unit_of_measurement: °C
        address: 19
        count: 1
        precision: 1
        slave: 1
        input_type: input
        scale: 0.1
        scan_interval: 95
        data_type: int16
      - name: "AvluftBT21"
        unit_of_measurement: °C
        address: 20
        count: 1
        precision: 1
        slave: 1
        input_type: input
        scale: 0.1
        scan_interval: 95
        data_type: int16
      - name: "TilluftBT22"
        unit_of_measurement: °C
        address: 42
        count: 1
        precision: 1
        slave: 1
        input_type: input
        scale: 0.1
        scan_interval: 95
        data_type: int16

Anything in the logs that might be useful for us?

Component error: modbus - cannot import name 'ModbusBaseClient' from 'pymodbus.client' (/usr/local/lib/python3.10/site-packages/pymodbus/client/__init__.py)

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @adamchengtkc, @janiversen, @vzahradnik, mind taking a look at this issue as it has been labeled with an integration (modbus) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `modbus` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Change the title of the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign modbus` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


modbus documentation modbus source (message by IssueLinks)

janiversen commented 1 year ago

It seems you have installed the new version, without updating the requirements. This month release uses a new version of pymodbus.

janiversen commented 1 year ago

Please do not add to a milestone, unless you intent to fix it yourself !

janiversen commented 1 year ago

You state it is “restart” that is not working, which is strange because this error should prohibit modbus from starting in the first place.

johanschelin commented 1 year ago

It seems you have installed the new version, without updating the requirements. This month release uses a new version of pymodbus.

Hello Jan and thanks for quick answers. I am beta-testing 2023.2.0b4 and this seems to be an issue in that beta then, that should be fixed before going public?

johanschelin commented 1 year ago

You state it is “restart” that is not working, which is strange because this error should prohibit modbus from starting in the first place.

My error is described as below, so you are correct that it does not work in the first place, and it prevents restart:

"Modbus stops working and HA cannot restart. Removing modbus from configuration.yaml makes restart working."

janiversen commented 1 year ago

Just checked 2023.2.0b4, requirements_all.txt contains:

# homeassistant.components.modbus
pymodbus==3.1.1

And I just did a fresh install of 2023.2.0b4, it runs without problems.

Please verify that you have pymodbus=3.1.1 installed, without that you will get exactly the error you have, you most likely have the old pymodbus.

balloob commented 1 year ago

@johanschelin do you have a custom integration installed that also relies on modbus? Do you have a deps folder in your config dir? Maybe an old modbus package got installed there.

janiversen commented 1 year ago

Just trying to upgrade one of my production systems to see that the UI based upgrade have a problem (which I do not believe).

johanschelin commented 1 year ago

Ok. Something wrong with the update perhaps. how do I confirm the version I use? How do I update it manually? Otherwise the production release is just around the corner and perhaps solves this as it should be updated then.

janiversen commented 1 year ago

As expected it starts without problems: ´´´ 2023-01-29 20:02:28.005 INFO (SyncWorker_7) [homeassistant.components.modbus.modbus] modbus solar communication open

2023-01-29 20:02:28.095 INFO (MainThread) [homeassistant.setup] Setup of domain modbus took 0.1 seconds

´´´

johanschelin commented 1 year ago

@johanschelin do you have a custom integration installed that also relies on modbus? Do you have a deps folder in your config dir? Maybe an old modbus package got installed there.

Hi @balloob

Yes I do run both SolarEdge and Sonnenbatterie from HACS which use modbus. https://github.com/binsentsu/home-assistant-solaredge-modbus https://github.com/weltmeyer/ha_sonnenbatterie

I do have 'deps' folder in my config directory, it is empty though

balloob commented 1 year ago

Your solaredge intgration relies on modbus 1.5 https://github.com/binsentsu/home-assistant-solaredge-modbus/blob/master/custom_components/solaredge_modbus/manifest.json#L5

So this is not an issue in Home Assistant.

johanschelin commented 1 year ago

Ok - as I understand it - using the Solaredge Modbus from Hacs prevents the modbus to update to the versoin that 2023.2.x will use.

Does that mean that modbus will break for anyone using 2023.2.x when it is released - if they still want to use the solaredge integration? And that my only option is to uninstall the Solaredge modbus before upgrading?

Just to be clear, it is the "normal" modbus that i configure in configuration.yaml that stops working after upgrade to 2023.2 beta. The solaredge and sonnenbatterie works. So this will probably happen to all users of the Solaredge Modbus HACS integration.

Understand that this is not a HA issue in that case, but should be written as a Breaking Change or a note in the update. I can contact the hacs-integration owner and refer to this thread so he can update to reqs and support the new modbus library.

janiversen commented 1 year ago

SolarEdge have

"requirements": ["pymodbus==1.5.2"]

seems that have not been updated for years. BUT this cannot have worked with 2023.1.x as stated in the description.

The modbus integration stopped using pymodbus version 1.5.2 a couple of years ago.

Please disable your custom components, then modbus will start to work.

johanschelin commented 1 year ago

SolarEdge have

"requirements": ["pymodbus==1.5.2"]

seems that have not been updated for years. BUT this cannot have worked with 2023.1.x as stated in the description.

The modbus integration stopped using pymodbus version 1.5.2 a couple of years ago.

Please disable your custom components, then modbus will start to work.

Ok, that is interestering... Because the Solaredge integrations still works fine, i get information from it - showing the very little energy produced today, and all the data from my AC Voltage and so on... The Sonnenbatterie also works and is sending info right now. So does the oficiall Nibe Integration that also uses modbus....

So, it seems like the integrations that provide modbus actually work, but not if I use config.yaml (which I use for 3-4 sensors that are not available in the Nibe integration yet).

Will test to disable SolarEdge it to definitely nail what is the problem.

johanschelin commented 1 year ago

Now tested to disable both SolarEdge Modbus and Sonnenbatterie integrations and restarted. As you said, the core modbus then works fine. Enabled Sonnenbatterie, and it still works fine. Enabled Solaredge Modbus and then the problem is now inverted - meaning that the core modbus works, but the SolarEdge does not start (probably because it is using an old modbus version). Showing this in the log so it is searchable for others that get this problem.

2023-01-29 20:53:36.473 ERROR (MainThread) [homeassistant.setup] Setup failed for custom integration solaredge_modbus: Unable to import component: No module named 'pymodbus.client.sync'

So... to conclude this:

Solution:

https://github.com/WillCodeForCats/solaredge-modbus-multi

Thanks for the help @balloob and @janiversen . Hopefully this issue can help other users in the same situation.

Tupsi commented 1 year ago

thanks for the explanation @johanschelin and the other option to use for solaredge . Just stumbled over the same problem after upgrading to the latest ha version.

DennisHedberg commented 1 year ago

Hi! Had same error message / problem with HACS Integration of Huawei Solar (via modbus).

Solution: Updated Huawei Solar to version V1.2.4 resolved the problem.

Thanks for your information!

Bimboboy007 commented 1 year ago

I have the same problem. Modbus sensors created via yaml no longer work. Use HA 2023.3.1 Use the SBFSpot integration because everything works. had the suspicion at the beginning that the communication from the inverter had switched off, but it is on.

janiversen commented 1 year ago

Please a new issue, with logs etc. This issue is solved. Make sure you test without custom components.

Actually if you have the same issue, then the solution is the same, just follow it.

Bimboboy007 commented 1 year ago

I turned them all off and didn't do anything. I have a 2nd system to test on, it runs the same and it works. Use SBFSpot lan, SMA Speedwire Integration and SMA Energy Meter and the modbus yaml on it without problems.

johanschelin commented 1 year ago

I turned them all off and didn't do anything. I have a 2nd system to test on, it runs the same and it works. Use SBFSpot lan, SMA Speedwire Integration and SMA Energy Meter and the modbus yaml on it without problems.

Please do as requested - open a new issue with logs. This issue is closed.