#ESPHome - Query and control Modbus

1 messages · Page 1 of 1 (latest)

serene anvil
#

Hi,
I have a PV inverter, which I read out via ESPHome and Modbus, which also works fine. But now I would like to be able to display and control a register that provides me with 3 values (0-1-2). The best way would be 0="text1", 1="text2" and 2="Text3", but unfortunately I can't manage that, what does it have to look like?

text_sensor:
  - platform: modbus_controller
    modbus_controller_id: ${modbus_controller_id}
    id: ${device_type}_GEN_Port_Status
    bitmask: 0
    register_type: holding
    address: 235
    raw_encode: HEXBYTES
    name: ${device_type}-GEN Port Status
    lambda: |-
      uint16_t value = modbus_controller::word_from_hex_str(x, 0);
      switch (value) {
        case 0: return std::string("GEN Input");
        case 1: return std::string("SmartLoad Output");
        case 2: return std::string("Micro INV Input");
        default: return std::string("----");
      }
      return x;
summer whale
#

You really wanted the ESPHome discord, or the #diy-archived channel