I wanted to create a sitemap to show the battery status of all my battery powered things. Some have a battery percentage where it was easy to find an example sitemap, but for devices that only report lowbattery through a channel it was not so easy to find a nicely formatted example.
Here is a workable solution - not perfect as each item has to be added twice, but the results are pleasing.
First of all a battery percentage is trivial, showing dynamic icons and the actual percentage on the right.
Frame label="Trådfri Controllers Battery Level"
{
Default label="TRADFRIRemoteControl_BatteryLevel"
item=TRADFRIRemoteControl_BatteryLevel
}
But the low battery item default, although simple to define, the results are not so great.
Default label="TRADFRIRemoteControl_LowBattery"
item=TRADFRIRemoteControl_LowBattery
This results in a moveable switch and the battery icon does not vary to show low battery warning
After scanning the OH docs and community, I came up with this:
Frame label="Nest Protects Low Battery"
{
Text item=KitchenNestProtect_LowBattery
label="Kitchen Nest Protect Battery" icon="battery" visibility=[ KitchenNestProtect_LowBattery==OFF]
Text item=KitchenNestProtect_LowBattery
label="Kitchen Nest Protect Battery Low" icon="lowbattery" visibility=[ KitchenNestProtect_LowBattery==ON]
}
When battery is OK it shows as a green icon
When battery is reporting low, then it displays a red icon - obviously a real example where a different device is currently reporting low battery.
In the sitemap snippet, there are two entries for each device which are alternately displayed (visibility) based on the low battery status. The standard icons - battery and lowbattery are used. The label adds the word low and the switch icon is suppressed by changing the item type to text.
h.t.h.