Light powered by MODBUS switch

Hi Guys,

I have a Modbus board of switches and want to use them in a variety of applications. It worked before when I tried to describe the light in a simple statement with the Modbus as a hub to call, but I want to make it a bit more modular, defining the light function through the switch. So, I thought to do something like:

modbus:
  - name: swbf2
    type: tcp
    host: swb-f2
    port: 17000

switch:
  - platform: modbus
    scan_interval: 5
    coils:
    - name: switch1
      hub: swbf2
      coil: 0
      slave: 0
      command_on: 1
      command_off: 0
      verify_state: true

light:
  - platform: switch
    name: GuestRoom_MainLight
    entity_id: switch.switch1

I see that am getting the following error:
2021-06-16 16:48:57 ERROR (MainThread) [homeassistant.components.switch] Error while setting up modbus platform for switch
Traceback (most recent call last):
File “/home/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity_platform.py”, line 250, in _async_setup_platform
await asyncio.shield(task)
File “/home/homeassistant/lib/python3.8/site-packages/homeassistant/components/modbus/switch.py”, line 25, in async_setup_platform
for entry in discovery_info[CONF_SWITCHES]:
TypeError: ‘NoneType’ object is not subscriptable

I see that the HA is trying to communicate to the modbus server, just okay, and it keeps the connection running. Any ideas?

Thanks in advance,
Regards Matt

It’s switches instead of switch!!!

switches:

  • platform: modbus
    scan_interval: 5
    coils:
    • name: switch1
      hub: swbf2
      coil: 0
      slave: 0
      command_on: 1
      command_off: 0
      verify_state: true

Jakke17,

Thanks a lot man! I will try it out as soon as I will get the power into the module. I am new to the HA and was following the documentation, where the example is:

 sensor:
   - platform: mqtt
     state_topic: "home/bedroom/temperature"
     name: "MQTT Sensor 1"
   - platform: mqtt
     state_topic: "home/kitchen/temperature"
     name: "MQTT Sensor 2"
   - platform: rest
     resource: "http://IP_ADDRESS/ENDPOINT"
     name: "Weather"
 
 switch:
   - platform: vera

Why the difference? Any other things like this I need to be aware of?

Cheers

If you are using/upgrading to Home Assistant version 2021.7, make sure to change your format according to Modbus - Configuring Platform Switch - otherwise it will break.

Good morning Ardy,

Just to clarify, these (-s)'es are specific to the modbus implementation and in the rest of HA it is still plan switch, light, etc., correct?

Thank you,
Regards

The link that I posted previously is only for Modbus Integration. To configure other integration, I suggest you refer to the current documentation in case something changes in the recent updates.

1 Like

Thank you Ardy!