I am looking for the solution to set a different icon for a device, depending on it's value;
I have a device presenting the battery percentage of a battery powered sensor.
What i want to do is update the icon according to the percentage (power left) of the battery;
I can only set one of these in config.js
// value <= 20%
icon: 'fas fa-battery-empty',
// value <= 50%
icon: 'fas fa-battery-quarter',
// value <= 75%
icon: 'fas fa-battery-half',
// value <= 85%
icon: 'fas fa-battery-three-quarters',
// value > 85%
icon: 'fas fa-battery-full',
Should i create something like the below, according to this example in custom.js? Any thoughts? Is there an easier approach?
Code: Select all
function getStatus_281(block) {
var percentage = parseInt(block.device.data)
if (parseFloat(percentage) <= 35) {
block.icon = 'fas fa-battery-empty';
} else if (parseFloat(percentage) <= 50) {
block.icon = 'fas fa-battery-quarter';
} else if (parseFloat(percentage) <= 75) {
block.icon = 'fas fa-battery-half';
} else if (parseFloat(percentage) <= 85) {
block.icon = 'fas fa-battery-three-quarters';
} else {
block.icon = 'fas fa-battery-full';
}
}