Question regarding ModbusTCP data within the configuration.yaml file

Hi there,

I just started using Home Assistant and am quite happy with the first results and how easy the first steps were!
I started reading Data via ModbusTCP from a 3-Phase AC meter as a sensor in the configuration file. The number (power in Watt) is an INT16 with values from -32668 to 32668. Reading and displaying works, though I’d like to visualize the data better. It now shows a negative value ‘X’ as ‘65536 - X’
I there a trick how do some simple math in the configuration.yaml file so the shown data is according to the measured values? Unfortunately I didn’t find anything on this topic yet.
This is how it looks like now;


type: tcp
port: 502

Modbus sensor


  • platform: modbus
    • name: L1
      unit_of_measurement: W
      slave: 30
      register: 2600
    • name: L2
      unit_of_measurement: W
      slave: 30
      register: 2601
    • name: L3
      unit_of_measurement: W
      slave: 30
      register: 2602

It would be great if somethin like this would be possible before displaying:

Y = X
If X > 32668
X = - ( 65536 - Y )
return X

Thanks in advance!

Hide the Lx sensors, and create LxDisplay sensors like this.

  - platform: template
        value_template: >
        '{% if states.sensor.L1.state | float > 32668 %}
        {{(65536 - states.sensor.L1.state | float) * -1}}
        {{states.sensor.L1.state | float}}

Hi Travis,

except for some syntax problem with capitals in the beginning… it works now!
Thank you!