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
73.65k stars 30.79k forks source link

[Modbus] Switches do not keep their state across HA restarts #130464

Open pspot2 opened 1 day ago

pspot2 commented 1 day ago

The problem

Normal HA switches (e.g. for example, input_boolean) maintain their state across HA restarts (unless the initial parameter is set). This doesn't seem to be the case for switches configured in the Modbus YAML.

There is the verify functionality mentioned in the documentation. However, some Modbus devices do not support reading individual registers or coils (click). The documentation says that "...If omitted, no verification is done, but the state of the switch is set with each toggle.". Based on this, my expectation would be that the respective state is also kept across HA restarts, which doesn't seem to be the case.

This leads to confusion because after HA restart, Modbus switches suddenly have the off state (although in reality the respective Modbus slave function is on).

To summarize:

Expectation

Modbus switches (where verification is not configured) keep their state across HA restarts.

Actual result

Modbus switches (where verification is not configured) reset their state to off after HA restart.

Way to reproduce

1) Configure a Modbus switch (that does something real on the slave) 2) Turn the switch on. 3) Verify that the respective functionality on the slave is on. 4) Restart HA. 5) Check the state of the switch.

What version of Home Assistant Core has the issue?

2024.11.x

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

Modbus

Link to integration documentation on our website

https://www.home-assistant.io/integrations/modbus/#configuring-switch-entities

Diagnostics information

No response

Example YAML snippet

- name: waveshare_port1
  type: serial
  method: rtu
  port: /dev/serial/by-id/usb-xxxx
  baudrate: 9600
  bytesize: 8
  parity: N
  stopbits: 1
  delay: 0
  message_wait_milliseconds: 30
  timeout: 5
  switches:
    - name: Waveshare relay channel 1
      slave: 0x01
      address: 0x0000
      write_type: coil
      command_on: 0xFF00
      command_off: 0x0000
    - name: Waveshare relay channel 2
      slave: 0x01
      address: 0x0001
      write_type: coil
      command_on: 0xFF00
      command_off: 0x0000
...

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 day ago

modbus documentation modbus source