I’m trying to figure out how to get the battery status displayed for different battery-operated devices. They all return their status in percent and I want to display an according icon.
I know it’s supposed to work like the other dynamic icons i.e. switch.png, switch-on.png and switch-off.png. And that works fine, but when using a percentage value the icon is only displayed when there is an icon with the corresponding value present i.e. battery-25.png, battery-50.png, battery-75.png and battery-100.png.
So the icons only appear when the battery is exactly 25%, 50%, 75% or 100%.
How can I change that behaviour? I think it should work with a MAP-File. Can you give me a hint?
Not sure this is currently possible. I also was playing with it, but gave up on an icon for every value. Tho if you had a cool graphic set with 100 points in the bar that could be cool.
why not working with a tem variable instead that is used for display.
if you get a return value for the battery state - you post this one with a rule into a temp variualbe that puts it to 25/50/75/100 state based on the value you want to display it?
something like:
rule "BatteryTemp"
when
Item battery received update
then
if (battery.state<=25) {
postUpdate(batteryDisplay, 25)
}
if (battery.state<25<=50) {
postUpdate(batteryDisplay, 50)
}
if (battery.state<50<=75) {
postUpdate(batteryDisplay, 75)
}
if (battery.state<75<=100) {
postUpdate(batteryDisplay, 100)
}
end
((!! untested rule !!))
Thanks that’s an interesting approach.
If i understand correct, that would leave me with the correct icons but the percentage-display would only display 25, 50, 75 or 100 and not the real battery values like 56%, 77%,… or do I miss something?
Did you get any further with this? Perhaps it is possible to add dynamic SVG states with a bit of client side programming? I am new to openHab - but digging in as I type.
I wanted to do the same thing but for a volume icon that has 3 states. I solved it with brute force.
What I did was created a sub folder ‘volume’ in the icons directory and copied my three icons there. I then created a bunch of hard links to them. One link for each possible volume value. Note that it has to be hard links. Soft links doesn’t work.
The bash command I used to create the hard links to the icons. The icon file names are volume–99.png, volume–59.png and volume-15.png. The volume range is -99 to 15:
for i in `seq -98 -60`; do sudo ln volume--99.png volume-${i}.png; done
for i in `seq -58 -20`; do sudo ln volume--59.png volume-${i}.png; done
for i in `seq -19 14`; do sudo ln volume-15.png volume-${i}.png; done
My sitemap (I used the trick above to get the mute icon in)