Lately I have been making some small changes for my things and the model, to make use of more OH3 ui features. So for my heating, I wanted to make the little badge appear in the rooms, signaling that heating in that room is on.
After googling for the conditions of those badges, I saw that I need an item that is a “state” to be on or off. My homematic valve thing doesn’t have that, but it has an “opening level” as a dimmer item.
So, easy solution, create an item that gets set to “ON” whenever “opening level” is higher than zero.
Just for fun, I wanted to try to create this really simple rule in blockly, and here we are:
At first it didn’t even have the “else if” part, I just added it for debugging, because … whenever I run the rule, I end up in the “else” part.
==> /var/log/openhab/openhab.log <==
2021-02-25 18:05:24.901 [INFO ] [org.openhab.rule.7fe90d98e4 ] - 91
So my guess is, blockly isn’t treating this dimmer items as a number. I changed the item type to number, but besides the logfile output (0.91) nothing changed - probably because the channel is a dimmer as well.
Usually you would use item.State as Number to fix this. But how do I do this in blockly?
I couldn’t find a function for it. I tried to create a variable and set this to the item … same result and no other options for the variable operator.
I mean … I know that blockly is limited, I’m just a bit confused that it already fails me at this level?
Note: I tried to use the “getItemState” block first in the IF condition, but this puzzle doesn’t dock there …
For reference, this is the javascript code from the rule above:
var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
if ('HeizungKuche_Level' > 0) {
events.postUpdate('HeizungKuche_Status', 'ON');
} else if ('HeizungKuche_Level' == 0) {
events.postUpdate('HeizungKuche_Status', 'OFF');
} else {
logger.info(itemRegistry.getItem('HeizungKuche_Level').getState());
}