Epever uphi modbus

I’m facing an issue with my Home Assistant setup involving a Modbus integration with the Epever UP HI inverter. Specifically, the entity representing the battery state on my dashboard displays ‘0’ instead of ‘Normal’. Here’s the relevant sensor template configuration I’m using:

sensor:

  • platform: template
    sensors:
    estado_da_bateria_text:
    friendly_name: “Battery State”
    value_template: >
    {% set state = states(‘sensor.modbus_hub_Estado_da_Bateria_10_0x3553’) | int %}
    {% set d0 = state & 1 %}
    {% set d1 = (state & 2) >> 1 %}
    {% set d2 = (state & 4) >> 2 %}
    {% set d3 = (state & 8) >> 3 %}
    {% set d4 = (state & 16) >> 4 %}

      {% if d0 == 0 and d1 == 0 and d2 == 0 and d3 == 0 and d4 == 0 %}
        Normal
      {% elif d0 != 0 %}
        Overvoltage
      {% elif d1 != 0 %}
        Undervoltage
      {% elif d2 != 0 %}
        Over discharge
      {% elif d4 != 0 %}
        Fault
      {% else %}
        Unknown
      {% endif %}
    

Despite this configuration, the entity on the dashboard displays ‘0’ instead of ‘Normal’. The error reported by Home Assistant is:

Invalid config for ‘template’ from integration ‘sensor’ at configuration.yaml, line 194: invalid template (TemplateSyntaxError: unexpected char ‘&’ at 98)

How can I troubleshoot and resolve this issue?

hey man sorry i can t help you with this, but im using same inverter UP HI can you send me the configuration.yaml ? its not working with me…
my current setup is:
inverter connected to ATC-1200 serial to tcp/ip.
i have the software working on my PC using virtual COM port and even using TCP connection to the converter…
but with HomeAssistant its not working.

modbus:
  - name: epever
    type: serial
    method: rtu
    port: /dev/ttyS0
    baudrate: 115200
    bytesize: 8
    stopbits: 1
    parity: N
    timeout: 10

Hi,

Below is my current configuration.

modbus:
  - name: modbus_hub
    type: serial
    port: /dev/ttyACM0
    baudrate: 115200
    bytesize: 8
    method: rtu
    parity: N
    stopbits: 1
    
    sensors:
      # Utilidade (rede concessionária de energia)
      - unique_id: modbus_hub_Tensão_da_Rede_10_0x3500
        name: "Tensão da Rede"
        unit_of_measurement: V
        slave: 10
        address: 0x3500
        input_type: input
        scale: 0.01
        precision: 2

      - unique_id: modbus_hub_Corrente_da_Rede_10_0x3501
        name: "Corrente da Rede"
        unit_of_measurement: A
        slave: 10
        address: 0x3501
        input_type: input
        scale: 0.01
        precision: 2

      - unique_id: modbus_hub_Potência_da_Rede_10_0x3502
        name: "Potência da Rede"
        unit_of_measurement: W
        slave: 10
        address: 0x3502
        input_type: input
        scale: 0.1
        precision: 0
        data_type: int32
        swap: word

      - unique_id: modbus_hub_Estado_da_Rede_10_0x3511
        name: "Estado da Rede"
        slave: 10
        address: 0x3511
        input_type: input
        # 0:Normal, 1:Entrada baixa; 2:Entrada alta, 3: Não conectado

      - unique_id: modbus_hub_Total_da_Rede_10_0x350F
        name: "Total da Rede"
        unit_of_measurement: kWh
        slave: 10
        address: 0x350F
        input_type: input
        scale: 0.01
        precision: 2
        data_type: int32
        swap: word

      # Array Fotovoltaica
      - unique_id: modbus_hub_Tensão_do_PV_10_0x3549
        name: "Tensão do PV"
        unit_of_measurement: V
        slave: 10
        address: 0x3549
        input_type: input
        scale: 0.01
        precision: 2

      - unique_id: modbus_hub_Corrente_do_PV_10_0x354A
        name: "Corrente do PV"
        unit_of_measurement: A
        slave: 10
        address: 0x354A
        input_type: input
        scale: 0.01
        precision: 2

      - unique_id: modbus_hub_Potência_do_PV_10_0x354B
        name: "Potência do PV"
        unit_of_measurement: W
        slave: 10
        address: 0x354B
        input_type: input
        scale: 0.01
        precision: 2
        data_type: int32
        swap: word

      - unique_id: modbus_hub_Total_do_PV_10_0x3557
        name: "Total do PV"
        unit_of_measurement: kWh
        slave: 10
        address: 0x3557
        input_type: input
        scale: 0.01
        precision: 2
        data_type: int32
        swap: word

      # Carga
      - unique_id: modbus_hub_Tensão_da_Carga_10_0x3521
        name: "Tensão da Carga"
        unit_of_measurement: V
        slave: 10
        address: 0x3521
        input_type: input
        scale: 0.01
        precision: 2

      - unique_id: modbus_hub_Corrente_da_Carga_10_0x3522
        name: "Corrente da Carga"
        unit_of_measurement: A
        slave: 10
        address: 0x3522
        input_type: input
        scale: 0.01
        precision: 2

      - unique_id: modbus_hub_Total_da_Carga_10_0x3530
        name: "Total da Carga"
        unit_of_measurement: kWh
        slave: 10
        address: 0x3530
        input_type: input
        scale: 0.01
        precision: 2
        data_type: int32
        swap: word

      # Bateria
      - unique_id: modbus_hub_Tensão_da_Bateria_10_0x3580
        name: "Tensão da Bateria"
        unit_of_measurement: V
        slave: 10
        address: 0x3580
        input_type: input
        scale: 0.01
        precision: 2

      - unique_id: modbus_hub_Corrente_da_Bateria_10_0x3581
        name: "Corrente da Bateria"
        unit_of_measurement: A
        slave: 10
        address: 0x3581
        input_type: input
        scale: 0.01
        precision: 2

      - unique_id: modbus_hub_Capacidade_da_Bateria_10_0x3586
        name: "Capacidade da Bateria"
        unit_of_measurement: "%"
        slave: 10
        address: 0x3586
        input_type: input
        scale: 1

      - unique_id: modbus_hub_Temperatura_da_Bateria_10_0x3512
        name: "Temperatura da Bateria"
        unit_of_measurement: "°C"
        slave: 10
        address: 0x3512
        input_type: input
        scale: 0.01

      - unique_id: modbus_hub_Estado_da_Bateria_10_0x3553
        name: "Estado da Bateria"
        slave: 10
        address: 0x3553
        input_type: input
        # 0:Normal, 1:Sobretensão, 2:Subtensão, 3:Desconexão por subtensão, 4:Falha

Daniel

Attached is the file containing the protocol for this inverter.

Modbus Converter Configuration

To use the converter, you can choose between the following configurations, depending on the protocol you wish to use:

Option 1: Modbus TCP

modbus:
  - name: modbus_hub
    type: tcp
    host: IP_ADDRESS
    port: 502

Option 2: Modbus UDP

modbus:
  - name: modbus_hub
    type: udp
    host: IP_ADDRESS
    port: 502

Note: Replace IP_ADDRESS with the IP address of your device. Modbus TCP is generally more reliable, while Modbus UDP can be faster but with less delivery guarantee. Choose the protocol that best meets your needs.