"Delayed Command" profile to replace timers

We now have Profiles to use between our Items and Channels. I want to discuss if it is possible and useful to use a profile to delay commands to be sent to the channels.

I use Timers (and sometimes the expire binding) to delay actions pretty often in my “smart” (as in “hands-off, no manual control needed”) setup of openHAB. Some of the everyday-life examples:

  • Turn on small lights instantly when entering a room or walking by

  • Turn on the big lights only if people stay there for more than 20 seconds (using Timers)

  • Switch HiFi-peripherals/TV ON/OFF only if the AV Receiver Input stays for 3 seconds (using Timers, for debouncing the Input-Knob-Turning)

  • Consider “everyone asleep” only if there is no motion for some time (using Timers)

I have timers all over the place and they do almost the same thing over and over but are implemented in so many different places and with different parameters. Would this be a thing we could control using the new Profiles feature? The description says With Profiles, you’re able to change the behavior how Channels interact with your Items. so I would assume I could use it to have the Item receive the command, but delay sending it to the Channel, re-check the Item’s state and only send the Command to the Channel if the Channel’s state is still the same? Like this:

Using the first example from above:

  • Person entered living room, grabs something, and leaves. Living Room PIR updated to ON
  • Rule sends Command=ON to lights through “delayed action”-Profile
  • Item is ON but lights stay off to obey the delay
  • Living Room PIR updated to OFF
  • *Rule sends Command=OFF to lights (but they are still OFF, physically)
  • Delayed action times out
  • Profile will now send the current Item State to the Channel
  • Channel receives command OFF (or nothing, because it’s the same as before)

Or - if the person stays in the room:

  • Person entered living room, stays, keeps triggering the PIR, so it stays ON for a long time. Living Room PIR updated to ON
  • Rule sends Command=ON to lights through “delayed action”-Profile
  • Item is ON but lights stay off to obey the delay
  • Person is still in the room, PIR is still ON
  • Delayed action times out
  • Profile will now send the current Item State to the Channel
  • Channel receives command ON

I hope this was clear enough. I’m having a hard time explaining this correctly. Please ask, if I left out any details or am too unclear :wink:

What do you think? Is this something we could generalize using profiles? Is it too hacky? Is it more hacky than using Timers?

2 Likes

I’ve had some discussion with this with David and I don’t think there is any way to use Profiles to replace Expire binding. Or maybe it was that there was a better approach. I don’t quite remember and am not sure where that was posted any more.

I think the big problem is Profiles are stateless and to replicate Expire there needs to be storage of some state between events.

I in no way want to replace the Expire binding. The Expire binding is great for resetting Items to a hard-coded state after being in another state for a predefined time.

My intention is to have something like a forward-expire binding. Maybe a binding is possible, too, yes. It would have to somehow block the command (which I don’t think is possible) to the channel and plan a timer, that - after expiring - really sends the command to the channel. Whichever command is set now (as opposed to before).

If you use don’t mind using Jython then I think you may be able to adapt the example provided here.

def execute(self, module, input):
    if self.forward == "command" or self.forward == None:
      events.sendCommand(self.this, str(items[self.other]))
    elif self.forward == "update":
      events.postUpdate(self.this, str(items[self.other]))
    else:
      log.info("Unsupported forward type: {}".format(self.forward))

Instead of sending the command immediately you’d place your timer code there and when the timer expires you get the current item state and send the command to the other item which then causes your lights to turn on (or something like that).

I guess that would be feasible but may be @smhgit can shed a light on this :slight_smile:

@marcel_erkel

Adding delay seems feasible to me (Should be simple unless I miss something). I am using this approach just for this cases, where adding extra feature can be simple until (and if) the feature will be added to the base.

1 Like