I am using something similar, but, I think more complex. I have defined for my wife and I, we usually cycle to work , what I call a bike comfort index. The idea is to show on lovelace something like this:
The color of the bike is a combination of min temp, max temp, wind and rain. The values at the 4 corners are the minTemp / maxTemp / rain and max wind.
Getting the values from the weather API up to sending all the results to HA through API is done like this:
The complex part is the javascript in BikeSensorsMF:
minTemp = {}
maxTemp = {}
windGust = {}
maxRain = {}
confort = {}
var windGustmax = 0;
var Tmin = 50;
var Tmax = -30;
var Rain = 0;
for (var i=0; i<24;i++) {
if (msg.payload.forecast[i].wind.speed > windGustmax) {
windGustmax = msg.payload.forecast[i].wind.speed;
}
if (msg.payload.forecast[i].wind.gust > windGustmax) {
windGustmax = msg.payload.forecast[i].wind.gust;
}
if (msg.payload.forecast[i].T.value < Tmin ) {
Tmin = msg.payload.forecast[i].T.value;
}
if (msg.payload.forecast[i].T.value > Tmax ) {
Tmax = msg.payload.forecast[i].T.value;
}
Rain += msg.payload.forecast[i].rain["1h"];
}
minTemp.value = Tmin;
maxTemp.value = Tmax;
windGust.value = (windGustmax * 3.6).toFixed(1);
maxRain.value = Rain.toFixed(1);
indice = 0
if ( minTemp.value < -5 ) indice = 6 + indice ;
else if ( minTemp.value < 0 ) indice = 4 + indice ;
else if ( minTemp.value < 5 ) indice = 2 + indice ;
else if ( minTemp.value < 10 ) indice = 1 + indice ;
if ( maxTemp.value > 40 ) indice = 6 + indice ;
else if ( maxTemp.value > 35 ) indice = 4 + indice ;
else if ( maxTemp.value > 30 ) indice = 2 + indice ;
else if ( maxTemp.value > 25 ) indice = 1 + indice ;
if ( windGust.value > 50 ) indice = 10 + indice ;
else if ( windGust.value > 40 ) indice = 6 + indice ;
else if ( windGust.value > 30 ) indice = 4 + indice ;
else if ( windGust.value > 20 ) indice = 1 + indice ;
if ( maxRain.value > 5 ) indice = 6 + indice ;
else if ( maxRain.value > 4 ) indice = 4 + indice ;
else if ( maxRain.value > 3 ) indice = 2 + indice ;
else if ( maxRain.value > 2 ) indice = 1 + indice ;
if ( indice >= 10 ) confort.value = 5;
else if ( indice >= 6 ) confort.value = 4;
else if ( indice >= 4 ) confort.value = 3;
else if ( indice >= 2 ) confort.value = 2;
else confort.value = 1;
return [ minTemp, maxTemp, windGust, maxRain, confort ];
I assume all of this is doable in templates. The problem (for me at least) is the debugging part of templates.
I know very little of javascript. And I was able to do this (crappy) code.
So, not perfect, but, I believe easier to code and to debug than templates. At least for me
GV