openhab / openhab-webui

Web UIs of openHAB
Eclipse Public License 2.0
216 stars 238 forks source link

[Blockly] New Block for enabling and disabling a thing #2590

Open Larsen-Locke opened 3 months ago

Larsen-Locke commented 3 months ago

The problem

Currently it's not possible to change the enabled-status of a thing within blockly.

With the new blocks introduced in 4.2M3 it's possible to get various information about a thing. On top of that it would be a great feature if it was possible to enable and disable a thing. With this feature all things, even bridges could be disabled and enabled. (It's something that you usually do manually if a thing has a connection problem: You disable and enable it)

Your suggestion

Introduce a new block "set enabled/disabled [thing]" An alternative could be "toggle enabled-status [thing]"

rkoshak commented 3 months ago

In the mean time you can use the inline script block.

  1. Create a new Types Variable setting the type to "Thing Object". I'll call it "myThing"
  2. Set the variable using a "get thing" block.
  3. use an inline script with myThing.setEnabled(false); to disable.

image

Larsen-Locke commented 3 months ago

that's directly possible in JavaScript now? I thought you need the thing manager for that, like: myThingManager.setEnabled(UID, true). But anyway, the idea was meant to complete the capabilities of blocky for the "normal" user

rkoshak commented 3 months ago

that's directly possible in JavaScript now?

Yes. See https://www.openhab.org/addons/automation/jsscripting/#things. The "get thing" block pulls the Thing Object and you can simply call setEnabled(bool) on the Thing Object to enable/disable. There's more you can do to it too. See the link.

But anyway, the idea was meant to complete the capabilities of blocky for the "normal" user

Agreed, but there is no telling when or if this will get implemented. Until it does, the approach above will work for you and anyone else who comes across this issue.