Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to add relay board to ESPHome by Modbus Controller Switch
#1
   
[Image: attachment.php?aid=2232]   
uart:
  id: mbus
  tx_pin: GPIO13
  rx_pin: GPIO16
  baud_rate: 9600

modbus:
  id: modbus1
  uart_id: mbus
  send_wait_time: 200ms

modbus_controller:
- id: a6
  address: 1
  modbus_id: modbus1
  update_interval: 1s


switch:
  - platform: modbus_controller
    name: 'modbus-switch1'
    address: 0  # 0:relay1  1:relay2 ......
    register_type: coil
    bitmask: 1


this is a demo , i have created one switch button in ESPHome, you can create many others.

KinCony Products use modbus command:
01 05 00 00 FF 00  turn on relay1
01 05 00 00 00 00  turn off relay1

make sure your relay board as these:
ON = 0xFF00  OFF=0000

if your relay board not use by this protocol. you can also write esphome as "write_lambda" way. i have tested, "write_lambda" to create switch also work fine. just need to create ON and OFF two command.

    write_lambda: |-
      ESP_LOGD("main","Modbus Switch incoming state = %f",x);
      // return false ; // use this to just change the value
      payload.push_back(0x1);  // device address
      payload.push_back(0x5);  // force single coil
      payload.push_back(0x00); // high byte address of the coil
      payload.push_back(0x00);  // low byte address of the coil
      payload.push_back(0xFF); // ON = 0xFF00 OFF=0000
      payload.push_back(0x00);
      return true;
Reply


Forum Jump:


Users browsing this thread: