Handle commands before being sent to the item


Is there a way to handle the commands sent to a item? A rule isn’t appropriate because I want to catch the command before the item receives it.

Thank you!

I may not fully understand what you need as you do not describe your use case, but here some pointers:

The use case is sending commands to a voice assistant when the related Thing is OFFILNE.

If I tell Google to perform an action to an item whose Thing is OFFLINE, the assistant replies correctly, saying that the command was send to the Item. The problem is that even tough the Item changed, the actions wasn’t performed.

My idea was to catch the command that is sent to an item, and check if the related Thing is ONLINE or OFFLINE. If it’s ONLINE: send the command to the item; if t’s OFFLINE: tell google that the item isn’t available.

Perhaps what you really want is to disable autoupdate on this Item. if you can rely on feedback from the device/binding under working conditions.

I never heard of autoupdate before. It seems a possible solution, but I’m not sure how can this help in this case. I’m using Z-Wave binding, so I guess is something like:

  • Declare the Item:
   Switch ZWave4_Item "Item name" {channel="zwave:device:ca5bbe0e:node4", autoupdate="false"}
  • Declare a rule:
rule Test
  Item ZWave4_Item received command
  if (Thing == "ONLINE") {
    // Return OK to voice assistant?
  else {
    // Return KO to voice assistant?

But how can I return the result to the voice assistant?

I think this “intercept the command” is the wrong approach. As is looking at Thing state.

Can we be clear - the assistant tells you that it sends the command, whether it’s likely to work or not?
And what you would like is confirmation that it worked (or not) with an additional message “Okay” (or “Failed”) ?

I’d tackle that with a timer.
Start a short timer when item receives command.
(the command gets announced as normal)
If device updates before timer expires, say “hurrah!”
If timer expires, say “failed!”

You’d probably have to add some detail about what to do if the command works but has no effect, e.g. command ON something that is already ON.


I am reviving this topic because the original question was not answered:
Is there a way to trigger a rule or a script before a command is sent?

I suspect it is not possible, but it would be great to have a trigger like ‘willReceiveCommand’ as it would make sense to have the possibility to do something just before an command is sent.

For example, I have a zwave device that requires a specific manufacturer command to be sent before the thermostat mode could be put to Manual. The manual command exists but sending it to the device returns an error if the specific manufacturer command is not sent before. The channel for this specific command exists, and sending the command manually from the console works, but I would like to create a simple rule to send the manufacturer specific command just before the manual command is sent.

Anyway, I am not here to discuss about this particular example, but on how to trigger a script or do some action just when a command is about to be sent. This is a feature that would allow more flexibility and possibilities for OpenHAB rules.

Thank you

No, but even if there was, there is no way to ‘intercept’ the command to modify it or perform another action. Meaning, if there was a trigger for something like ItemStatePredictedEvent, there still would be no way to stop the command from getting through. I don’t see a trigger for this event being useful, but I may add it in.

Your best option is to use a proxy Item to trigger a rule that performs the actions.


The openHAB event bus distributes command events to anyone that might be listening. Bindings, rules, etc.

If you want a two stage event, or some kind of sequence, you must make your own with the use of an intermediary Item or similar.

Thank you @5iver and @rossko57

Do you consider in the future adding the ability for the openHAB event bus to send a notification event just before it distributes a command event?
I thing that it could be a very powerful thing. even if it would not allow to intercept (change or cancel) the command (but allowing that as well would give a lot of programming power).

As for my example, I am considering systematically creating a proxy for each of my Things, as I believe in MVC programming design (Model View Controller), the Proxy being the Model.

Sounds a useless feature to me. If you have a command event to distribute, just do it.
If you want to massage a command before you send it to the bus, do that.
If you want to trigger some chain of other events from a command on the bus, do that.

I cannot see any benefit in announcing what you’re just about to do anyway. (Even though Daleks always do that!)


That is not useless.

I switched from Jeedom to OpenHAB recently. One great thing about Jeedom is the ability to trigger something before or after a command is sent, and I used it both. OpenHAB allows to trigger only after.

This is particularly useful when we don’t know what or who is doing the trigger but we want to know before the command is sent to do something before. ObjectiveC notifications relies on that too with events ‘somethingWillHappen’ and ‘somethingDidHappen’.

Telling ‘I am about to do that’ is not the same as ‘I just did that’ and allow to react beforehand. Of course, being able to intercept the command, Change it or abort it would give the full power to this concept.

I can’t see much use in it, but if you want to do it that way, it is pretty easy to do so with an intermediate Item.
Use the building blocks already available to you.