Max and min dynamic value in Gauge card?

Hi, I’m new here, and I already have some questions! :grimacing:

Is it possible that MIN and MAX attribute of the GAUGE card are dynamic values?
This is my idea, but it doesn’t work that way:

- type: gauge
  entity: sensor.dark_sky_temperature_1h
  name: "Temp"
  min: "{{ states('sensor.dark_sky_overnight_low_temperature_0d') |int - 1 }}"
  max: "{{ states('sensor.dark_sky_daytime_high_temperature_0d') |int + 1 }}"

I look forward to the suggestions and help you can give me!

2 Likes

templates aren’t possible with native lovelace cards. Some custom cards extend templating to all fields on cards.

Do you have HACS installed? I recommend starting there https://github.com/custom-components/hacs. Then download and configure one of the many templating cards.

I came across this as I wanted to make a dynamic gauge displaying vacation mode for my house so I wanted duration and time left. I followed this tutorial Implementing house mode in your Home Assistant – kef.dev
But then came to this page as was not getting anywhere, but I then discovered from hacs the " Config Template Card Card" and then you can use the following example:

type: custom:config-template-card
entities:
  - sensor.vacation_duration
  - sensor.vacation_remaining
card:
  type: gauge
  entity: sensor.vacation_remaining
  name: Vacation Days Left
  unit: days
  min: 0
  needle: true
  max: ${states["sensor.vacation_duration"].state}
  segments:
    - from: ${states["sensor.vacation_duration"].state * 0.0}
      color: '#FF453A'
    - from: ${states["sensor.vacation_duration"].state * 0.04}
      color: '#FE5235'
    - from: ${states["sensor.vacation_duration"].state * 0.09}
      color: '#FE5F31'
    - from: ${states["sensor.vacation_duration"].state * 0.13}
      color: '#FE6C2C'
    - from: ${states["sensor.vacation_duration"].state * 0.18}
      color: '#FE7A28'
    - from: ${states["sensor.vacation_duration"].state * 0.22}
      color: '#FE8723'
    - from: ${states["sensor.vacation_duration"].state * 0.27}
      color: '#FE941F'
    - from: ${states["sensor.vacation_duration"].state * 0.31}
      color: '#FEA11A'
    - from: ${states["sensor.vacation_duration"].state * 0.36}
      color: '#FEAF16'
    - from: ${states["sensor.vacation_duration"].state * 0.40}
      color: '#FEBC11'
    - from: ${states["sensor.vacation_duration"].state * 0.45}
      color: '#FEC90D'
    - from: ${states["sensor.vacation_duration"].state * 0.50}
      color: '#FED709'
    - from: ${states["sensor.vacation_duration"].state * 0.54}
      color: '#EDD20E'
    - from: ${states["sensor.vacation_duration"].state * 0.59}
      color: '#DCCD14'
    - from: ${states["sensor.vacation_duration"].state * 0.63}
      color: '#CBC819'
    - from: ${states["sensor.vacation_duration"].state * 0.68}
      color: '#BAC31F'
    - from: ${states["sensor.vacation_duration"].state * 0.72}
      color: '#A9BE25'
    - from: ${states["sensor.vacation_duration"].state * 0.77}
      color: '#98B92A'
    - from: ${states["sensor.vacation_duration"].state * 0.81}
      color: '#87B430'
    - from: ${states["sensor.vacation_duration"].state * 0.86}
      color: '#76AF36'
    - from: ${states["sensor.vacation_duration"].state * 0.90}
      color: '#65AA3B'
    - from: ${states["sensor.vacation_duration"].state * 0.95}
      color: '#54A541'
    - from: ${states["sensor.vacation_duration"].state * 1}
      color: '#44A047'
type or paste code here

works perfectly :slight_smile:

1 Like

Although the dynamic max & segment colors are working perfectly, the gauge card is continuously rendering again when the needle entity changes values. The needle changes the whole time back from 0 to the new updated value instead of the old value to the new. You have that also?

On every change of a monitored entity the config-template-card (CTC) redraws itself.
Animation of the needle (0 → curr value) occurs on a redraw. So - this a inevitable outcome of using CTC.

Ok many thanks for clarification. In my case it’s updated every second, so that’s unfortunately not workable :slight_smile:

Wrap into auto-entities like this example:

type: vertical-stack
cards:
  - type: entities
    entities:
      - input_number.test_level_1
      - input_number.test_level_2
  - type: custom:auto-entities
    card:
      type: vertical-stack
    card_param: cards
    filter:
      template: >-
        {{
          {
            'type': 'gauge',
            'entity': 'sensor.processor_use',
            'name': 'Temp',
            'severity': {
              'green': 0,
              'yellow': states('input_number.test_level_1')|int,
              'red': states('input_number.test_level_2')|int
            },
          }
        }},
1 Like

Well many thanks.
That seems to be working without continuous rendering. Your help is much appreciated :clap: :slight_smile:

I only don’t get the segments part working, but that’s just because I don’t use the right syntax I guess.
Any idea what would be the right one?

type: vertical-stack
cards:
  - type: entities
    entities:
      - sensor.electricity_meter_huidig_gemiddelde_vraag
      - sensor.electricity_meter_maximale_vraag_huidige_maand
  - type: custom:auto-entities
    card:
      type: vertical-stack
    card_param: cards
    filter:
      template: |-
        {{
          {
            'type': 'gauge',
            'entity': 'sensor.electricity_meter_huidig_gemiddelde_vraag',
            'name': 'Piekverbruik',
            'needle': 'true',
            'max': states('sensor.electricity_meter_maximale_vraag_huidige_maand')|int,
            'segments': {
              - 'from': 0
                'color': 'green'
              - 'from': states('sensor.electricity_meter_maximale_vraag_huidige_maand')*0,8|int,
                'color': 'orange'
              - 'from': states('sensor.electricity_meter_maximale_vraag_huidige_maand')|int,
                'color': 'red'
            },
          }
        }},

list with dicts should be like

[
  {'a':'a','b':'b'},
  {'a':'a','b':'b'}
]

Many thanks, that’s working!!

Thanks Lidar - managed to ditch one more custom card using your answer as I already use auto-entities

Perfect :slight_smile: