Manage dynamically a gauge colour range

Hiii everyone!!

This is my gauge:

type: custom:mod-card
[...]
  segments:
    - from: 5
      color: '#FF0000'
    - from: 6
      color: '#00FF00'
    - from:8
      color: '#FF0000'

I need to modify:

  • from 6 with - sensor.min
  • from 8 with - sensor.max

I’ve try:

  segments:
    - from: 5
      color: '#FF0000'
    - from:
      - operator: template
        value: |
          [[[ 
           return (states['sensor.min'].state)
          ]]]
      color: '#00FF00'
    - from:
      - operator: template
        value: |
          [[[ 
           return (states['sensor.max'].state)
          ]]]
      color: '#FF0000'

segments:
    - from: 5
      color: '#FF0000'
    - from: [[[return (states['sensor.min'].state)]]]
      color: '#00FF00'
    - from: [[[ return (states['sensor.max'].state)]]]
      color: '#FF0000'

  segments:
    - from: 5
      color: '#FF0000'
    - from: "{{states('sensor.min')}}"
      color: '#00FF00'
    - from: "{{states('sensor.max')}}"
      color: '#FF0000'

Any solution are wellcome!!

Your attempts are based on using unsupported things.
Do not invent non-existing options.
Use only documented supported ways, ask in Community and do not ask chatgpt etc.
The gauge card does not support templating. Wrap it into a card which does support templates.
Go to the main auto-entities card thread - and google by “gauge” word, you will find my solution for templating this card.

And WTH you are using mod-card… it is not a part of the gauge card, it is not needed here at all.

@ Ildar_Gabdullin the wizard of customizations!!
Thank you for your interest in my need.
I had to take some time to carefully consider my answer.
Here it is:
I would like to point out that I am aware and agree with the fact that nothing is owed here.
Having said that, perhaps it escapes that a multitude of intelligences pass through here, some oriented towards programming, others not but simply passionate about the subject.
Some young with great hopes, others on the home stretch but no less gifted with cognitive appetite.
I belong to the last category mentioned.

I could have simply asked “how do you do it?” but in doing so I could have also implied that I like to have “the food ready”. So I wanted to share in my request the (vain) attempts that I made with my limited knowledge.
Also because I hoped that, as sometimes happens, the problem was a typing error or some simple syntax error.

I didn’t invent anything… I tried to tailor my limited knowledge to the problem. Asking ChatGPT never helped me much.
So I did as you suggested… I asked the community and got your answer:
1- reprimand;
2 - search the site for the add-on
3 - search for gauge and find my solution.

Let’s say that you quickly switched to the board and that’s what you felt like writing.
Thanks for doing so.
Let’s also say that in hindsight, the question was badly phrased.
But I only understood it after your answer.

type: custom:mod-card
tap_action:
  action: none
double_tap_action:
  action: none
hold_action:
  action: more-info
card:
  type: gauge
  entity: >-
    sensor.ph
  name: pH
  card_mod:
    style:
      .: |
        ha-card {
          width: 80px;
          height: 50px !important;
          top: 115px;
          left: -365px;
          padding: 0px -0px 0px 0px;
          background: rgb(75, 75, 75);
          border: 3px solid rgb(0, 0, 0);
          border-radius: 10px;
          box-shadow: 3px -3px 10px -3px rgba(25, 90, 80, 1);
          color: rgb(255, 32, 122);
          --paper-item-icon-color: rgb(255, 32, 122);
        }
        .name {
          font-size: 8px !important;
          font-weight: bold;
          color: white !important;
          position: absolute;
          bottom: 2px;
          padding: 0px 0px 0px 0px;
          }
      ha-gauge$: |
        svg {
        transform: scale(1.4) translateY(-5px);
        overflow: visible;
        }
        svg text {
        transform: scale(1.2) translateY(-20px);
        }
        text.value-text {
          font-size: 50px !important;
          font-weight: bold;
          fill: rgba(255, 255, 224, 1) !important;
          text-anchor: middle;
        }
        .needle {
          fill: white !important;
        }
  unit: ''
  needle: true
  min: 5
  max: 9
  segments:
    - from: 5
      color: '#FF0000'
    - from: 6
      color: '#00FF00'
    - from: 8
      color: '#FF0000'

This is the complete code of my gauge.
There is very little of mine since it is a set of copy and paste of code found on the board.
I had already found this solution of yours:

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'
            },
          }
        }},

but I understand that he uses a different addon than mine.
So, to add a feature, I would risk destroying the gauge layout.
And since I have a dozen of them all the same on the dashboard, the remedy would be worse than the disease.

I don’t know what this grapheme means .: | but thanks to the fact that someone used it, I was able to independently create what I was interested in.
By trial and error… changing here this happens, etc.
I had a new need that I tried to address independently without success.

After all, if I were as good as you are at the subject, I wouldn’t have had the need to ask the question.
I would probably be here, like you, helping others.
Maybe in a more empathetic way.
Thanks for your attention.

I cannot read your whole answer and understand it properly due to a simple fact that I am in some kind of an usual situation for most of civil citizens, let’s just say that I am away from a toothbrush for a week thanks to famous reasons.
In short:

  1. mod-card is only used for cards which do not have own ha-card. If gauge card does have ha-card - no need to use mod-card. Go to card-mod thread - 1st post - link at the bottom, it MAY have styles for gauge (do not remember for sure).
  2. Auto-entities currently seems to be the only way to make the gauge card working properly with dynamic options. Good you found that solution.
  3. Probably you may want to add card-mod in that code for auto-entities. Go to main card-mod thread - 1st post - link at the bottom - auto-entities. You will find examples for add8ng card-mod into a template inside auto-entities.
  4. As for inventing unsupported options: it was not blaming YOU personally, it was blaming YOUR wrong ways. In short - you are not a bad guy, your actions were bad)))). See a difference))).

We may continue this conversation in a week I hope when I will be more civilized with a PC.

I’m sorry for your isolation situation. I hope it will be resolved soon.
If you refer to this post in your index there is only a reference to the Gauge which is not relevant.
(forgive me if I have not read the almost 7000 posts).

I hope I have clarified my need better.
Any help is welcome.

I wonder what makes post relevant then? It shows how to use card-mod for the Gauge card. Probably it does not solve same tasks as your styles.

Of course… not relevant to solving my problem!

No more help?