Dimmer as a Switch change from OH2 to OH3

One of the differences I have noticed is the change in how dimmers are treated when used in switch mode.
OH2 - defined a dimmer with sitemap and rules using switch and sendCommand(“ON”) (rightly or wrongly) .
In OH3 sendCommand must be (ON) no quotes or (“100”)
Same goes where we have widgets using different coloured icons for on/off - needs .state ==“100” for on otherwise doesnt work…or at least that’s the simplest way I have found.

None of that is the case for me, so that might be specific to your devices. What bindings are you using?

Sitemaps are nothing like MainUI widgets, so you should expect completely different syntax.

Tell us more about rules though…

There are a lot of different things gong here having to do with the type of an item, the difference between and openHAB state and command and how various parts of OH access data.

A dimmer Item has a state and that state (unless it is NULL or UNDEFINED) will be a number. On the other hand, OH is smart enough to allow dimmers to accept many different commands. ON and OFF are both sensible commands for a dimmer item as are INCREASE and DECREASE and specific numbers. On the other hand PLAY, which is a valid command for a Player item, is not a sensible command for a dimmer item.

The important part is that even if you send the command ON to a dimmer item this does not make it’s state ON. It’s state just gets sets to some number usually depending on how that item’s binding has been configured to interpret that command. Part of the confusion here is common because ON can also be a state for certain item types, but as far as OH is concerned, ON the command and ON the state are two fundamentally different things.

This is where the sendCommand part comes in. The function expects a string value (that typically means something that is defined as being between quotes such as "ON"). The underlying code of the sendCommand function is then smart enough to change that string into what it thinks is the most sensible command to send to the item (and assuming that your code is reasonable, it does quite a good job of this). Some of the rules languages, most notably rulesDSL, do have some built-in “helpful” shortcuts that allow certain values to stand in for commands and states without being explicitly defined as such and so you can compare a item state to ON or send ON as a command in rulesDSL with no other effort on your part.

Similarly, when working with item states in certain contexts, OH is smart enough to do some basic conversion if required. A dimmer’s 0-100 state can be sensibly, in some cases, converted to a true/false value by assuming that 0 is false and anything greater than 0 is true. OnOff states have a similar sensible true/false context so some comparison can be made. Again, this is not universal and you should not expect that just because an Item can receive an ON command that it’s state can be sensibly compared to an ON state.

Widgets are another story altogether, however, because the information in widgets does not com directly though the OH core, it comes from calls to the OH API where the information is always returned as a string. So in widgets, the “state” you are using for display or comparisons is always a string version of the true OH state. This explains why you must use item.YourDimmerItem.state == “100” as the test in a widget - via the API the dimmers state of 100 has been delivered as a string.

There’s one more piece to this. A channel that can be linked to a dimmer item, such as a light bulb’s brightness channel, can also often be linked to a switch item. Now this item will have ON or OFF as its state and the conversion between the number the channel actually represents and the binary state is handled by the link. But, if you do this, then you can directly and sensibly compare that item’s state to ON or OFF even when you can’t do that for the dimmer item.

In OH2 rules sendCommand (“ON”) Worked fine
In OH3 needs either sendCommand(ON) or sendCommand(100)
Both zwave and zigbee

I never used quotes with my dimmers in OH2 rules. I wasn’t aware that worked, but sendCommand(ON) definitely did.

This is true for rules, and not what you said earlier.

In my previous message, I should have said that “must be (ON)” was the case for me. What I meant is that I’ve never used quotes for dimmers in OH2 or OH3.

As the others noted, widgets work differently, and thus require quotes.