Old v2 rule into gui code

Hi, I have a rule that I need to upgrade. It used to work in 2.x but no longer in 3.x
I would be happy with help to put it in a rules file or the Gui code section.
Can someone please help me out, I have tried all day with no joy.
Here is my old rule that doesnt like " receivedEvent.getEvent()"

rule “Mijia Wireless Switch”
when
Channel “mihome:sensor_switch:04cf8c9783a3:158d0002f80bdc:button” triggered

then
var actionName = receivedEvent.getEvent()
switch(actionName) {
case “SHORT_PRESSED”: {
if (SW3_01_1.state != ON)
SW3_01_1.sendCommand(ON)
else SW3_01_1.sendCommand(OFF)

    }
    case "DOUBLE_PRESSED": {
        if (SW3_01_2.state != ON)             
             SW3_01_2.sendCommand(ON)
         else  SW3_01_2.sendCommand(OFF) 
        //currState = currState + 1
        //val func2 = brlight.get(currState % brlight.size)
        //func2.apply()
                    
    }
    case "LONG_PRESSED": {
        if (SW3_01_3.state != ON)             
             SW3_01_3.sendCommand(ON)
         else  SW3_01_3.sendCommand(OFF)
        
    }
    //case "LONG_RELEASED": {
    //    Bedroom_Light.sendCommand(100)
    //}
}

end

see here
it is now

receivedEvent

Seriously?
So just to be sure, it’s

var actionName = receivedEvent
instead of
var actionName = receivedEvent.getEvent()

The manual said get rid of getEvent but didn’t know thats what it meant.

Cheers

Yes. No need to assign receivedEvent to a variable as receivedEvent already is a variable

Thanks working Well.
rule “Mijia Wireless Switch”
when
Channel “mihome:sensor_switch:04cf8c9783a3:158d0002f80bdc:button” triggered

then
var actionName = receivedEvent
switch(actionName) {
case “SHORT_PRESSED”: {
if (SW3_01_1.state != ON)
SW3_01_1.sendCommand(ON)
else SW3_01_1.sendCommand(OFF)

    }
    case "DOUBLE_PRESSED": {
        if (SW3_01_2.state != ON)             
             SW3_01_2.sendCommand(ON)
         else  SW3_01_2.sendCommand(OFF) 
        //currState = currState + 1
        //val func2 = brlight.get(currState % brlight.size)
        //func2.apply()
                    
    }
    case "LONG_PRESSED": {
        if (SW3_01_3.state != ON)             
             SW3_01_3.sendCommand(ON)
         else  SW3_01_3.sendCommand(OFF)
        
    }
    //case "LONG_RELEASED": {
    //    Bedroom_Light.sendCommand(100)
    //}
}

end

A couple of things.

First, please use code fences when pasting code or logs to the forum.

```
code goes here
```

To answer parts of your question not yet answered:

To make this a UI rule is pretty straight forward.

  1. Navigate to Settings → Rules → + to create a new rule
  2. Fill out the ID, name, and description
  3. Add a trigger → Thing Event → your mihome Channel
  4. Add an action → Script Action → Rules DSL
  5. copy the code between then and end into the script action

That’s it. For this rule it’s pretty simple.

You could look into reimplementing it as Blockly or one of the other languages but it’s not necessary.

Thanks Rich and Oliver, much appreciated.
I did get the old Rule to work by making 6 simple rules in the ui. 2 for each of the 3 triggers, your way seems much easier.
Cheers