Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing to Modbus registers stopped working #94149

Closed
duan-dt opened this issue Jun 7, 2023 · 17 comments
Closed

Writing to Modbus registers stopped working #94149

duan-dt opened this issue Jun 7, 2023 · 17 comments
Assignees

Comments

@duan-dt
Copy link

duan-dt commented Jun 7, 2023

The problem

At some point of time (unsure if this was due to an update), writing to a modbus register stopped working for me. I don't use it (writing) often, however for the past week or so I have been trying to write to a modbus register with no success. Writing to the register does not fail or produce an error, it just does not update the register with the new value. I have no problem reading modbus registers and have been able to do so continuously for months already.

I tried different HA installations: HA Supervised, HA OS, different hardware, e.g. Odroid XU4, two different Generic X86-64 machines. The device (a Growatt SPF 5000 ES inverter) is connected via an onboard usb-to-serial device (the underlying chipset is Silicon Lab CP210x).

image

What version of Home Assistant Core has the issue?

2023.5.4

What was the last working version of Home Assistant Core?

No response

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

home-assistant_2023-06-07T09-47-19.107Z.log

Example YAML snippet

odbus:
  - name: Left_Inverter
    type: serial
    port: /dev/serial/by-id/usb-Silicon_Labs_CP2102N_USB_to_UART_Bridge_Controller_789195d4659cec11b292654d73138bba-if00-port0
    baudrate: 9600
    bytesize: 8
    method: rtu
    parity: N
    stopbits: 1
    delay:  3
    retry_on_empty: true
    # retries: 10
    # close_comm_on_error: true
    message_wait_milliseconds: 1000
    #timeout: 5
    sensors:

      - name: Output source config (Left-Inverter)
        scan_interval: 5
        address: 1
        slave: 1
        input_type: holding
        data_type: int16
        scale: 1
        offset: 0
        precision: 0
        unique_id:  Left_Inverter.OutputSourceConfig
      - name: Charging source config (Left-Inverter)
        scan_interval: 5
        address: 2
        slave: 1
        input_type: holding
        data_type: int16
        scale: 1
        offset: 0
        precision: 0
        unique_id:  Left_Inverter.ChargingSourceConfig        

#Snippet of automation / Service call through Developer Tools
service: modbus.write_register
data:
  hub: Left_Inverter
  address: 1
  slave: 1
  value: [2,0]

Anything in the logs that might be useful for us?

No error messages that I could see...

Additional information

No response

@home-assistant
Copy link

home-assistant bot commented Jun 7, 2023

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 Renames 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
Copy link
Member

Two things:

  • please active debug logging as documented in the modbus integration
  • please remove your custom_components, in order to exclude them

@duan-dt
Copy link
Author

duan-dt commented Jun 7, 2023

Hi

Debug is activated in configuration.yaml:

logger:
default: warning
logs:
homeassistant.components.modbus: debug
pymodbus: debug
homeassistant.components.serial: debug

I've removed all custom_components, for some odd reason HACS still comes up in the log (eventhough I removed the integration as well).
home-assistant_2023-06-07T17-15-44.631Z.log

@janiversen
Copy link
Member

there are no debug lines from neither pymodbus nor modbus.

It means you did not restart HA, so it did not pickup the configuration or the modbus integration never connected.

you can control it yourself, the log needs to contain a lot modbus debug lines.

@janiversen
Copy link
Member

please remember We need a debug log containing your attempt to write, so we can see what actually happens. One of the possible problems is that your device wants a write_register and not write_registers as you have chooses by using an array.

@duan-dt
Copy link
Author

duan-dt commented Jun 8, 2023

I've tried multiple restarts and multiple register writes and it is still not showing up in the logs. Can you perhaps confirm if the logging is set up correctly as I don't know how else I can get it to log... The only modbus entries I see is on startup when the port is opened.

Log file setup in configuration.yaml:

Loads default set of integrations. Do not remove.

