Comparing two items in blockly doesn't work

I might have found a little problem.
When i create a point as dimmer and want to compare it inside a rule with a brightnes of a light, it doesnt trigger.

if (itemRegistry.getItem('EzPreBri').getState() == itemRegistry.getItem('EzTischZone_Helligkeit').getState())
    something happens...

i don’t get an error in the logs. I think the type for both items is the same so it might not be a type conversion error.

You could try and log the state of both to see how they look like

I already done that. The Resul was that 20 = 20 but the rule doesnt work.
Can someone reproduce the problem?

Possibly related

In A rule file this is no problem because i can define to convert if there is any conflict. in this case i used the new blockly thing.

Just to go a little bit deeper into this problem, when i compare two items and set they are defginitly the same value, i am not able to get back a true result.

if (itemRegistry.getItem('EsstischZone_Helligkeit').getState() == itemRegistry.getItem('EzPreBri').getState())

EsstischZone_Helligkeit is a philips hue brigthness Item and EzPreBri is a manualy added dimmer Item.

Could anyone trie to reproduce this error? is it a general thing or just related to my system?

Maybe Important to know:

  • i used blockly to create this simple request.
  • when i compare EzPreBri to itself, everything works fine
  • when i compare EzPreBri to another Item with the same stats, it doesnt work.
  • when i use “abc”) all compared Items are string types
  • when i set EzPreBri to 20 an compare it just to 20 it also works.

What are your actual Item types?

when i use "EzPreBri")

it returns string.

in my item settings it is set as Dimmer

I think that’s correct, “EzPreBri” is just a string constant not your Item object.

Okay, good, what about the other Item?

also a Dimmer

I Think i have found the sollution.
When you create a rule with blockly and trie to compare two item values, for example:


then openhab compares the pointers towards the values and not the values them self. This is an issue wich should be fixed.

To solfe this problem you can switch to the javascript view. you should see this:

if (itemRegistry.getItem('WzPreBri').getState() == itemRegistry.getItem('LiBri').getState()) 
  events.sendCommand('MyItem', 'something awesome');

now you have to openhab to use the value and not the pointer.
in my case the values are integer type but this also works for other types.
The magic word is “parse…()” in my case “parseInt()”

in my case i have to change the first line to:

if (parseInt(itemRegistry.getItem('WzPreBri').getState()) == parseInt(itemRegistry.getItem('LiBri').getState())) 

i hope this will help if someone has a simiular problem.