Battery Level Status

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

Thank you. Now it installs fine. I can also confirm that the bug with displayState is also resolved

Is there a way to sort the list ascending by battery level or since it’s not possible the Minimum Battery Level is displayed at the top?
It seems like the list is sorted descending by item name.

1 Like

The Minimum Battery Level is displayed at the top.

Not that I’m aware of.

Now that expressions support arrow functions, you can use the repeater map function to achieve pretty good sorting of objects on the basis of key values, but it will break the widget for anyone not at least using recent milestones.

1 Like