How to code styling so an unavailable entity does not break it

I have a picture-elements card set up with a 3d house plan that has been working great.

there is about 800 lines of styling in the card_mod: Style | section which tests for certain states on a lot of my entities and initiates animations (blinking or rotating) or color changes.

The issue is that if one of the entities in one of the test code snippets goes unavailable, all my animations stop.

Here is an example:
I had a sensor that went unavailable : “sensor.enc10_8mb_uptime_raw” in this code–

{% set raw1 = states(‘sensor.enc10_8mb_uptime_raw’)| int %}
{% if raw1 < 600 %}
–u1-color: #ff3300;
–state-animation-blink-u1: my-blink-u1 3s linear infinite;
{% else %}
–u1-color: #33cc33;
{% endif %}

@keyframes my-blink-u1 {
0% {opacity: 0;}
50% {opacity: 100;}
100% {opacity: 0;}
}

I use some kind of test for fan states, leak sensor states, switch states, etc

The unavailability cause all my animations to stop. Is there a way to have the styling skip this section if it is not in a proper state? Kind of like error handling in a program to keep it from crashing.

1 Like