Can't get state===ON to work in a widget

I’m running OH3.1.0M5 and trying to create a widget with a button with some dynamic features but I seem to not be able to get the syntax right.

I have an item, a switch, called test_switch. When I enter this in the Code Tools - Widgets Expression Tester:

=(items["test_switch"].state) 

The answer is: ON

Yet when I enter:

=(items["test_switch"].state === ON)

The answer is: false

I get the same for =(items.test_switch.state === ON)

I must be overlooking something silly.

Maybe related, when I try to update test_switch using a command from an oh-button I see this in the logging:

2021-06-16 11:25:42.704 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: toString
2021-06-16 11:25:42.704 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: t
2021-06-16 11:25:42.704 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: te
2021-06-16 11:25:42.704 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: tes
2021-06-16 11:25:42.704 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: test
2021-06-16 11:25:42.705 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: test_
2021-06-16 11:25:42.705 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: test_s
2021-06-16 11:25:42.705 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: test_sw
2021-06-16 11:25:42.705 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: test_swi
2021-06-16 11:25:42.705 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: test_swit
2021-06-16 11:25:42.705 [WARN ] [e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: test_switc

Have a look in this post which explains the different operators, “===” is used only in very specific cases to my understanding. You might just want to use “==”?

Add " around ON

=== "ON"

items.test_switch.state

and

items["test_switch"].state

is essentially the same.

I’ve tried == as well, no difference. (The === I used since this is used in the examples on oh-button - Button | openHAB)

For == vs. ===

== in JavaScript is used for comparing two variables, but it ignores the datatype of variable. === is used for comparing two variables, but this operator also checks datatype and compares two values. Checks the equality of two operands without considering their type. Compares equality of two operands with their types

Thank you (and the others responding as well)!

I knew it was something like that, kept overlooking it. It IS confusing because in a rule I can do KitchenBlindsRight_Control.sendCommand(UP)

Be careful not to mix up Rules DSL and JavaScript. That post you linked to is for Rules DSL and what was said there may or may not actually translate to JavaScript. In this particular case there are some subtle differences in JavaScript. === is actually a little different in JavaScript and Rules DSL. In Rules DSL === looks to see if the two operands are actually pointing to the same place in memory. In JavaScript it instead does more checks for equality but does not require both variables to point to the same place in memory.

1 Like