receivedCommand in blockly?

Hi,

maybe it’s a stupid question, but how do I react to a command which was send to an item?

Just the equivalent to this DSL rule:

triggers:
  - id: "1"
    configuration:
      itemName: test
    type: core.ItemCommandTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: |-
        switch (receivedCommand){
          case ON: {
            logInfo("TEST","TEST received ON")
          }
            
          case OFF: {
            logInfo("TEST","TEST received OFF")  
          }
        }
    type: script.ScriptAction

That is not yet supported in Blockly.

If you want to do it in JavaScript as blockly doesn’t support it then it is like this:

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
var Exec = Java.type("org.openhab.core.model.script.actions.Exec");
var Duration = Java.type("java.time.Duration");
var TOPIC = null;
var PAYLOAD = null;

var rfinput = itemRegistry.getItem('RFBridgekitchen_Receiveddata').getState().toString();

switch(rfinput) {
 //row 3 green and switch is on S
     case 'BB369A':
     events.sendCommand("Lightsshedinandoutside_Shedlights", 'ON');
       logger.info('Shed lights ON');
    break;

//row 3 red and switch is on S
     case 'BB3692':
     events.sendCommand("Lightsshedinandoutside_Shedlights", 'OFF');
       logger.info('Shed lights OFF');
    break;
  default:  
}

any news when “received command” will support in blockly?

PS maybe there is another way (in blockly) to get

buttons click?

PR is made and under review. There will be an event block and you can get to the item command through that.

1 Like

It has been made available with the 3.2.0 Release,

The Blockly Reference though is work in progress which is why you don’t see it yet there.

1 Like