default_config:

logger:
default: warning
logs:
homeassistant.components.modbus: debug
pymodbus: debug
homeassistant.components.serial: debug

Load frontend themes from the themes folder

frontend:
themes: !include_dir_merge_named themes

Text to speech

tts:

  • platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

homeassistant:
packages:
inverters: !include modbus.yaml

@janiversen
Copy link
Member

seems you did not do the needed spaces at the start of each.

The documentation have an example ready to copy/paste.

@duan-dt
Copy link
Author

duan-dt commented Jun 8, 2023

Removed it completely and copied and paste from the Modbus Integration webpage.
image

It is still not showing anything. The only messages is the following two lines which indicates to me that the log works but the Service Call does not log anything:

2023-06-08 08:53:23.199 INFO (SyncWorker_1) [homeassistant.components.modbus.modbus] modbus Left_Inverter communication open
2023-06-08 08:53:23.214 INFO (SyncWorker_4) [homeassistant.components.modbus.modbus] modbus Right_Inverter communication open

@duan-dt
Copy link
Author

duan-dt commented Jun 9, 2023

Managed to get the log to work after I have yet again did a clean install. This is now running a HA OS on a Odroid XU4.

I can see the write errors but it is not clear to me what it actually mean

home-assistant_2023-06-09T16-27-47.718Z.log

@janiversen
Copy link
Member

you have a problem:

Left_Inverter: Modbus Error: [Connection] Failed to

pymodbus.logging] [Errno 2] could not open port /dev/serial/by-id/usb-Silicon_Labs_CP2102N_USB_to_UART_Bridge_Controller_789195d4659cec11b292654d73138bba-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-Silicon_Labs_CP2102N_USB_to_UART_Bridge_Controller_789195d4659cec11b292654d73138bba-if00-port0'
2023-06-09 17:39:24.035 DEBUG (SyncWorker_3) [homeassistant.components.modbus.modbus]

seems your serial port cannot be opened, this is a problem outside our control.

This continues throughout the log, so you have not read any values, and of course you are also not able to write registers.

Closing this issue as it is a user problem and not a bug in the integration.

@janiversen janiversen closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2023
@duan-dt
Copy link
Author

duan-dt commented Jun 10, 2023

Hi @janiversen

i’ve seen the message but I don’t think it is the cause. I am able to successfully read from the device. The error randomly appears- I suspect it sometimes updates too quickly or updates during a change on the hardware parameters itself. Here is proof that it is not the port thab cannot be opened:

image
image
image

@janiversen
Copy link
Member

Well if you say so, I requested a debug log showing the write fails and the successful communication before, so I assumed you provided that.

I can only interpret the log you supply, and the last log was clearly a connect error so if you claim that is not the problem then please provide a log showing the problem.

@duan-dt
Copy link
Author

duan-dt commented Jun 10, 2023

Hi

Here's an updated log file:
home-assistant_2023-06-10T08-28-11.348Z.log

I have removed all but one of the addresses I am scanning. I am able to write to the register successfully (see below screenshot) although I noticed two errors in the log file (above) again.

image

Could updating/scanning of the modbus sensor entities cause or prevent a write cycle from taking place? If so, is there a way to suspend modbus reading/scanning until writing is complete?

@janiversen
Copy link
Member

That is not a debug log ! apart from that the only error is the I/O and that will surely interrupt both read and write cycles,

Without a real debug log containing a failing write I cannot help you further.

@duan-dt
Copy link
Author

duan-dt commented Jun 10, 2023

Thank you trying to assist.
I don’t know how else to get logs. I can only access the logs under Settings -> System -> Logs which is what I’ve sent.

The device is not added as an integration so I cannot enable debug logging as with other integrations. The sensors appear as entities.

@janiversen
Copy link
Member

#Read the documentation for the modbus integration

@hifihedgehog
Copy link

@janiversen, /dev/serial/by-id is broken due to a recent Linux update.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants