Guidance on using Blockly

After searching for quite a while, it is now time to ask…I want to use Blockly to write some simple rules such as turn a Kasa plug on/off at a certain time, and on certain days.
I keep reading the Blockly docs but am missing a fundamental thing,

  1. Does Blockly need to be installed? (if so, how?)
  2. Where do I find Blockly in the openhab gui?
  3. where can I find a current tutorial with some simple examples?

Seems like all the docs I’ve read go through great lengths to tell you how wonderful it is and all the cool things it can do without describing exactly HOW to do it…

On the other hand, what I want to do can be handled as a cron task but I cant find a tutorial on how to connect openhab things to cron statements, which would also be helpful as an alternative to blockly

Thanks for any guidance

  1. Does Blockly need to be installed? (if so, how?)

No

  1. Where do I find Blockly in the openhab gui?

Create a new rule
For the action choose: run scrips
and then design with blockly

  1. where can I find a current tutorial with some simple examples?

Use your browser search for “openhab blockly tutorial” choose the first video that comes up

https://www.youtube.com/watch?v=EdllUlJ7p6k

It’s long but detailed.

Actually yes. You need to install the JS Scripting Automation Add-on to get Blockly.

Inline Script

The reference docs are Rules Blockly | openHAB, and it’s covered in Getting Started at Rules - Blockly | openHAB. But for a simple rule like you described where you set a light to com on at a certain time, you don’t even need Blockly. See Rules | openHAB and Rules - Basic | openHAB.

You probably want to go through the first three pages of The Getting Started Rules section.

Have you gone through Getting Started? That’s the whole point of that part of the docs, to walk you through setting stuff up end-to-end.

That’s becuase you don’t. Everything works with Items.

I figured it out and will answer my own questions:
1-Blockly is installed in and already a part of openhab 4.3
2-To get to Blockly, from the openhab simple GUI: Settings → Scripts → Add a script, e.g. TestScript, Save TestScript, then → Click on the test script. The Blockly components will show up as a colored pallet of elements (e.g. Logic, loops, etc.)

It would make things a lot clearer if the Blockly descriptions would say that it is a graphical representation of a scripting language (visual as well as textual). The description docs talk about rules which overload the rule concept.
3- One first can create a simple rule (Settings-> Rules), Use the + sign to create a rule. Choose When → add trigger → time event and choose the time conditions. Save and the rule should fire when the specified time occurs.

IMHO, if you are used to programming, consider creating scripts with text editor, the colored blocks in Blockly look like a jumbled mess (for complex rules) that visually take some time to parse…to each their own.

Thank you for the clarifications

I did not know that installing JS Scripting was a requirement and missing in Inline Script was from trying to do things from memory instead of having the correct screen in front of me.

Thank you. Yes, I did hand continue to read the docs. They are extremely detailed and IMHO, obfuscate the steps to initially create some simple rules and then scripts, e.g. a quick start guide.
I do appreciate the effort.

That’s one way to get to Blockly but it’s not really a way that is going to be useful to you given the specific problem you state you want to solve.

Rules are not an overloaded concept. Rules exist in openHAB as a concept independtly from the language one might choose to implement Script Actions and Conditions.

