Blockly missing block to update a dictionary value

OH 4.3.2

Unless I missed it, I don’t see a way to update the value of a dictionary key, the equivalent in javascript of:

mydict["mykey"] = "newvalue";

I had to use the “inline script” block to do this. It seems that these are the only two blocks for dictionaries:

Am i correct? If so, could it be added?

Open an issue on opebnhab-webui.

Those parts of the menu come from the upstream project so adding it might require going there but starting with openhab-webui is probably the right place.

So I guess from your answer that this is currently a limitation.
I opened an issue like you suggested.
Thanks.

For those who want to follow it:
Blockly missing block to update a dictionary value · Issue #3075 · openhab/openhab-webui

see blockly: set value to key of dictionary by stefan-hoehn · Pull Request #3078 · openhab/openhab-webui · GitHub

1 Like

Hi Stefan,
i am aktually trying to use the set feature for dictionaries.
My Openhab version 4.03 Commit 4cdd594a and there is Set “ “ to value “ “ of dictionary “ “ available.
In the PR from Mar8 florian-h05 added the 5.0 Milestone label.

My problem at the moment is, regardles how i try to add values to dict key:

dict_raw

dict_stringified

dict_asnumber

The generated code always looks like:

myArraytest\[(‘key’ + String(eventNumber))\] = ‘parseFloat(eventWeektest)’;

As effekt i am not able to get the value of eventWeek into the dict but the strings “eventWeektest”, “(String(eventWeektest))” or “parseFloat(eventWeektest)”.
I already tried to create myArray as typed Variable and also eventWeek from type Number but this changed anything.
Am i doing something wrong here, was this PR not intended to allow values from type Number or do i have to upgrade to Milestone5.xx to get this working ?

If you are running OH 4.x than you need to upgrade to at least 5.0. 5.1 should be released in a week or so.

Hi Rich,

thanks for the quick answer.

Had a typo in my first post my OpenHab version is 5.03 !

The block to set value in an dict (assigned to an variable) is already available for me in my version of openhab.
And its possible to assign a value to the adressed key, but it only assigns strings.
In my case instead assigning the value of the variable “eventWeek” it assign the string “eventWeek”.
Even if i try to convert the value of the variable into an string, not the string representation of the value gets assign but the string “String(eventWeek)”.
Same applies when trying to convert into a number before assigning.
I looked into the code for the block at Add block to set value to key of dictionary but i am uncertain if the PR allows assigning values of an variable to the dict.
My programming skills aren’t mature enough to get on to.

So i am not sure if this PR solves my problem as i thaught it basicly deals with making this block available at first.

This works for me.

The first log says 6 and the second says 60

 [INFO ] [omation.jsscripting.rule.1_test_dict] - 6
 [INFO ] [omation.jsscripting.rule.1_test_dict] - 60

Thanks for the answer,

but i decided to solve this problem with a different approach.
It’s for an Garbage Widget with sliders showing the exact date (mostly friday or saturday) of the collection and icons of the respective garbage trash cans getting emptied.

Besides the fact that the date varies there can be 0 to 3 waste types each week.
So i was trying to find a solution by precollecting the info per week.
This i was able to achieved with an additional string item with a JSON array that i fill every time the first waste item changes (from icalender).

Here is an animated gif of this Widget (Version without my correction thus showing wrong Dates):

muell-widget