Inverting a statistical graph

Is it possible to invert the value range of a dashboard graph? I am graphing the depth of water in my well (template sensor in ft), and to mimic how it looks down in the well, the higher the number, the lower it should be on the Y axis.

As a workaround, I tried this, but it always displays as “0 ft”. Maybe ft can’t be negative.

- platform: template
  sensors:
    well_depth_neg:
      unit_of_measurement: "ft"
      value_template: >
         {{ states('sensor.well_watcher')*-1 }} 

States are always strings. You need to convert them to numbers before performing mathematical operations:

      value_template: >
         {{ states('sensor.well_watcher')|float(0) *-1 }} 

Use float() if your number has a decimal part, use int() if your number has no part to the right of the decimal point.

Always supply a default value in the brackets for the issues where the state can not be converted to a number.

1 Like

Thank you @tom_l !

I know this topic is quite old, and the solution did not work for me. I had to adjust it to:

value_template: "{{ value | float(0) * -1 }}"

That sounds like you are using it in a completely different integration. One that has value and value_json variables. The integration used in the solved example above does not have these variables.

That would indeed explain why yours did not work for me. SMH apologies.

1 Like