Battery Level Status

Thanks a lot Rich,

In the end, changing the oh-label to oh-list in the header made the trick and stopped showing the state outside of the badge. Thanks!

I’m struggling a bit to show my items with this.
When I add the widget, and fill in the group_items, I see my batteries.

But looks like I can’t save the page? I’m just loosing all info.
When I save, go to the code tab, and return, the group_items are gone in the settings?
Guess I miss something, but not sure what.

config:
  label: Batterijen
  sidebar: false
blocks: []
masonry:
  - component: oh-masonry
    slots:
      default:
        - component: widget:rlk_battery_status
          config: {}
grid: []
canvas: []

Some item examples:

 grep ALL_bat items/*
items/default.items:Group:Number:MIN 		ALL_bat 			"Batterijen [%d %%]" 		<battery>

items/gardena.items:Number		GardenaS1Battery 			"Grondsensor Moestuin [%s %%]" <battery> (ALL_bat, BU_bat) { channel="gardena:sensor:73f46e562b:92eb53ac-96c2-4193-a7c9-df1c4d8a578c:common#batteryLevel"}
items/ikea.items:Number 		Gordijn_AT_Bureau2ControlBat "Gordijncontrole Venster [%s %%]" <battery>     (ALL_bat, AT_bat) 	{ channel="tradfri:0203:gwd44da43c1dd9:65543:battery_level" }
items/netatmo.items:Number 		na_Outdoor_BatteryLevel		"Weerstation Buiten [%.0f %%]"     	<battery>   (ALL_bat, WO_bat)	{ channel = "netatmo:NAModule1:068acca6:0200003cf822:BatteryVP" }
items/netatmo.items:Number		na_Rain_BatteryLevel		"Regenmeter"				<battery>   (ALL_bat, WO_bat) 	{ channel = "netatmo:NAModule3:068acca6:05000005f2b0:BatteryVP" }
items/shelly.items:Number		Shelly001_Batterij			"Patio bewegingssensor [%s %%]"	<battery> (ALL_bat, WO_bat) 		{ channel = "shelly:shellymotion:39e03af21b:battery#batteryLevel" }
items/shelly.items:Number		Shelly006_Batterij			"Voordeur bewegingssensor [%s %%]"	<battery> (ALL_bat, WO_bat)	{ channel = "shelly:shellymotion:22145547c4:battery#batteryLevel" }
items/zwave.items:Number		Water_Kelder_Batterij		"Kelder Watersensor [%s %%]"		<Battery>		(ALL_bat, WO_bat)			{ channel = "zwave:device:30038385:node117:battery-level" }
items/zwave.items:Number		Water_Bureau_Batterij		"Bureau Water [%s %%]"  		<Battery>		(ALL_bat, AT_bat)			{ channel = "zwave:device:2f4ef5d0:node100:battery-level" }
...

ctrl-s usually will save your progress. But that before going to the code tab or exiting the layout page.

What ever is going on is genetic to MainUI and not specific to this widget.

OK, found it!

Seems I was edeting the wrong data.

  • I clicked the icon for ’ Edit Repeater’.
    I inserted the data over there in groupitem, and nothing was saved.

  • When I click the main widget icon (?), I arrived on ‘Edit rlk_battery_status’.
    Not so much options in here, and it works. :wink:

Great widget!

is it possible?

Maybe i have a Item like this

Group groupA "LabelA" (location) [Equipment]
Number ItemName "LabelB" <batterylevel> (groupA, groupB) [...] {channel="...}

and in Widget the item is just “loop.item”

        default:
          - component: oh-list-item
            config:
              title: = loop.item.label

loop.item.label = “LabelB”
but how to get “LabelA” of “groupA” of Item? i have tried loop.item.groups[0].label did´nt work

any clue?

You can find a discussion about how to get the equipment group of a point item in a widget here:

1 Like

I’m diving into the world of widgets since a couple of days and played with the filter.
I added an ‘eye’ button to display all battery levels. Pressing again will hide them again.
A different approach I tried was to open the battery levels group wel clicking on the icon, but I thing this is nicer.

battery_view

The code of the button is added twice in the code, with the ony difference the icon… When I tried this whith iconF7: "=vars.filterOn == false ? eye_slash_fill : eye_fill", the icon dissapears completely. So this is a workaround.

uid: battery_status
tags: []
props:
  parameters:
    - context: item
      description: Group:Number:MIN Item that aggregates all the battery levels
      label: Minimum Battery Level Item
      name: minLevel
      required: true
      type: TEXT
      filterCriteria:
        - value: Group
          name: type
    - default: "100"
      description: Maximum percentage to show in the widget
      label: Max Percent
      name: max
      required: false
      type: INTEGER
      min: 0
      max: 100
    - default: "60"
      description: The percentage above which green is used
      label: Green Level
      name: green
      required: false
      type: INTEGER
      min: 0
      max: 100
    - default: "30"
      description: The percentage above which orange is used
      label: Orange Level
      name: orange
      required: false
      type: INTEGER
      min: 0
      max: 100
  parameterGroups: []
timestamp: Dec 4, 2021, 11:29:59 AM
component: f7-card
config:
  title: Battery status
  style:
    noShadow: false
    padding: 0px
    border-radius: var(--f7-card-expandable-border-radius)
    box-shadow: 5px 5px 10px 1px rgba(0,0,0,0.1)
    margin-left: 5px
    margin-right: 5px
slots:
  default:
    - component: f7-block
      config:
        style:
          position: absolute
          top: 0px
          right: 0px
          flex-direction: row
          display: flex
      slots:
        default:
          - component: oh-button
            config:
              iconF7: eye_fill
              outline: false
              round: true
              color: white
              visible: "=vars.filterOn == false ? false : true"
              action: variable
              actionVariable: filterOn
              actionVariableValue: "=vars.filterOn == false ? true : false"
              style:
                width: 50px
                margin-top: 5px
                margin-right: -10px
          - component: oh-button
            config:
              iconF7: eye_slash_fill
              outline: false
              round: true
              color: white
              visible: "=vars.filterOn == false ? true : false"
              action: variable
              actionVariable: filterOn
              actionVariableValue: "=vars.filterOn == false ? true : false"
              style:
                width: 50px
                margin-top: 5px
                margin-right: -10px
    - component: oh-list
      slots:
        default:
          - component: oh-repeater
            config:
              fragment: true
              for: item
              sourceType: itemsInGroup
              groupItem: =props.minLevel
              filter: 'vars.filterOn == false ? true : Number.parseFloat(items[loop.item.name].state) <= props.max'
            slots:
              default:
                - component: oh-list-item
                  config:
                    icon: '=(Number.parseFloat(loop.item.state) > props.green) ? "f7:battery_100" : (Number.parseFloat(loop.item.state) > props.orange) ? "f7:battery_25" : "f7:battery_0"'
                    iconColor: '=(Number.parseFloat(loop.item.state) > props.green) ? "green" : (Number.parseFloat(loop.item.state) > props.orange) ? "orange" : "red"'
                    title: =(loop.item.label).replace('Battery level ','')
                    item: =loop.item.name
                    badge: "=(items[loop.item.name].displayState === undefined) ? loop.item.state + ' -' : items[loop.item.name].displayState"
                    badgeColor: '=(Number.parseFloat(loop.item.state) > props.green) ? "green" : (Number.parseFloat(loop.item.state) > props.orange) ? "orange" : "red"'
    - component: f7-card-footer
      slots:
        default:
          - component: Label
            config:
              text: '=(items[props.minLevel].state) > props.max ? "Battery levels are OK!" : "Minimum Battery Level: " + ((items[props.minLevel].displayState === undefined) ? items[props.minLevel].state : items[props.minLevel].displayState)'

The primary issue here is the two result options - you need quotes around them. When you start with = it’s an expression so the parser thinks that eye_slash_fill and eye_fill are variables (which are, of course, empty). If you use

"=vars.filterOn == false ? 'eye_slash_fill' : 'eye_fill'"

You should be able to get it back down to just one copy of the icon code without the visible workaround.

1 Like

Fantastic! 15 lines less code :slight_smile:

A post was split to a new topic: Help with a battery widget

@jebro, to maximize the utility of this thread and in accordance with the rules of the marketplace I want to keep it strictly on topic. I would like to ask that you move your post to a new thread in the Addons-UI category or the Tutorials and Solutions category. If there is something specific you want to recommend to change in the original post, please send me a PM or make a suggestion as a reply to this thread.

@adm105, to maximize the utility of this thread and in accordance with the rules of the marketplace, I’ve moved your post to it’s own thread since it is asking for help with a widget you’ve written yourself and not the original posted widget.

Hey @rlkoshak , I’m probably dumb but… I’m having quite a bit of difficulty in getting this to work. Maybe it’s me not understanding how to use the mainUI? Can you give me a pointer or two?
This is what I see when I set up a battery item. And I don’t understand how I can add more battery items either… I added multiple battery level status widgets to try to work it out but it’s not working as I assume it should. I added four widgets at the top.
Can you recognize what I’m doing wrong? I read this message “ Required Group:Number:MIN Item that aggregates all the battery levels “ and I’m pretty sure that I’m not following this correctly, but on the other hand I don’t know what to do either… please help?

Edit: maybe I should get more sleep. XD I think I got it now :smiley:

1 Like

You define a Group Item of type Number in Settings → Items. Configure the Group with an aggregation function of MIN.

Add all of your battery Items as members of that Group.

Configure the widget to use the Group Item as the “Minimum Battery Item”. Any member of the Group that falls below the “Max Precent” will be shown.

Based on the configuration you provide, it will list all the members of the Group below the provided threshold.

One widget for all your batteries, not one widget per battery Item.

1 Like

EDIT: @rlkoshak, I can see this bug fix is still missing?

It seems that displayState is never available in the loop? I get too many decimals:

Even though the pattern is specified for item, and displayState is available as standalone:

Running openHAB 3.3.0 release

Feature request: ability to customize/localize title text

It looks like I applied it to the title but not inside the repeater loop. It’s now in both places and there is a property for the title text.

1 Like

@rlkoshak same issue as in Service Status Standalone Widget - #7 by ssalonendefault parameter seems to break the addon, should be defaultValue? The widget cannot be installed anymore.

That makes it even weirder because this widget has always used default for the Number fields.

Maybe there is a mismatch between the importer parser and the widget editor.

I only changed the new property above. I left the number properties using “default”.

Still fails

2022-11-28 18:48:34.384 [ERROR] [munity.CommunityUIWidgetAddonHan
dler] [org.openhab.core.addon.marketplace] - Unable to parse YAML
: Unrecognized field "default" (class org.openhab.core.config.cor
e.dto.ConfigDescriptionParameterDTO), not marked as ignorable (22
 known properties: "readOnly", "max", "limitToOptions", "groupNam
e", "name", "stepsize", "context", "defaultValue", "min", "label"
, "filterCriteria", "verify", "type", "description", "options", "
required", "advanced", "unit", "multipleLimit", "pattern", "multi
ple", "unitLabel"])                                              
 at [Source: (StringReader); line: 15, column: 21] (through refer
ence chain: org.openhab.core.ui.components.RootUIComponent["props
"]->org.openhab.core.config.core.dto.ConfigDescriptionDTO["parame
ters"]->java.util.ArrayList[1]->org.openhab.core.config.core.dto.
ConfigDescriptionParameterDTO["default"])                        
2022-11-28 18:48:34.385 [ERROR] [munity.CommunityUIWidgetAddonHan
dler] [org.openhab.core.addon.marketplace] - Widget from marketpl
ace is invalid: Unable to parse YAML                             
data: {"topic":"openhab/addons/marketplace:128043/failed","payloa
d":"[\"marketplace:128043\",\"Widget is not valid.\"]","type":"Ad
donEvent"}                                                       
data: {"topic":"openhab/addons/marketplace:128043/failed","payloa
d":"[\"marketplace:128043\",\"Widget is not valid.\"]","type":"Ad
donEvent"}  

Hmmm. This must be something that changed. I’ll update the Number fields too.

Done

1 Like