As discussed in https://community.openhab.org/t/oh3-widget-vars-default-value/138318 it is currently not possible to set a default value for a variable in an OH3 widget.
Being able to do so would simplify many widgets and remove the need to manually protect against undefined variable son each and every expression.
The following widget code does not work, as the var. default value is not working:
uid: demo:default_vars
tags: []
props:
parameters:
- default: This is a default value
description: A text prop
label: Prop 1
name: prop1
required: false
type: TEXT
parameterGroups: []
timestamp: Aug 22, 2022, 5:38:10 PM
component: f7-card
config:
title: =(vars.prop1 || 'No Default Value Set')
The following is the result:
However when using props. as follows:
uid: demo:default_vars
tags: []
props:
parameters:
- default: This is a default value
description: A text prop
label: Prop 1
name: prop1
required: false
type: TEXT
parameterGroups: []
timestamp: Aug 22, 2022, 5:38:10 PM
component: f7-card
config:
title: =(props.prop1 || 'No Default Value Set')
the default value is used and results as follows:
In my widget I use many vars. expressions as they are carried across to other expressions etc and are changed in the widget, which it appears is not supported with props.
It would be useful to many if the default value could be extended to variables as well as the current props.
As discussed in https://community.openhab.org/t/oh3-widget-vars-default-value/138318 it is currently not possible to set a default value for a variable in an OH3 widget. Being able to do so would simplify many widgets and remove the need to manually protect against undefined variable son each and every expression.
The props. default value issue was resolved in https://github.com/openhab/openhab-webui/pull/1049/commits/cf7cfd9e5b7d2156f1b55c2c0f67698dade6e00f and it would be great is this could be extended to cater for variables as well.
The following widget code does not work, as the var. default value is not working:
The following is the result:
However when using props. as follows:
the default value is used and results as follows:
In my widget I use many vars. expressions as they are carried across to other expressions etc and are changed in the widget, which it appears is not supported with props.
It would be useful to many if the default value could be extended to variables as well as the current props.