@Mattias_Persson, can I ask for help on this question of mine?
I would like to have this sensor changing the icon color according to its percentage…
0% remains green and 5% to 100% red.
I already had it working, but it was dependent on a sensor in its “on” state. But I didn’t want to be dependent on that sensor because I don’t have it anymore.
- type: custom:button-card
entity: sensor.gas_sensor_tuyasns_gas
name: '% Gás'
tap_action:
!include lovelace_ui/another_ui_tablet/popup/segurança_gas_smoke.yaml
template:
- base
- icon_gas_1
- loader
icon_gas_1:
styles:
custom_fields:
icon:
- width: 92%
- margin-left: -14%
- margin-top: -1%
custom_fields:
icon: >
[[[
const style = `
<style>
.on {
animation: on 1s;
transform-origin: -100% 46%;
animation-fill-mode: forwards;
}
.off {
animation: off 1s;
transform-origin: -100% 46%;
animation-fill-mode: forwards;
}
</style>
`;
const path = `
<path fill="#2fae81" d="M1.57142849 6.14285713h10.85714302v1.14285716H1.57142849z"/>
<path fill="#67c7a5" d="M9.00000003 11.28571435H4.99999997c-1.25714288 0-2.28571432-1.02857144-2.28571432-2.28571432V5.28571426C2.71428565 2.91428566 4.62857139.99999991 7 .99999991c2.3714286 0 4.28571435 1.91428574 4.28571435 4.28571435v3.71428577c0 1.25714288-1.02857144 2.28571432-2.28571432 2.28571432z"/>
<path fill="#a1ecd1" d="m 9.0444711,5.4206731 c -0.7053572,0 -1.234375,0.5290179 -1.234375,1.234375 0,0.7053571 0.5290178,1.234375 1.234375,1.234375 0.7053572,0 1.2343749,-0.5290179 1.2343749,-1.234375 0,-0.7053571 -0.5290177,-1.234375 -1.2343749,-1.234375 z"/>"
<path fill="#a1ecd1" d="m 4.9471153,5.4459135 c -0.7053572,0 -1.234375,0.5290179 -1.234375,1.234375 0,0.7053571 0.5290178,1.234375 1.234375,1.234375 0.7053572,0 1.234375,-0.5290179 1.234375,-1.234375 0,-0.7053571 -0.5290178,-1.234375 -1.234375,-1.234375 z" />
<path fill="#607d8b" d="M7 9.00000003c-1.14285716 0-2.00000003.85714287-2.00000003 2.00000003 0 1.14285716.85714287 2.00000003 2.00000003 2.00000003 1.14285716 0 2.00000003-.85714287 2.00000003-2.00000003 0-1.14285716-.85714287-2.00000003-2.00000003-2.00000003z"/>
<path fill="#263238" d="M7 9.57142861c-.17142857 0-.28571429.11428572-.28571429.28571429s.11428572.28571429.28571429.28571429.28571429-.11428572.28571429-.28571429S7.17142857 9.57142861 7 9.57142861zm0 2.28571432c-.17142857 0-.28571429.11428572-.28571429.28571429s.11428572.28571429.28571429.28571429.28571429-.11428572.28571429-.28571429S7.17142857 11.85714293 7 11.85714293zm-1.22857145-1.5714286c-.08571428.14285715-.02857143.31428572.11428572.40000001.14285714.08571429.31428572.02857143.4-.11428572.0857143-.14285714.02857143-.31428571-.11428571-.4-.17142857-.05714286-.31428572-.02857143-.4.11428571zm1.9714286 1.14285717c-.08571428.14285714-.02857142.31428571.11428572.4.14285715.08571429.31428572.02857143.4-.11428572.0857143-.14285714.02857144-.31428571-.11428571-.4-.14285714-.05714286-.31428572-.02857143-.4.11428571zm-1.9714286.28571428c.08571429.14285715.25714286.17142858.4.11428572.14285715-.08571429.17142858-.25714286.11428572-.4-.05714285-.14285715-.25714286-.17142858-.4-.11428572-.17142858.08571429-.2.25714286-.11428572.4zm1.9714286-1.14285716c.0857143.14285715.25714287.17142858.40000001.11428572.14285714-.08571429.17142857-.25714286.11428572-.4-.11428572-.14285715-.25714286-.17142858-.40000001-.11428572-.14285714.08571429-.2.25714286-.11428572.4z"/>
`;
if (variables.state === 'on' && variables.timeout < 2000) {
return `
<svg viewBox="0 0 14 14"> ${style}
<path fill="#ea3836" d="M1.57142849 6.14285713h10.85714302v1.14285716H1.57142849z"/>
<path fill="#fa584e" d="M9.00000003 11.28571435H4.99999997c-1.25714288 0-2.28571432-1.02857144-2.28571432-2.28571432V5.28571426C2.71428565 2.91428566 4.62857139.99999991 7 .99999991c2.3714286 0 4.28571435 1.91428574 4.28571435 4.28571435v3.71428577c0 1.25714288-1.02857144 2.28571432-2.28571432 2.28571432z"/>
<path fill="#ea3836" d="m 9.0444711,5.4206731 c -0.7053572,0 -1.234375,0.5290179 -1.234375,1.234375 0,0.7053571 0.5290178,1.234375 1.234375,1.234375 0.7053572,0 1.2343749,-0.5290179 1.2343749,-1.234375 0,-0.7053571 -0.5290177,-1.234375 -1.2343749,-1.234375 z"/>"
<path fill="#ea3836" d="m 4.9471153,5.4459135 c -0.7053572,0 -1.234375,0.5290179 -1.234375,1.234375 0,0.7053571 0.5290178,1.234375 1.234375,1.234375 0.7053572,0 1.234375,-0.5290179 1.234375,-1.234375 0,-0.7053571 -0.5290178,-1.234375 -1.234375,-1.234375 z" />
<path fill="#607d8b" d="M7 9.00000003c-1.14285716 0-2.00000003.85714287-2.00000003 2.00000003 0 1.14285716.85714287 2.00000003 2.00000003 2.00000003 1.14285716 0 2.00000003-.85714287 2.00000003-2.00000003 0-1.14285716-.85714287-2.00000003-2.00000003-2.00000003z"/>
<path fill="#ea3836" d="M7 9.57142861c-.17142857 0-.28571429.11428572-.28571429.28571429s.11428572.28571429.28571429.28571429.28571429-.11428572.28571429-.28571429S7.17142857 9.57142861 7 9.57142861zm0 2.28571432c-.17142857 0-.28571429.11428572-.28571429.28571429s.11428572.28571429.28571429.28571429.28571429-.11428572.28571429-.28571429S7.17142857 11.85714293 7 11.85714293zm-1.22857145-1.5714286c-.08571428.14285715-.02857143.31428572.11428572.40000001.14285714.08571429.31428572.02857143.4-.11428572.0857143-.14285714.02857143-.31428571-.11428571-.4-.17142857-.05714286-.31428572-.02857143-.4.11428571zm1.9714286 1.14285717c-.08571428.14285714-.02857142.31428571.11428572.4.14285715.08571429.31428572.02857143.4-.11428572.0857143-.14285714.02857144-.31428571-.11428571-.4-.14285714-.05714286-.31428572-.02857143-.4.11428571zm-1.9714286.28571428c.08571429.14285715.25714286.17142858.4.11428572.14285715-.08571429.17142858-.25714286.11428572-.4-.05714285-.14285715-.25714286-.17142858-.4-.11428572-.17142858.08571429-.2.25714286-.11428572.4zm1.9714286-1.14285716c.0857143.14285715.25714287.17142858.40000001.11428572.14285714-.08571429.17142857-.25714286.11428572-.4-.11428572-.14285715-.25714286-.17142858-.40000001-.11428572-.14285714.08571429-.2.25714286-.11428572.4z"/>
</svg>
`;
}
if (variables.state === 'on' && variables.timeout > 2000) {
return `
<svg viewBox="0 0 14 14"> ${style}
<path fill="#ea3836" d="M1.57142849 6.14285713h10.85714302v1.14285716H1.57142849z"/>
<path fill="#fa584e" d="M9.00000003 11.28571435H4.99999997c-1.25714288 0-2.28571432-1.02857144-2.28571432-2.28571432V5.28571426C2.71428565 2.91428566 4.62857139.99999991 7 .99999991c2.3714286 0 4.28571435 1.91428574 4.28571435 4.28571435v3.71428577c0 1.25714288-1.02857144 2.28571432-2.28571432 2.28571432z"/>
<path fill="#ea3836" d="m 9.0444711,5.4206731 c -0.7053572,0 -1.234375,0.5290179 -1.234375,1.234375 0,0.7053571 0.5290178,1.234375 1.234375,1.234375 0.7053572,0 1.2343749,-0.5290179 1.2343749,-1.234375 0,-0.7053571 -0.5290177,-1.234375 -1.2343749,-1.234375 z"/>"
<path fill="#ea3836" d="m 4.9471153,5.4459135 c -0.7053572,0 -1.234375,0.5290179 -1.234375,1.234375 0,0.7053571 0.5290178,1.234375 1.234375,1.234375 0.7053572,0 1.234375,-0.5290179 1.234375,-1.234375 0,-0.7053571 -0.5290178,-1.234375 -1.234375,-1.234375 z" />
<path fill="#607d8b" d="M7 9.00000003c-1.14285716 0-2.00000003.85714287-2.00000003 2.00000003 0 1.14285716.85714287 2.00000003 2.00000003 2.00000003 1.14285716 0 2.00000003-.85714287 2.00000003-2.00000003 0-1.14285716-.85714287-2.00000003-2.00000003-2.00000003z"/>
<path fill="#ea3836" d="M7 9.57142861c-.17142857 0-.28571429.11428572-.28571429.28571429s.11428572.28571429.28571429.28571429.28571429-.11428572.28571429-.28571429S7.17142857 9.57142861 7 9.57142861zm0 2.28571432c-.17142857 0-.28571429.11428572-.28571429.28571429s.11428572.28571429.28571429.28571429.28571429-.11428572.28571429-.28571429S7.17142857 11.85714293 7 11.85714293zm-1.22857145-1.5714286c-.08571428.14285715-.02857143.31428572.11428572.40000001.14285714.08571429.31428572.02857143.4-.11428572.0857143-.14285714.02857143-.31428571-.11428571-.4-.17142857-.05714286-.31428572-.02857143-.4.11428571zm1.9714286 1.14285717c-.08571428.14285714-.02857142.31428571.11428572.4.14285715.08571429.31428572.02857143.4-.11428572.0857143-.14285714.02857144-.31428571-.11428571-.4-.14285714-.05714286-.31428572-.02857143-.4.11428571zm-1.9714286.28571428c.08571429.14285715.25714286.17142858.4.11428572.14285715-.08571429.17142858-.25714286.11428572-.4-.05714285-.14285715-.25714286-.17142858-.4-.11428572-.17142858.08571429-.2.25714286-.11428572.4zm1.9714286-1.14285716c.0857143.14285715.25714287.17142858.40000001.11428572.14285714-.08571429.17142857-.25714286.11428572-.4-.11428572-.14285715-.25714286-.17142858-.40000001-.11428572-.14285714.08571429-.2.25714286-.11428572.4z"/>
</svg>
`;
}
if (variables.state === 'off' && variables.timeout < 2000) {
return `
<svg viewBox="0 0 14 14"> ${style}
<path fill="#2fae81" d="M1.57142849 6.14285713h10.85714302v1.14285716H1.57142849z"/>
<path fill="#67c7a5" d="M9.00000003 11.28571435H4.99999997c-1.25714288 0-2.28571432-1.02857144-2.28571432-2.28571432V5.28571426C2.71428565 2.91428566 4.62857139.99999991 7 .99999991c2.3714286 0 4.28571435 1.91428574 4.28571435 4.28571435v3.71428577c0 1.25714288-1.02857144 2.28571432-2.28571432 2.28571432z"/>
<path fill="#a1ecd1" d="m 9.0444711,5.4206731 c -0.7053572,0 -1.234375,0.5290179 -1.234375,1.234375 0,0.7053571 0.5290178,1.234375 1.234375,1.234375 0.7053572,0 1.2343749,-0.5290179 1.2343749,-1.234375 0,-0.7053571 -0.5290177,-1.234375 -1.2343749,-1.234375 z"/>"
<path fill="#a1ecd1" d="m 4.9471153,5.4459135 c -0.7053572,0 -1.234375,0.5290179 -1.234375,1.234375 0,0.7053571 0.5290178,1.234375 1.234375,1.234375 0.7053572,0 1.234375,-0.5290179 1.234375,-1.234375 0,-0.7053571 -0.5290178,-1.234375 -1.234375,-1.234375 z" />
<path fill="#607d8b" d="M7 9.00000003c-1.14285716 0-2.00000003.85714287-2.00000003 2.00000003 0 1.14285716.85714287 2.00000003 2.00000003 2.00000003 1.14285716 0 2.00000003-.85714287 2.00000003-2.00000003 0-1.14285716-.85714287-2.00000003-2.00000003-2.00000003z"/>
<path fill="#263238" d="M7 9.57142861c-.17142857 0-.28571429.11428572-.28571429.28571429s.11428572.28571429.28571429.28571429.28571429-.11428572.28571429-.28571429S7.17142857 9.57142861 7 9.57142861zm0 2.28571432c-.17142857 0-.28571429.11428572-.28571429.28571429s.11428572.28571429.28571429.28571429.28571429-.11428572.28571429-.28571429S7.17142857 11.85714293 7 11.85714293zm-1.22857145-1.5714286c-.08571428.14285715-.02857143.31428572.11428572.40000001.14285714.08571429.31428572.02857143.4-.11428572.0857143-.14285714.02857143-.31428571-.11428571-.4-.17142857-.05714286-.31428572-.02857143-.4.11428571zm1.9714286 1.14285717c-.08571428.14285714-.02857142.31428571.11428572.4.14285715.08571429.31428572.02857143.4-.11428572.0857143-.14285714.02857144-.31428571-.11428571-.4-.14285714-.05714286-.31428572-.02857143-.4.11428571zm-1.9714286.28571428c.08571429.14285715.25714286.17142858.4.11428572.14285715-.08571429.17142858-.25714286.11428572-.4-.05714285-.14285715-.25714286-.17142858-.4-.11428572-.17142858.08571429-.2.25714286-.11428572.4zm1.9714286-1.14285716c.0857143.14285715.25714287.17142858.40000001.11428572.14285714-.08571429.17142857-.25714286.11428572-.4-.11428572-.14285715-.25714286-.17142858-.40000001-.11428572-.14285714.08571429-.2.25714286-.11428572.4z"/>
</svg>
`;
} else {
return `
<svg viewBox="0 0 14 14"> ${style}
${path}
</svg>
`;
}
]]]
Thank you