Using Modbus RTU Relay with Homeassistant

From Waveshare Wiki
Jump to: navigation, search

Preparation

Hardware Preparation

1. Install Raspberry Pi OS System

Modbus RTU Relay RPI01.png

  • After installation, the Raspberry Pi OS system environment is as follows:

Modbus RTU Relay RPI02.png

2. Install Home Assistant Core

Modbus RTU Relay RPI03.png

  • After installation, open the browser and run Home Assistant:

Modbus RTU Relay RPI04.png

3. Environment Configuration

  • Hardware connection diagram:

Modbus RTU Relay RPI05.png

Execute the following command to enter the Raspberry Pi configuration:

sudo raspi-config

Choose Interfacing Options -> Serial -> No -> Yes:
You need to disable the login shell and enable the serial port hardware:
L76K GPS Module RPI.png

  • Configure Homeassistant's configuration.yaml on Raspberry Pi, file path: /home/homeassistant/.homeassistant/configuration.yaml
sudo nano /home/homeassistant/.homeassistant/configuration.yaml 

Add the following content at the end of the file:

modbus:
  - name: modbus_hub
    type: serial
    port: /dev/ttyS0
    baudrate: 9600
    bytesize: 8
    method: rtu
    parity: N
    stopbits: 1
    binary_sensors:
      - name: my_relay
        address: 0
        device_class: plug
        input_type: coil
        scan_interval: 15
        slave: 1
        slave_count: 15
        unique_id: my_relay
    lights:
      - name: "Light_1"
        address: 0
        write_type: coil
        slave: 1
      - name: "Light_2"
        address: 1
        write_type: coil
        slave: 1
      - name: "Light_3"
        address: 2
        write_type: coil
        slave: 1
      - name: "Light_4"
        address: 3
        write_type: coil
        slave: 1
      - name: "Light_5"
        address: 4
        write_type: coil
        slave: 1
      - name: "Light_6"
        address: 5
        write_type: coil
        slave: 1
      - name: "Light_7"
        address: 6
        write_type: coil
        slave: 1
      - name: "Light_8"
        address: 7
        write_type: coil
        slave: 1
      - name: "Light_9"
        address: 8
        write_type: coil
        slave: 1
      - name: "Light_10"
        address: 9
        write_type: coil
        slave: 1
      - name: "Light_11"
        address: 10
        write_type: coil
        slave: 1
      - name: "Light_12"
        address: 11
        write_type: coil
        slave: 1
      - name: "Light_13"
        address: 12
        write_type: coil
        slave: 1
      - name: "Light_14"
        address: 13
        write_type: coil
        slave: 1
      - name: "Light_15"
        address: 14
        write_type: coil
        slave: 1
      - name: "Light_16"
        address: 15
        write_type: coil
        slave: 1

Then save and exit.

Modbus RTU Relay RPI07.png

Modbus RTU Relay RPI08.png
Modbus RTU Relay RPI09.png

  • Turn on Relay 1~4, 9~12:

Modbus RTU Relay RPI10.png
Modbus RTU Relay RPI11.png