esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 36 forks source link

Modbus switch on holding register with bitmask causes unexpected side effects #5220

Open wowtor opened 10 months ago

wowtor commented 10 months ago

The problem

Not sure if this is a bug or a feature request.

I have a Modbus switch configured with bitmask and with register_type set to holding.

The expected behavior is that the masked bit is read/written, and nothing else.

The observed behavior is that toggling the switch causes the full register to be written. Bits outside the bitmask are always filled with zeros. This may cause unexpected side effects because the other bits may be used for something else.

The fix should be IMHO, in order of desirability:

Which version of ESPHome has the issue?

2023.11.6

What type of installation are you using?

pip

Which version of Home Assistant has the issue?

2023.12.0

What platform are you using?

ESP32

Board

esp-wrover-kit

Component causing the issue

Modbus

Example YAML snippet

switch:
  name: my switch
  platform: modbus_controller
  address: 5
  bitmask: 0x40
  register_type: holding

Anything in the logs that might be useful for us?

No response

Additional information

No response

github-actions[bot] commented 6 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

makuser commented 5 months ago

/unstale

jinjamator commented 1 month ago

I can see the same behavior, which makes this component unusable with those nice dirt cheep eletchsup 23IOD32 (32 inputs, 32outpus) devices sold on ali. They are only supporting 0x3, 0x6, 0x16 commands for the outputs. So I have to use holding but I also want to switch more than 1 output per 16 outputs to on at a time.

dominikstupka commented 3 weeks ago

Hi guys, do you found any solution for this? I have same issue.

clowrey commented 1 day ago

I am running up against this same issue - there is probably a way to work around it with custom Lambda with variable for the previous register read - I have not developed this yet. But it would be really nice to have it as a built in option.

As it is now the bitmask basically works fine for reading - but the write is the issue as it always overwrites every other bit which is usually not the intention with specific bit digital signals.