Initialize non semantic item

  • Platform information:
    • Hardware: Raspi 4B
    • OS: Raspbian
    • Java Runtime Environment: 17
    • openHAB version: 4.02
  • Issue of the topic: please be detailed explaining your issue

Hi there,
I’d like to have a non semantic item for summing up energy values from other items over time by use of a Blockly rule. The item is member of a group with persistance only if updated.
As long as the item is empty (“NULL”) it is not pickable in Blockly. How can I initialize such an item, say set it to zero?

Michael

I just do a script and hit the run now at the bottom of the script page and post update.
Here is a JS example:

items.getItem(“Curtain_window”).postUpdate(“OPEN”)

Save the rule the first time before you run it.

you would use something like:
items.getItem(“youritem”).postUpdate(0)

Tried it with a ECMA script, but that didn’t work, even by using “items.getItem.state”
Script runs for a while (5 secs) and item stays unchanged.

Just tick „Show non-semantic“ at the bottom of the items pick dialog.
It is possible to select items with null state.

Otherwise choose any item and make changes directly in the code tab.

1 Like

Selection dialog without problems, but selection was not transferred to blockly item.

Otherwise choose any item and make changes directly in the code tab.

But the last one did work!

I tested it. It is possible to select non-semantic and uninitialized items.
Something is wrong on your side.

After trying several times it works now also with the item selection dialog. Reason for the behavior is not clear. Maybe it had to do with some effects after upgrading to Openhab 4.0.2.
Thanks!

If you use the developer sidebar (alt-shift-d) the third tab has a “Scratchpad” option which will create a -Scratchpad- Script which is perfect for this sort of thing. And it’s quickly accessed thanks to the developer sidebar.

In newer JS Scripting, the following is supported which is a little more terse and easier to read.

items['Curtain_window`].postUpdate("OPEN");
items.Curtain_window.postUpdate("OPEN");

Logs? Which ECMAScript version, 5.1 or 11?

It’s Edition 11.
Didn’t look in the logs after having initialized the items. Right now there is no warning present, even after starting a simple rule, which took nearly 15 seconds. (But mostly the rule is completed in parts of a second.)

I do it this way because then I can use the ctrl-space to auto-complete the item names

If I use

items['Curtain_window`].postUpdate("OPEN");

the auto-complete doesn’t work. But it is good to know that is an option.

The longest rule I have is probably only 10 lines long so readability is not an issue for me.