Giter Site home page Giter Site logo

Comments (7)

5iver avatar 5iver commented on July 17, 2024

Thank for for submitting this feature request, but the core helper libraries are only a temporary crutch until the rule engine has been further built out with features. It would be possible to implement something like this in Jython, but by implementing it in the rule engine, it could be used in rules built through the UI rule editor and any scripting language. There have been discussions about implementing Actions or Profiles as a replacement for the Expire binding functionality in OH 3.0.

That said, Area Triggers and Actions implements similar functionality by just adding some Item metadata.

from openhab-helper-libraries.

mjcumming avatar mjcumming commented on July 17, 2024

@boc-tothefuture what is the use case for this scenario?

from openhab-helper-libraries.

boc-tothefuture avatar boc-tothefuture commented on July 17, 2024

@mjcumming -
In this particular case I want to send a notification if any of my ESPHome devices go offline for more than 30 minutes. I have done this in the past with virtual items w/ the expire binding and creating and maintaining my own timers. However, I wanted an easier solution with little to no boilerplate.

from openhab-helper-libraries.

5iver avatar 5iver commented on July 17, 2024

I use some ESP12Es and check that they are still online with the network binding. Here is the metadata I use to get a notification when either are offline for more than an hour...

set_metadata("Status_Network_ESP12E_01", "area_triggers_and_actions", {
    "actions": {"notification_action": {"OFF": {"delay": 3600, "types": {"audio": True, "mobile": True}, "Priority": 0, "recurring": True}}}}, overwrite=True)
set_metadata("Status_Network_ESP12E_02", "area_triggers_and_actions", {
    "actions": {"notification_action": {"OFF": {"delay": 3600, "types": {"audio": True, "mobile": True}, "Priority": 0, "recurring": True}}}}, overwrite=True)

from openhab-helper-libraries.

rkoshak avatar rkoshak commented on July 17, 2024

#233 provides a library that does all the Timer management book keeping for you. With one function call (check()) you can create a new timer or reschedule it if it already exits. You pass it up to two functions, one that optionally gets called if the Timer already existed when check was called and the other that gets called when the Timer expires.

So for the simple case where you want a Timer to check when foo is ON for five minutes

from core.rules import rule
from core.triggers import when
from community.timer_mgr import TimerMgr # probably should go in personal.timer_mgr until/if it gets merged

timers = TimerMgr()

def on_too_long(itemName):
    # what you do when the timer expires

@rule("timers for being on too long")
@when("Item foo changed to ON")
def changed_on(event):
    timers.check(event.itemName, 300000, lambda: on_too_long(event.itemName))

With the above code, if no Timer exists when check is called with the name event.itemName, one is created. If check is called before the timer triggers it gets cancelled. If check isn't called before the five minutes is up on_too_long gets called.

The library also has the option to reschedule the timer instead of cancelling it and you can pass an optional function to it to that gets called when check is called and the Timer already exists, useful for sending alerts that an Item is flapping for example.

from openhab-helper-libraries.

boc-tothefuture avatar boc-tothefuture commented on July 17, 2024

@rkoshak -
This does not cancel the timer if the item get changed to "OFF", Correct? That logic would still need to be implemented (potentially in the on_too_long method).

from openhab-helper-libraries.

5iver avatar 5iver commented on July 17, 2024

This issue is resolved and the requested feature will not be implemented. If you wish to discuss alternatives, please do so in the forum.

from openhab-helper-libraries.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.