Blockly programming question

Hello guys,
I am trying to be friend with google’s blockly.

I am trying to make a script toggling the smart plug with Xiaomi Smart Cube. What is wrong with this script?

image

Is there a webpage with examples of blockly in OH3?
Thank you,
M.

if item Kocka == SHAKE_AIR is not really meaningful. The Item is never going to be SHAKE_AIR. The Item’s state probably will be what you want to test (just like you do on the nested if statement).

With a rule like this, you don’t even need Blockly. You can create two rules:

  1. trigger when Kocka changes to SHAKE_AIR
  2. Add a condition to only run the rule when BWSHP63_state is not ON
  3. Add an action to send command ON to BWSHP63_state

Second rule

  1. trigger when Kocka changes to SHAKE_AIR
  2. Add a condition to only run the rule when BWSHP63_state is ON
  3. Add an action to send command OFF to BWSHP63_state

No code required.

Thank you for good explanation!
I was experimenting with your reccomendation and now I can control roller blind and a socket in my test room.
If they are 5% and less closed and I shake with cube, they are going down and turning on the socket
In other case they are going up and switching off the light.
There is only a short step to adapt it to group of Ikea blinds and the ceiling light in Living room now!

1st Rule

2nd Rule

I did not add But only if RoletaZadna_Position >= 5, because it was not working.

M

BTW,
would this be correct then?

image

why there should be the purple frame around it?
M

Maybe. You’d have to try it to see if it will work. I don’t see anything wrong with it but I don’t have Blockly memorized. The purple block looks like you added a function or something.

1 Like

I ended up with two rules, one with roller position = 100 and another = 0. the < > signs was not working good.