Switch / case rule in Blockly?

Hi,

I am currently trying to move all my rules from .rules files into rules which make use of Blockly etc. inside the main ui.

Is it possible in Blockly to recreate a switch / case rule?

rule "LivingRoom - Button"
when
    Item LivingRoomButton_Click received update
then
    switch(LivingRoomButton_Click.state.toString) {
        case "single": {
            logInfo("broker trigger debug", "triggered single click")
	        if(LivingRoom_1_LEVEL.state >= 1) {
            	LivingRoom_1_LEVEL.sendCommand(OFF)
	        }
	        else if (LivingRoom_1_LEVEL.state <= 0) {
	            LivingRoom_1_LEVEL.sendCommand(ON)
            }            
        }
        case "double": {
            logInfo("broker trigger debug", "triggered double click")
	        if(LivingRoomAmbilight.state >= 1) {
            	LivingRoomAmbilight.sendCommand(OFF)
	        }
	        else if (LivingRoomAmbilight.state <= 0) {
	            LivingRoomAmbilight.sendCommand(ON)
            }             
        }
        case "triple": {
            logInfo("broker trigger debug", "triggered triple click")
        }
        case "quadruple": {
            logInfo("broker trigger debug", "triggered quadruple click")
        }
        case "many": {
            logInfo("broker trigger debug", "triggered many click")
        }
        case "long": {
            logInfo("broker trigger debug", "triggered long click")
            TestDummy.sendCommand(3)
        }
        case "long_release": {
            logInfo("broker trigger debug", "triggered long_release click")
        }                
    }
end

Maybe use “if/else-if” blocks? Similar, switch is just syntactic sugar.

1 Like

Hello together,
is there another solution for that without if else statements?

Why would you need one? What would you gain over using if / if-else blocks?

Why we have switch in Javascript and why we not use else if? Same question…
If you have so many if boxes you get lost. There are so many blocks eg text or arrays you can put the needed data together. There will maybe a same way for cases and switch.