Display negative sensor value as positive in mini graph

I’d like to use a mini graph (and the display options it offers) for a sensor that is (always) returning a negative value. I’m not sure how to go about converting the value in the mini graph yaml to a positive one before it is then displayed on the graph. It probably really simple - and I have found the following code in a similar question - but the answer didn’t state quite where this code goes and I’m very new to coding!

  - platform: template
        value_template: "{{ (states('sensor.fronius_house_load') | int) | abs }}"

The mini graph yaml currently looks like this:

type: custom:mini-graph-card

  - sensor.myenergi_harvi_10312221_storage_ct2
name: Water Tank Heating from Solar
  labels: true
  - value: 20
    color: '#0ffc03'
  - value: 100
    color: '#fcd703'
  - value: 500
    color: '#fc0320'


This goes into your configuration.yaml file, then you have to restart Home Assistant for the new sensor to be created.

1 Like

Ahh. got it - so I in effect use the code above to create a sensor based on the original - and then reference the new sensor in the mini graph. Thanks!

1 Like