I have been thinking about best practice for developing a widget and the fast way to implement good code with the least amount of effort from the user.
Looking at the already awesome UI Widget: Weather
I decided to try it. I installed binding then thing… easy.
Next I went to Model / Create Equipment From Thing / Select ALL and create thing
You can get to this stage in a couple of min with every item created for you.
Lets take one item into consideration
This Item Localweatherandforecast_ApparentTemperature
Current outside temp
Is not the same needed for the widget Number localCurrentApparentTemperature "[%.0f°]"
You can’t change the item name once created in mainUI.
Note: This is not a complaint
Creating items this way puts them all under a group.
Localweatherandforecast
If you set a widget as the default widget the item props is auto populated to this value.
uid: fancyWeather
tags:
- weather
props:
parameters:
- description: "<b>Optional prefix</b> for item names.<br>More infos here: <a>https://community.openhab.org/t/ui-widget-weather/106842</a>"
label: Item prefix
name: itemPrefix
required: false
type: TEXT
groupName: general
If the name: itemPrefix
is changed to name: item
then item would be Localweatherandforecast
Then you can assign each item using the auto generated item which will always have a Prefix
=items[props.item + "_ApparentTemperature"].displayState || items[props.item + "_ApparentTemperature"].state
This is very helpful if you have multiple things of the same type.
Others have suggested the same thing and RGroll has done a fantastic job. I apologise that I encountered this on his example widget.
I think when selecting the Widget as the Default widget I can auto populate the data here.
I think this may lead to less questions about how to setup widgets and more fun time for all.
Please discuss feedback is welcome as is other ideas to standardise widgets.