Hello everyone,
I am currently building a custom widget for a PV system in openHAB and want to dynamically display the status of multiple smart plugs in a status bar.
My string item (Test_Wallplug_String) receives the following configuration format (Name:TargetState:GroupName):
Plaintext
Wallplug21:off:Group_GF_Storageroom_Wallplug21;Bad Steckdose:on:Group_GF_Bathroom_Wallplug23
My goal is to count in the widget’s status bar how many devices are defined as :on: or :off: in the string without the expression evaluator (=...) crashing with a TypeError: 'function' is not a function.
As soon as I try to evaluate the array using .filter() or .map() with anonymous functions, the UI throws the error.
Question: How do you write a safe string evaluation inside an expression within a custom widget to count items based on specific substrings (like :on:)?
Here is a snippet of my current status bar implementation:
YAML
- component: span
config:
content: "=(items[props.stringItem] && items[props.stringItem].state) ? items[props.stringItem].state.split(';').length : 'No data'"
Does anyone have a tip on how best to solve this using widget expressions?
Thank you in advance!