First Simple Blockly Script not work

Hi, try to create my first blockly script and send some commands to my device. I have OH 3.2.0

  1. Create a “virtual” RollerShutter device
  2. Create Idle Blockly Script

    3 Press buttons on the “virtual” RollerShutter device and see the reaction in OH Log
    image
    4 Nothing happens, my Blockly script don’t send any command to my device(((

The script is just a script. To react to openHAB events you need to use Triggers - you need to use Rules where you define a Trigger, and then you can call a Script.

In addition to @hafniumzinc
The internal state of a rolershutter item is a number between 0 (open) and 100 (closed), as you can see in your log (last line).

Therefore e.g. any UP command is internally translated into state 0.

If you build a rule you either need to listen to the received command (what would be UP), or validate the item state against any number between 0 and 100.

1 Like

Control by names UP DOWN STOP work perfectly, but I try to start use blockly because I wanted to do all logic in one file. If i use 3 separate rules (every rule gets trigger from one button and sends only one command) all work perfectly, but I think is not good because there will be too many rules in the future, or it’s ok if I use one rule for one button? - maybe there is a better solution?

PS I also try to create one rule that is triggered by any button(UP/DOWN/STOP) and then run my blockly script… but this does not work((

You can do both, 1 rule for all actions or 3rules.

If you can post both version, the one that’s working and the one that’s not working, then someone can maybe help

The only reason that not use three separate rules is I want to keep my OH cleaner and use fewer rules files… so I want(if possible) to do all logic in one file, not only in this case but in future automation.

Here is a video. In the video, I show how I setup a single rule for one UP button(work solution) and how I setup one rule for all three buttons(not working).

The video is helpful, but you can also just copy and paste the code of the rule next time if you want.

As already mentioned before state and command are different, therefore your 2nd example is not working.
The command is UP but the state will change to 0 (if state is different then 0) or will not change at all (if it’s already 0).

Do the following, with your “not working” rule:

From the actions section remove the action to execute your script, but define the blockly code directly in your rule (new action → run script → blockly)

Add logging for received command (available within openhab → run & process → contextual info) and item state and test your rule. This should give you the expected results and show the difference between command & state.

Then you can rebuild your logic with received command instead of item state.

Can you do me a favour and explain exactly what your intent is, what you are trying to achieve? I am sure we can then guide you what to do.

Thx I will try

Hi, my goal is to control 433Mhz “Window opener device” from google home by voice. Tools what I have:

  • broadlink rm pro - is Universal remote I use it for sending 433 commands on “Window opener device”
  • Window opener device - 433Mhz device that I buy on Aliexpress it accepts Open/Close/Stop commands and open-close window
  • “virtual” RollerShutter device - is a virtual device that I create in OH3 and expose it to google home, it accepts commands from the interface buttons and google home.

If short - with three separate rules I already can do Voice control… but I choose the hard way and want to experiment (as a bonus keep my OH a little cleaner) so I try to find a way how to operate all three (UP, DOWN, STOP) commands from “virtual” RollerShutter device in one rule/script file.

Fair enough, but how exactly does it have to be controlled?

Imagine you would tell someone how to control the Hardware what commands would you give them? If you like me to tell you how to do it with blocklies I need to have at least some pseudo code or some explanation of the algorithm as I yet don’t know what to control when, how and why.

Sorry don’t understand about “some pseudo code” example that I can give (maybe you have an example of what you mean))). If simply say the case is - I have three commands (commands not important) and I have three buttons (in basic OH “virtual” RollerShutter device). How to create logic in one file so that when any of three buttons are pressed, three commands are sent (each to its own button).

Here is the new code in one blockly script (i put it inside the rule structure as Matze suggests).


Now I get working Up/Down function in “one” file… but how to get a Stop? Also “received commands” do not work and return “undefined:sob:
image

PS because my device (windows opener) does not support any feedback (it only accepts Open/Stop/Close Commands) I want to crate and save a custom global variable (to check if it is moving true/false) is this possible in blockly?

  • what triggers the rule?
  • what is “virtual blinds”?
  • what are the button items called that should control the blind?
  • why do you want to access the “received command”?

… want to create and save a custom global variable
Please read the blockly reference for value storage

Can you provide the three individual rules? Merging them into one should be easy.

Please read the blockly reference as I have just finished it and it should be complete now. It also gives you some guidance in the beginning about the triggering of the rule.

The rule should be triggered by item → received command

If the rule is triggered manually for testing or by item → change, then you will receive the “undefined”

The trigger rule for a single file is:
image

By buttons and virtual (a device that doesn’t have representation in “Thing” menu) devices I mean this:

I try to get access to the “received command” because I think maybe this can help me get Up/Down/Stop signals from “Virtual device” that show in a log message:
image

Problem was that I use my blockly script in the wrong trigger option “was updated”, but after the last message from Matze0211 I change it to “received a command” and now my script can execute “received command” and work as i need. So, for now, I think all work ok.

Thanks, guys I learn many new things with your help. Post here the last blockly script I put it in a single rule