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
            },
          }
        }},
5 Likes

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:

Can you please share your working version?
I’m struggling with setting the segments using auto-entities :frowning:
Thanks.

Scroll up a bit.

Sorry, but I can’t get it working.

I have this gauge:

Static gauge
      - type: gauge
        entity: sensor.volvo_battery_charge_level
        name: ""
        needle: true
        min: 0
        max: 100
        segments:
          - from: 0
            color: "#db4437"
          - from: 10
            color: "#ffa600"
          - from: 30
            color: "#43a047"
          - from: 75
            color: "#00a6ff"
          - from: 91
            color: "#3744db"

and I want to make the range from 30 to 75 dynamically. My attempt is based on the replies here:

Not working dynamic gauge
          - type: custom:auto-entities
            card:
              type: vertical-stack
            card_param: cards
            filter:
              template: >-
                {{
                  {
                    'type': 'gauge',
                    'entity': 'sensor.volvo_battery_charge_level',
                    'name': '',
                    'needle': 'true',
                    'min': 0,
                    'max': 100,
                    'segments': [
                      '#db4437': 0,
                      '#ffa600': 10,
                      '#43a047': states('input_number.minimum_charge_level_for_auto_charging')|int,
                      '#00a6ff': states('input_number.maximum_charge_level_for_auto_charging')|int,
                      '#3744db': 91
                    ],
                  }
                }}

But it doesn’t show anything with this code. I assume the error is with wrong or missing curly / square brackets, but I can’t see the solution.

This is what I am using … all credits go to @Ildar_Gabdullin :clap:

Using severity
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')|float * 1.2),
        'severity': {
          'green': 0,
          'yellow': (states('sensor.electricity_meter_maximale_vraag_huidige_maand')|float * 0.8),
          'red': (states('sensor.electricity_meter_maximale_vraag_huidige_maand')|float)
        },
          
      }
    }},
Using segments
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')|float *1.2),
        'segments': [
            {'from': '0','color':'green'},
            {'from': (states('sensor.electricity_meter_maximale_vraag_huidige_maand')|float * 0.8)  ,'color':'orange'},
            {'from': (states('sensor.electricity_meter_maximale_vraag_huidige_maand')|float) ,'color':'red'},              
          ]
          
      }
    }},

Many thanks to both of you, now I got it working and also understood the dictionaries :slightly_smiling_face:

This approach can also work with the custom:dual-gauge-card.

Here’s my example. In my case it shows the maximum capacity of the Tesla Powerwall 2 battery (value is a template of the total capacity minus the blackout reserve)

square: false
type: grid
cards:
  - type: custom:auto-entities
    card:
      type: vertical-stack
    card_param: cards
    filter:
      template: |-
        {{
          {
            'type': 'custom:dual-gauge-card',
            'title': 'Max vs Available',
            'min': 0,
            'max': (states('sensor.powerwall_abs_kwh') | float),
            'outer': {
              'entity': 'sensor.powerwall_abs_kwh',
              'unit': '',
              'min': 0,
              'label': 'Max',
              'max': (states('sensor.powerwall_abs_kwh') | float),
              'colors': [
                { 'color': 'var(--label-badge-green)', 'value': 18 },
                { 'color': 'var(--label-badge-blue)', 'value': 16 },
                { 'color': 'var(--label-badge-orange)', 'value': 8 },
                { 'color': 'var(--label-badge-red)', 'value': 3 }
              ]
            },
            'inner': {
              'entity': 'sensor.powerwall_kwh_remain',
              'shadeinner': true,
              'precision': 0,
              'unit': '',
              'min': 0,
              'max': (states('sensor.powerwall_abs_kwh') | float),
              'label': 'Avail',
              'colors': [
                { 'color': 'var(--label-badge-green)', 'value': 18 },
                { 'color': 'var(--label-badge-orange)', 'value': 16 },
                { 'color': 'var(--label-badge-yellow)', 'value': 8 },
                { 'color': 'var(--label-badge-red)', 'value': 3 }
              ]
            }
          }
        }},
columns: 1
title: Powerwall Maximum vs Remain

1 Like