Modbus -> Switches -> holdings

Due to Gree modbus protocol limitation to write command_on/off I need to use function code 10 = holdings, but how to configure it in yaml? below does not work:

switches:
      - name: "AC_ON_OFF" 
        scan_interval: 5
        slave: 9
        address: 2
        command_on: [0xAA,0x00]???
        command_off: [0x55,0x00]???
        write_type: holdings
        verify:
            input_type: holding
            address: 2
            state_on: 0xAA
            state_off: 0x55

of course using modbus service it works

action: modbus.write_register
data:
  hub: modbus
  address: 2
  slave: 9
  value:
    - 170
    - 0

Hello,

It looks like you’re on the right track! To configure the command_on and command_off for the switches in YAML, you need to specify the value instead of using hexadecimal values directly. Here’s an updated version of your YAML configuration:

switches:
  - name: "AC_ON_OFF"
    scan_interval: 5
    slave: 9
    address: 2
    command_on:
      - value: 170
      - value: 0
    command_off:
      - value: 85
      - value: 0
    write_type: holdings
    verify:
      input_type: holding
      address: 2
      state_on: 170
      state_off: 85

Does this help?

Best regards,
Janet
FloridaBlue

it does not work:
"
Invalid config for ‘modbus’ at modbus.yaml, line 23: expected int for dictionary value ‘modbus->0->switches->0->command_on’, got [170, 0]
Invalid config for ‘modbus’ at modbus.yaml, line 26: expected int for dictionary value ‘modbus->0->switches->0->command_off’, got [85, 0]
"