The term “Script” is unfortunately super overloaded with something like five different meaning depending on the concept (we even have a section in Getting Started and in the Concepts section of the docs IIRC discussing that unfortunate problem.

Which is why we support a custom DSL language, two flavors of JavaScript, Groovy, Ruby, and Python.

OH is big and very complex. And we can’t know which specific details everyone will need to know for their own getting started journey.

But if you’ve suggestions for anything that can be removed to make things clearer we are more than willing to adjust the docs to make them better. As with any all volunteer project, getting volunteers to contribute is a constant struggle.

But Getting Started isn’t really a quick start guide. I’m convinced a quick start guide is impossible for OH. Getting Started is a User’s guide. The rest of the docs are the reference docs.

Blockly is good for quickly getting up to speed with OH specific namespaces, objects and methods. But once you know them, you’re better off progressing to JavaScript code (which blockly generates). Coding in native JS gives you access to the full range of inbuilt functions, whereas OH blockly only implements a portion of them.

very complex - That is an understatement. I never expected such heavyweight machinery for home automation. It seems that it is trying to be all things to all people. Hats off to maintainers/developers keeping their heads wrapped around it.

Understood. I have a certain type of learning approach and that has somewhat shaded my teaching approach (in universities and industry).

Since you are intimately involved in this effort I’ll put a lot of weight on your view of a quick start guide. I’d like to add that a quick start guide could possibly be constructed based on a certain perspective that would abstract away a lot of detail but provide off-ramps to address more detailed use scenarios. The whole time I was trying to get my ‘simple’ use scenario working I was making notes on ‘steps’. Since I was ‘thrashing’ and eventually figured out some stuff, I’ll need to learn more about the capabilities and reformulate my approach/steps. If I stick with this, I’ll offer my cut at a ‘quick start’ guide. Initially, all I wanted to do was configure a smart plug and turn it on/off daily at a certain time. The doc I was following has the running example of a feedback control system with moisture sensor, actuator, schedule and various triggers. One should not have to read through 20+ pages to simply create the equivalent of a smart plug timer.

Which doc is this? I don’t think I’m familiar with this particular tutorial. Is it part of the official docs (i.e. Introduction | openHAB)? We don’t really have control over anything outside the OH project itself.

The complexity of home automation is often vastly underestimated. There are hundreds of siloed and incompatible technologies, tens of thousands of devices, and everyone’s requirements for home automation are almost completely unique.

openHAB compromises on simplicity but provides almost limitless possibilities when it comes to automation. But as a consequence, very simple things can be more complex than they otherwise could be (a lot of work has been and continue to be done to improve that). But the benefit is if you can code it, you can probably do it from an automation perspective.

If you are mainly looking for unified control over all your devices with a nice interface, HA might be a better choice but you give up some flexibility in automation capabilities.

If you are looking for automation, openHAB is IMO the best option out there. For an example of the sorts of automations people are doing with OH you can look in the Tutorials and Solutions section of the forum.

One common example is using the future price of energy coupled with the output from PV systems to schedule when/if to run the washing machine and drier.

My family’s favorite automation is on school days our smart speakers will announce when we need to leave in order to get the kid to school on time gien current driving conditions.

My most impactful automation is getting an alert if the motion sensor at my dad’s house doesn’t detect motion for too long a time.

It’s automations like these which combine three+ technologies and APIs to perform some action or actions automatically where OH really shines. But it’s the simpler stuff like turning on a light at the same time every day, where it is a bit more complex than the alternatives. If you don’t expect to grow beyond simple automations like these, openHAB may not be the best choice for your needs.

To steal from Neil Stephenson’s “In the Beginning…Was the Command Line”, openHAB is like Linux, a free tank. Not everyone is willing to learn to drive the tank, but the possibilities are limitless if you do.

Probably not and really, you don’t. But you have to know what the right pages to read are.

The way the official docs are designed, to most quickly get you up to this specific automation would be:

  1. https://www.openhab.org/docs/concepts/: If you don’t know the difference between and purpose of an Item, a Thing, and a Rule you are going to have a hard time with the rest of the docs.
  2. Getting Started - Introduction | openHAB and https://www.openhab.org/docs/tutorial/first_steps.html: Get OH up an running
  3. Adding Things - Simple | openHAB, or Adding Things - Intermediate | openHAB, or https://www.openhab.org/docs/tutorial/things_advanced.html: Get your first Thing(s) discovered or created. The first one covers the fully discoverable type technologies, the second one covers the most common case where one must first manually create a Thing (e.g. to connect to a USB dongle) which, once created, will discover all the devices. The third is for those technologies where dsicovery isn’t possible, Which is the right page to read? We can’t know, we don’t know which technologies you are using.If we only support the simple case in a quick start, anyone who doesn’t have such a technology is left out completely.
  4. https://www.openhab.org/docs/tutorial/model.html: Create your Items. Items are the way OH interacts with devices.
  5. https://www.openhab.org/docs/tutorial/rules_basic.html: If you read 1, you can probably skip Rules - Introduction | openHAB and Rules - Other Technologies | openHAB but simply toggling a Switch at certain times of day only requires simple rules. You don’t even need Blockly.

The challenge though is if your goal is to be able to toggle a light on or off from a UI, it’s a different set of pages that should be read. You’d skip the rules pages and read a couple of the UI pages depending on how you want to see it. If you want to see a chart on the UI of your temperature, it would be yet a different set of pages that are relevant. We want to support all of these users though, so it’s hard.

1 Like