2
votes

Integrating a MODBUS installation with Home Assistant

MODBUS controller in the Gavazzi SH2WEB24

Home Assistant Configiguration.yaml:

modbus:
  name: SmartHouse
  type: tcp
  host: <my_ip_addr>
  port: 502

# SmartHouse Functions
switch:
  platform: modbus
  scan_interval: 10
  registers:
    - name: test1
      hub: SmartHouse
      slave: 1
      register: 352
      command_on: 1
      command_off: 0

# SmartHouse Convert to light
light:
  - platform: switch
    name: Light_test1
    entity_id: switch.test1

In the Home Assistant startup logs, we see this error:

Logger: pymodbus.client.sync Source: /usr/local/lib/python3.8/site-packages/pymodbus/client/sync.py:214 First occurred: 10:40:02 (1 occurrences) Last logged: 10:40:02

Connection to (<my_ip_addr>, 502) failed: [Errno 111] Connection refused

The modbus controller is working fine when used with the Gavazzi (windows) software. In that software, only IP and port need to be specified, no other credentials. So why would there be a "connection refused" error addressing it from Home Assistant?

1

1 Answers

1
votes

Got it working.

Key is to enable modes in the SHTOOL software: in project settings / communication enable "Modbus TCP/IP"

Also the modes map must be created: Modbus / Modbus map: click a bulb, expand it and click the 'v' icon to enable the mapping. You can as well do that with all entities to map all of them to modbus.

Note the "use address" field. This is important, and will be used as "register" value below (see **). This list can be exported to ckv via "Save modbus as CSV"

Go to Home Assistant Enable the "File Editor" if you didn't do this already. See this link for more info

Now ediy the config file: Click "File Editor" in the left pane. Look for /config/configuration.yaml

Then add these entries:

modbus:
  name: SmartHouse
  type: tcp
  host: <your smart house IP>
  port: 502

# SmartHouse Functions
switch:
  platform: modbus
  scan_interval: 10
  registers:
    - name: light1
      hub: SmartHouse
      slave: 1
      register: <register as noted above **>
      command_on: 1
      command_off: 0

# SmartHouse Convert to light
light:
  - platform: switch
    name: light1
    entity_id: light1

That's basically it. Now you can use this light e.g. in the dashboard. Go the dashboard, edit it and add the light. You can click it to toggle, and see the status as well.