Gauge card: can it show negative numbers?

Hi all. I can see the latest HA version allows multiple segments to be defined. I’d like to use this to measure air temperature, but it doesn’t seem to accept negative numbers, so can only start from above freezing. Is there a way to get a gauge to show negative numbers? I’ve tried both the visial and YAML routes.

Thanks in advance!

1 Like

No problem

type: gauge
entity: sensor.utetemp_129
min: -30
max: 30
name: Test
needle: true
severity:
  green: -10
  yellow: 15
  red: 20
2 Likes

That’s brilliant thanks. I tried this but as it went red in the configuration I assumed it had rejected the values. But it hadn’t!

Thanks for the help! :relaxed:

I notised that myself also. But it still works :slightly_smiling_face:

Hm, this is weird, but for me it does not work like this…

What is not working?

Displaying negative values. But i think i figured it out: My negative value was not big enough to make a visual difference. If i enter -100 against +1000 it´s barely visible. I had to enter -1000 againts +1000 and now it´s working. Thank you!

Hi,
And what about getting green in the center and yellow beside at both sides? Any idea?
I need green from -5 to 5 but yellow -10 to -5 and 5 to 10

Found it as segments at the HA gauge help.
Yeap, now it is perfect

Came here to ask the same, but indeed it accepts negative values even though the tooltip states you need to enter a value of 1 or higher.

Just thought I’d post the direction I went on this in case anyone finds it useful…

Instead of 0 being the mid-point on the gauge, I flip the gauge around when the value is negative, see:

battery-power-neg

I achieved this by creating a template sensor (in configuration.yaml for noobs like me!) which clones the sensor in question, but changes it to an absolute value.

sensor:
  - platform: template
    sensors:
      battery_power_abs:
        value_template: "{{ (states('sensor.battery_power') | float | round(2)) | abs }}"

Then for the gauge card I’m using the lovelace-card-mod to flip the gauge around (and change the colour) via CSS when I detect a negative value from the original sensor.

type: gauge
entity: sensor.battery_power_abs
max: 5
unit: kW
name: Battery power
card_mod:
  style:  
    ha-gauge$: |
      svg {
        {% if states('sensor.battery_power') |float < 0 %}      
          transform: scaleX(-1);       
        {% endif %}
      }
    .: |
      ha-card {
        --info-color: limegreen;
        {% if states('sensor.battery_power') |float < 0 %}
          --info-color: green;
        {% endif %}
      }
1 Like