- Switch/Case
Another thread states that getting into trouble with switch/case and numbers.
(Problem with case and switch in rules)
The solution was
Switch((Group_preset.state as DecimalType).intValue)
{
case 1: {
}
case 2: {
}
}
The problem is that the number item can be a float value and “1.0” is not the same as “1” for switch/case…
- Group_preset
As far as I know, you can’t set an item to null. But if you use a number item, you can set it to Zero (0) which is different from null or uninitialized.
I recommend use Zero (=0) instead of null.
=> as @rossko57 mentioned:
Group_preset.postUpdate(0)
In your rule you can remove the if/else and just go with switch/case
Switch((Group_preset.state as DecimalType).intValue)
{
case 0: {
gLight.sendCommand(ON)
}
case 1: {
gLight.sendCommand(OFF)
Yeelight1_p.sendCommand(ON)
Yeelight2_p.sendCommand(ON)
}
case 2: {
}
}
- sendCommand
It’s better to use the method of an item instead of the action. So use gLight.sendCommand(OFF) or Yeelight1_p.sendCommand(ON) instead of sendCommand(Yeelight1_p, ON)
The difference:
the method of the item knows exactly of what type the state is. The action has to guess the type of state and could be wrong…
Andreas