Possible to change color of sensor data if increasing/decreasing from previous value?

I am monitoring a group of 20 temperature sensors and would like to display if each temp is either increasing or decreasing in color, similar to what is found on a stock ticker.

I know I can change the style using the card_mod HACS integration, but I don’t know if there’s a CSS interpretation that monitors a value change.

Does anyone know of a solution?

I believe the statistics sensor displays the trend, so I guess create a sum of all of them and add this to the statistics sensor.

Thank you, I think I’m halfway there. I created a statistics helper to monitor the last 2 sensor values and have the positive/negative result. Next step is to add that to the card_mod CSS styling as an if statement for color style on whether positive/negative.

I’m stuck now trying to figure out how card_mod can take the value of a one sensor and applying the style to a different one.

Simply substituting the newly created ‘sensor.temp_office_trend’ for ‘states(config.entity)’ unfortunately does not work.

  - entity: sensor.central_office_temperature
    card_mod:
      style: |
        :host {
          color:
            {% if states(sensor.temp_office_trend) | int < 0 %} red {% endif %};
        } 

Suggest to test templates in “Dev tools → Template”, here the template is wrong (quotes missing).
Btw if the condition is “false” you will get

color: ;

which is an error in css.

Thank you! I just needed to add the quotes! (I do have another condition for green but left it out above for simplicity :slight_smile:

- entity: sensor.central_office_temperature
    card_mod:
      style: |
        :host {
          color:
            {% if "states(sensor.temp_office_trend) | int < 0" %} red
            {% elif "states(sensor.temp_office_trend) | int >= 0" %} green
            {% endif %};
        }

EDIT: The quotes are incorrect.
states(‘sensor.temp_office_trend’) is the correct format (thank you Ildar)

The above code correctly outputs:
image

Ideally only the actual temperature would change color and not the label. I tried the below but it’s not applying to the card.

- entity: sensor.central_office_temperature
    card_mod:
      style:
        hui-generic-entity-row:
          $: |
            text-content:not(.info) {
              color:
                {% if "states(sensor.temp_office_trend) | int < 0" %} red
                {% elif "states(sensor.temp_office_trend) | int >= 0" %} green
                {% endif %};
            }

EDIT: The quotes are incorrect.
states(‘sensor.temp_office_trend’) is the correct format (thank you Ildar)

No, the template is wrong.
You think that it is correct because

if "states(sensor.temp_office_trend) | int < 0"

is same as

if "any string"

which gives “true”.
Must be

if states('sensor.temp_office_trend') | int < 0

Thank you again!

Changing the quotes to the “hui-generic-entity-row” style did not change the output.

I tried the below in the card after seeing the correct output in Dev Tools and it doesn’t change the color of the value. Is “text-content:not(.info)” the incorrect parameter?

    card_mod:
      style:
        hui-generic-entity-row:
          $: |
            text-content:not(.info) {
              color:
                green
            }

I am not getting, I told about quotes for the template, not for the “hui-generic-entity-row” word.
Suggest to go to the main card-mod thread, check the 1st post → link at the bottom titled “fantastic” and then ask ANY card-mod-related questions THERE.

Apologies for not being specific. I was using your advice to also change the quotes to my previous post above your reply/correction. I’m attempting to change just the color of the value returned (data) and not the text.

Yes, and this example & many other examples are explained in that path I mentioned above. Suggest to check it, might be educative & useful.

1 Like

I’ve been reading the posts! You’ve been very busy :grinning:

Thank you for all your work and leading me to this excellent treasure trove!