OH3 Widget vars default value

The same solution works as part of any expression, so:

groupItem: =(vars.selectedPartition || "Partition1") + '_Bypass_Group'

works just fine. But it’s true that if you have a lot of variable use in your widget it can get tedious and difficult to track.

It never hurts to ask! There quite a few widgets that could be greatly simplified if this were possible. On the other hand, I don’t know if there’s some technical reason why this hasn’t been done up to this point.

There is one other option possible, but it’s a workaround that really only works if you plan on having only one of these widgets on a single page. I said initially that variables in widgets couldn’t have default values, but variables can also be defined on pages so that widgets have access to variables with a more “global” scope and can communicate with each other. These page level variables can have default values set. So if you’re only going to have one widget using the variable, then you can just also define the variable at the page level and give it a default value there.