Thank you for the tips regarding switchSupport and the right format for percentage in labels!
I now get the idea of the rule to replace the behavior one would get with real hardware (that’s interesting for testing purposes), but I cannot make that guard condition at the beginning to work that way:
if(!(dlQC.state instanceOf DecimalType))
// Results in: The name '! <XMemberFeatureCallImplCustom>' cannot be resolved to an item or type.
if(dlQC.state instanceOf DecimalType)
// Results in: The name 'DecimalType' cannot be resolved to an item or type.
This dynamic type system of Xtend is too confusing for me. I managed to implement something that works properly and also behaves OK with the switch with the following rule instead:
rule "Fake Dim dlQC"
when
Item dlQC received command
then
var Number cs = if (dlQC.state instanceof DecimalType) dlQC.state as DecimalType else 0
switch receivedCommand {
case INCREASE :
dlQC.postUpdate(if (cs > 95) 100 else cs + 5)
case DECREASE :
dlQC.postUpdate(if (cs < 5) 0 else cs - 5)
case OFF :
dlQC.postUpdate(0)
case ON :
dlQC.postUpdate(100)
}
end
The only inconvenient is that, when I switch OFF and ON, I think it gets the value 1 (which should mean 100%) but it actually treats it as 1%, so INCREASE sets the dimmer to 6%, then 11% and so on.