I’m having a bit of trouble trying to get this to work. I have installed the plugin, and it is working with this sensor:
sensor.speedtest_download:
templates:
icon_color: >
if (state > 500) return 'rgb(0, 255, 0)';
if (state > 400) return 'rgb(100, 255, 0)';
if (state > 300) return 'rgb(150, 255, 0)';
if (state > 200) return 'rgb(200, 255, 0)';
if (state > 150) return 'rgb(255, 255, 0)';
if (state > 100) return 'rgb(255, 200, 0)';
if (state > 50) return 'rgb(255, 150, 0)';
if (state > 30) return 'rgb(255, 100, 0)';
if (state == 'unknown') return 'rgb(50, 50, 50)';
return 'rgb(255, 0, 0)'
The color of the entity changes depending on the internet speed. Pretty great and I’m very happy with it! However, I want to do it in a smarter way, continuously changing the color without creating all these if statements. I’m trying to do that with this template:
sensor.speedtest_upload:
icon: mdi:speedometer-slow
templates:
hs_color: >
var hue = Math.round(Number(state)/1000*240);
return '['hue ',80]'
However, this is not working. I tried many variants of this code, for example using:
sensor.speedtest_upload:
icon: mdi:speedometer
templates:
hs_color: >
'[{{states.sensor.speedtest_upload.state|int/1000*240}}, 80]'
But both are not working, and I don’t really know how to fix it. I found a topic of someone who tried the same thing, but cannot find that anymore. Is what I’m doing simply not possible, or is there something wrong with my syntax?
What should the language of the code be by the way?