core: modbus platform switch component doesn't work after upgrade to 2021.4.1

The problem

After upgrade to version 2021.4.1 from 2021.3.4 modbus switch can’t initialize anymore. Also, found that documentation is not correct. For ex.: the doc says that input_type can be holding/discrete/coil but in fact allowed values are coil/discrete/input

What is version of Home Assistant Core has the issue?

2021.4.1

What was the last working version of Home Assistant Core?

2021.3.4

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Modbus

Link to integration documentation on our website

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

Example YAML snippet

modbus:
- name: hub
  type: tcp
  host: 192.168.88.3
  port: 502
  switches:
    - name: Ventilation
      slave: 1
      address : 9
      command_on: 1
      command_off: 0
  sensors:
    - name: Fan In Speed
      slave: 1
      address: 10
      scale: 1
      offset: 0
    - name: Fan Out Speed
      slave: 1
      address: 11
      scale: 1
      offset: 0
    - name: Supply air
      unit_of_measurement: °C
      slave: 1
      address: 14
      precision: 1
    - name: Return air
      unit_of_measurement: °C
      slave: 1
      address: 12
      precision: 1
    - name: Exhaust air
      unit_of_measurement: °C
      slave: 1
      address: 15
      precision: 1
    - name: Fresh air
      unit_of_measurement: °C
      slave: 1
      address: 13
      precision: 1
    - name: By-Pass
      slave: 1
      address: 18
      scale: 1
      offset: 0
    - name: By-Pass Open Temperature
      slave: 1
      address: 2
      scale: 1
      offset: 0
    - name: By-Pass Open Interval
      slave: 1
      address: 3
      scale: 1
      offset: 0

Anything in the logs that might be useful for us?

Error while setting up modbus platform for switch
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 205, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/src/homeassistant/homeassistant/components/modbus/switch.py", line 132, in async_setup_platform
    switches.append(ModbusRegisterSwitch(hub, entry))
  File "/usr/src/homeassistant/homeassistant/components/modbus/switch.py", line 253, in __init__
    self._verify_state = config[CONF_VERIFY_STATE]
KeyError: 'verify_state'

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

Or you could use Modbus as a custom component. Therefore, it won’t be affected by Home Assistant updates, and you can have a working install till next stable Home Assistant gets released.

All you have to do is to copy the patched modbus folder into <config directory>/custom_components/

https://developers.home-assistant.io/docs/creating_integration_file_structure/#where-home-assistant-looks-for-integrations