Dimming with Blockly not working

Hi all,

Im trying to use remote scene switches to dim my lights.

Every time i execute it i get the following errors
What am i missing here…

I just want to add or subtract 10 from the dimmer as long as im holding the switch.

2024-01-27 20:21:02.375 [WARN ] [rnal.defaultscope.ScriptBusEventImpl] - Command '-10' cannot be parsed for item 'ZWaveNode026_Dimmer (Type=DimmerItem, State=20, Label=Chandelier, Category=DimmableLight, Tags=[Point], Groups=[ZWaveNode026])'.
2024-01-27 20:24:11.940 [WARN ] [rnal.defaultscope.ScriptBusEventImpl] - Command '1010' cannot be parsed for item 'ZWaveNode026_Dimmer (Type=DimmerItem, State=10, Label=Chandelier, Category=DimmableLight, Tags=[Point], Groups=[ZWaveNode026])'.```

You may need to clamp the value to between 0 and 100.

you’re getting a string from your dimmer item. Then your operations are done on strings and returned as strings which causes the error.
If you use OH4 then you have the number-block under “math” to convert to a number.

Btw: OH4 has huge improvements for blockly-users that make it so much easier an fun. So in case you haven’t upgraded yet that’s the time…

Btw @stefan.hoehn (sorry to ping you, but you’re the wizard): Why does getState from a dimmer-item return a string and not a number? A dimmer is always a number, isn’t it. The same from a number-item works without conversion.

In OH3 you had to multiply your variable by 1 to turn a string into a number.
Screenshot_20240128-081421~3

1 Like

In openHAB4, use get <numericState> of Item (<numericState> is part of the dropDown list, default value of this list is <name>)

IMHO this is because Strings often return Units with the value like 1000 K(elvin) which results into a String. As Udo has mentioned, just use the numeric state instead.

console.info(items.getItem('colorTemperature_lightStrip').state);
console.info(typeof items.getItem('colorTemperature_lightStrip').state); -> String 
console.info(items.getItem('colorTemperature_lightStrip').numericState);
console.info(typeof items.getItem('colorTemperature_lightStrip').numericState); -> Object -> effectively a Number

Hope that helps…

1 Like

Thank you! Added the number conversion and were all good!

Looking at your long item ids I wonder if you know this toggle which shows the item name instead?

image