Change color of Gauge depending on value of another Entity using card-mod, even just set the colour

I have spent ages on this & must be being really daft.

At the most basic level trying to set the colour of a Gauge (have the severity off, no use for me)
card-mod working OK, tested code at bottom of this post.

Basically I have solar power coming in & charging the battery, the battery Watts are always positive but there is a separate identity that is 1 for charging & 0 for flowing from the battery.

I would like the power gauge to be green when charging & red when flowing away.
I think I found some code to test & might work but I can’t even change the colour perminantly.
It is always blue.

Ideally if someone could advise how to change the colour but also to code for testing for 1 or 0 & set the colour accordingly.

this is a very basic code but tried hundreds of variations.
type: vertical-stack
cards:

  - type: gauge
    entity: sensor.solis_battery_power
    card_mod:
      style: |
        ha-card {
          color: green;
        }


This works OK ...
type: markdown
content: '## Hello'
card_mod:
  style: |
    ha-card {
      color: red;
      background: transparent;
      text-align: center;
    }

I found my own solution, I think I was looking in the wrong direction
Using conditions to hide the card with different severity colours depending on state
Luckily battery direction is either 1.0 or 0.00, would be nice for future projects to be able to use greater than or less than but this works for me great now.

- type: conditional
        conditions:
          - entity: sensor.solisss_battery_current_direction
            state: '1.0'
        card:
          type: gauge
          min: 0
          max: 3500
          needle: false
          severity:
            green: 0
            yellow: 0
            red: 0
          entity: sensor.solisss_battery_power
      - type: conditional
        conditions:
          - entity: sensor.solisss_battery_current_direction
            state: '0.0'
        card:
          type: gauge
          min: 0
          max: 3000
          needle: false
          severity:
            green: 0
            yellow: 10000
            red: 10000
          entity: sensor.solisss_battery_power
1 Like