How can I build a dynamic Item name for itemValue?


my goal is to create an Alarm clock widget with customisable Item names, so i can use one widget for different persons and days.
A typical item I need to control would look like:
NAME_WECKER_SO_H where NAME and SO are the “dynamic” parts.
In settings i defined two Strings:
owner_name (set to NAME)
theday (set to SO)

<label>{{itemValue('NAME_WECKER_SO_H')}}</label> gives me the actual value of the existing item
{{config.owner_name}}_WECKER_{{config.theday}}_H displays: NAME_WECKER_SO_H

but: <label>{{itemValue({{config.owner_name}}_WECKER_{{config.theday}}_H)}}</label> does not work.

I tried different variations but i just can’t find the right way to “nest” this :frowning:

Would someone know if this is possible at all, and if so provide an example?
Many thanks in advance,
Best Regards,

Hi Oli,

try to write it like this:

Value is: {{itemValue(config.owner_name + '_WECKER_' + config.theday + '_H')}}


This thread contains ideas

Hi Lars,
thanks, this is working great inside a “label” tag.
However now I got the next challenge:

ng-click="sendCmd({{itemValue(config.owner_name + '_WECKER_' + config.theday + '_H')}}, +{{itemValue(config.owner_name + '_WECKER_' + config.theday + '_H')}}+1)"

is not working. Not even some error in the logs.
Would you have another idea?
Thanks&Best regards,

Thanks Rossko,
I’m using this technique sucessfully in my rules, the examples just don’t help much in HABPanel.

You are trying to send a command to the value of an item and not to the item itself.

BTW: Does the command, you are trying to send, really starts with a + ? Seems strange to me :slight_smile:

Ugh…Cut&Paste error. actually i tried:


and yes, the + seems odd, but it is working as expected. This raises the items value by one:

<label class="btn-lg btn-default" ng-click="sendCmd('OLI_WECKER_SO_H', +itemValue('OLI_WECKER_SO_H')+1)"><i class="glyphicon glyphicon-plus"></i></label>

You could try to simplify the code and make it more readable:

<label class="btn-lg btn-default" ng-init="itemName = config.owner_name + '_wecker_' + config.theday + '_h'" ng-click="sendCmd(itemName, +itemValue(itemName)+1)"><i class="glyphicon glyphicon-plus"></i></label>

Create a variable in the ng-init and use it in the ng-click.

Strike! Just started fiddling with ng-init - you saved me at least half a day :slight_smile:
Thanks a million. Once it’s all finished I’ll add it to the Alarm clock example I’ve made so it covers Classic UI, HABDroid and now HABPanel…
Edit: All working, even though not really shiny yet…but function first:

In case you’re interested to see the end result: