Nippey
(Nippey)
October 14, 2022, 9:17am
1
Hi,
I am trying to integrate a 32-channel digital input “N4DIM32” into my installation using a RS485-Ethernet gateway. I use it for magnetic (reed) contacts on my windows.
I can communicate with the 32-IN using other tools, which can use the “read holding register” (0x03) command.
But now, I tried to setup in HA:
modbus:
- name: window_contacts
type: rtuovertcp
host: 192.168.188.86
port: 502
sensors:
- name: "Fenster 1"
slave: 1
address: 128
device_class: window
input_type: holding
This will fail. It won’t work with the proposed ‘coil’ or ‘discrete’
Invalid config for [modbus]: value must be one of ['coil', 'discrete_input'] for dictionary value @ data['modbus'][0]['binary_sensors'][0]['input_type']. Got 'holding'.
Then I tried to change over to ‘sensors’ instead of ‘binary_sensors’, as I got ‘holding’ there.
Now, it won’t accept my device_class “window” anymore.
Invalid config for [modbus]: expected SensorDeviceClass or one of [........] for dictionary value @ data['modbus'][0]['sensors'][0]['device_class']. Got 'window'.
If I use pymodbus directly, it works fine:
from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient('192.168.188.86',port=502)
result = client.read_holding_registers(slave=1,address=128,count=3) #Reading 3 registers at once
print(result.registers[0]) #"1" -> Window 1 (open)
print(result.registers[1]) #"0" -> Window 2 (closed)
print(result.registers[2]) #"0" -> Window 3 (closed)
What is the best way to get my values here.
(I can either read 32 separate registers, one for each input, or 2 16-bit registers that contain all 32 inputs.)
Nippey
(Nippey)
October 17, 2022, 7:14am
2
Created a patch for modbus:
home-assistant:dev
← Nippey:patch-1
opened 07:00AM - 17 Oct 22 UTC
<!--
You are amazing! Thanks for contributing to our project!
Please, DO N… OT DELETE ANY TEXT from this template! (unless instructed).
-->
## Breaking change
<!--
If your PR contains a breaking change for existing users, it is important
to tell them what breaks, how to make it work again and why we did this.
This piece of text is published with the release notes, so it helps if you
write it towards our users, not us.
Note: Remove this section if this PR is NOT a breaking change.
-->
## Proposed change
<!--
Describe the big picture of your changes here to communicate to the
maintainers why we should accept this pull request. If it fixes a bug
or resolves a feature request, be sure to link to that issue in the
additional information section.
-->
I have a 32-channel input ("N4DIM32") for modbus. This device exposes its internal states via holding registers.
(If required, I can attach the interface description provided by the seller.)
As binary_sensor currently only supports CALL_TYPE_COIL, CALL_TYPE_DISCRETE:
**ADDED: Support for CALL_TYPE_REGISTER_HOLDING.**
## Type of change
<!--
What type of change does your PR introduce to Home Assistant?
NOTE: Please, check only 1! box!
If your PR requires multiple boxes to be checked, you'll most likely need to
split it into multiple PRs. This makes things easier and faster to code review.
-->
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [x] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
## Additional information
<!--
Details are important, and help maintainers processing your PR.
Please be sure to fill out additional details, if applicable.
-->
- This PR fixes or closes issue: fixes #
- This PR is related to issue:
- Link to documentation pull request: https://github.com/home-assistant/home-assistant.io/pull/24595
- Community link: https://community.home-assistant.io/t/modbus-binary-sensor-cannnot-read-from-holding-register/474938
## Checklist
<!--
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.
-->
- [x] The code change is tested and works locally.
- [x] Local tests pass. **Your PR cannot be merged unless tests pass**
- [x] There is no commented out code in this PR.
- [x] I have followed the [development checklist][dev-checklist]
- [x] The code has been formatted using Black (`black --fast homeassistant tests`)
- [ ] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [x] Documentation added/updated for [www.home-assistant.io][docs-repository]
If the code communicates with devices, web services, or third-party tools:
- [ ] The [manifest file][manifest-docs] has all fields filled out correctly.
Updated and included derived files by running: `python3 -m script.hassfest`.
- [ ] New or updated dependencies have been added to `requirements_all.txt`.
Updated by running `python3 -m script.gen_requirements_all`.
- [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to `.coveragerc`.
<!--
This project is very active and we have a high turnover of pull requests.
Unfortunately, the number of incoming pull requests is higher than what our
reviewers can review and merge so there is a long backlog of pull requests
waiting for review. You can help here!
By reviewing another pull request, you will help raise the code quality of
that pull request and the final review will be faster. This way the general
pace of pull request reviews will go up and your wait time will go down.
When picking a pull request to review, try to choose one that hasn't yet
been reviewed.
Thanks for helping out!
-->
To help with the load of incoming pull requests:
- [ ] I have reviewed two other [open pull requests][prs] in this repository.
[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone+-status%3Afailure
<!--
Thank you for contributing <3
Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/en/development_checklist.html
[manifest-docs]: https://developers.home-assistant.io/docs/en/creating_integration_manifest.html
[quality-scale]: https://developers.home-assistant.io/docs/en/next/integration_quality_scale_index.html
[docs-repository]: https://github.com/home-assistant/home-assistant.io
home-assistant:next
← Nippey:patch-2
opened 07:11AM - 17 Oct 22 UTC
Modbus: Add support for Holding Registers to Binary Sensor
## Proposed change…
<!--
Describe the big picture of your changes here to communicate to the
maintainers why we should accept this pull request. If it fixes a bug
or resolves a feature request, be sure to link to that issue in the
additional information section.
-->
## Type of change
<!--
What types of changes does your PR introduce to our documentation/website?
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR.
-->
- [ ] Spelling, grammar or other readability improvements (`current` branch).
- [ ] Adjusted missing or incorrect information in the current documentation (`current` branch).
- [ ] Added documentation for a new integration I'm adding to Home Assistant (`next` branch).
- [ ] I've opened up a PR to add logo's and icons in [Brands repository](https://github.com/home-assistant/brands).
- [x] Added documentation for a new feature I'm adding to Home Assistant (`next` branch).
- [ ] Removed stale or deprecated documentation.
## Additional information
<!--
Details are important, and help maintainers processing your PR.
Please be sure to fill out additional details, if applicable.
-->
- Link to parent pull request in the codebase: https://github.com/home-assistant/core/pull/80460
- Link to parent pull request in the Brands repository:
- This PR fixes or closes issue: fixes #
- Community post: https://community.home-assistant.io/t/modbus-binary-sensor-cannnot-read-from-holding-register/474938
## Checklist
<!--
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.
-->
- [x] This PR uses the correct branch, based on one of the following:
- I made a change to the existing documentation and used the `current` branch.
- I made a change that is related to an upcoming version of Home Assistant and used the `next` branch.
- [ ] The documentation follows the Home Assistant documentation [standards].
[standards]: https://developers.home-assistant.io/docs/documenting/standards