stue
(Matthias)
April 13, 2021, 9:35am
1
Im looking for a way to define a default value for properties in custom widgets.
I see the “workaround” @RGroll is using in the weather widget.
"=(!props.itemPrefix) ? items.UVIndex.state : 'UV Index: ' + items[props.itemPrefix + 'UVIndex'].state
My goal is to define the default value in the parameter section (props) for a better structure:
uid:
props:
parameters:
- description: <b>Optional prefix</b> for item names.
label: Item prefix
name: itemPrefix
type: TEXT
default: myDefaultValue
But unfortunately, there is no parameter “default” in the docs:
https://www.openhab.org/docs/developer/bindings/config-xml.html
<parameter name="String" type="{text|integer|decimal|boolean}" min="Decimal" max="Decimal" step="Decimal" pattern="String" required="{true|false}" readOnly="{true|false}" multiple="{true|false}" groupName="String" unit="A|cd|K|kg|m|mol|s|g|rad|sr|Hz|N|Pa|J|W|C|V|F|Ω|S|Wb|T|H|Cel|lm|lx|Bq|Gy|Sv|kat|m/s2|m2v|m3|kph|%|l|ms|min|h|d|week|y">
<context>{network-address|serial-port|password|password-create|color|date|datetime|email|month|week|dayOfWeek|time|tel|url|item|thing|group|tag|service|channel|rule|location}</context>
<required>{true|false}</required>
<default>String</default>
<label>String</label>
<description>String</description>
<unitLabel>String</unitLabel>
<options>
<option value="String">String</option>
</options>
<filter>
<criteria name="String">String</criteria>
</filter>
</parameter>
By the way: what does this stands for:
<default>String</default>
What do you think about adding just an additional parameter “default”?
<parameter name="String" default="String" type="{text|integer|decimal|boolean}" min="Decimal" max="Decimal" step="Decimal" pattern="String" required="{true|false}" readOnly="{true|false}" multiple="{true|false}" groupName="String" unit="A|cd|K|kg|m|mol|s|g|rad|sr|Hz|N|Pa|J|W|C|V|F|Ω|S|Wb|T|H|Cel|lm|lx|Bq|Gy|Sv|kat|m/s2|m2v|m3|kph|%|l|ms|min|h|d|week|y">
Would this cause problems and would it be hard to implement?
RGroll
(Rainer)
April 13, 2021, 10:07am
2
stue
(Matthias)
April 13, 2021, 10:28am
3
Dammit, I haven’t seen that at all and Google didn’t told me even after 5h of search yesterday.
so that this topic here is not completely useless, can you shoot out a short answer for my last questions?
I did the same workaround for my widget
Note: Binding has changed the capitalisation since this post use code in post 16
With the help of the community I have created an Sesibo widget.
Here is what I have the widget looks like
[image]
After installing the binding and getting it online. With api key
[image]
Add you aircons as things
[image]
Then goto MODEL
Create equipment from thing
Select all items
[image]
Remember the name e.g. BedroomAircon
Now got Developer Widgets create a new widget and replace with…
uid: Sens…
Actually is you leave it as items you can set it as the things default widget and as long as long as the items follow the same name they will all show up.
stue
(Matthias)
April 13, 2021, 10:56am
5
Haven’t seen this workaround. Nice.
But after all it’s another workaround. Same as the - - f7-…-thing. There are other workarounds too.
I don’t have the full overview but I think implementing another parameter property won’t be a huge issue for the maintainer (who are doing a great job by the way ).
at the same time it would make it easier to build customizable custom-widgets and much easier to use and adjust those which is a big advantage for all openhab users
Oliver2
(Oliver)
April 18, 2021, 7:45pm
6
you can add default values to your widget’s props:
uid:
props:
parameters:
- description: <b>Optional prefix</b> for item names.
label: Item prefix
name: itemPrefix
type: TEXT
defaultValue: whatever
why does that not help?
stue
(Matthias)
April 18, 2021, 8:45pm
7
It’s not working in my case. If I open the “set props” handler, the field for itemPrefix is filled with the defined defaultValue but…
- component: Label
config:
text: =props.itemPrefix
… just gives me an “undefined”. If I manually change the value in the “set props” handler, this label shows the defined value/text
Oliver2
(Oliver)
April 18, 2021, 11:55pm
8
yes. that“s how I do it also. add a space character and delete it, so that it gets flagged as dirty and being recognized
stue
(Matthias)
April 19, 2021, 8:43pm
9
In my point of view this could be unnecessarily confusing for the regular user.
If there is a value shown in the input box, this value should exactly be recognized by the software/application /widget (automatically).