How to rigger alert when i detect no movement

OH 3
openhabian on raspberry
Z-wave.
Hi,
I am trying to figure out a rule on how to trigger a message when i detect no movement.

Here is the scenario :
When mamy gets up at night, i detect movement first in the bedroom, followed by movement in the hallway, then in the toilet.
So i would like to trigger a notification, when movement in the toilet ends, and i see no subsequent movement in het hallway or further up in the bedroom. (checking she hasn’t fallen).
Newbee in openhab - Suggestions on how to get started on this one?

Thks in advance!

???
Shall we guess ?

??? excuse me, do not understand your reply?

This is going to be a quite a bit more complicated than your title suggests. You aren’t just trying to do something after a motion sensor stops reporting movement. You need to track a sequence of events with a maximum allowable amount of time between them. That’s not going to be remotely easy.

Your requirements are:

  1. only runs at night?
  2. when movement in the bedroom is detected expect movement in the hallway within X seconds. If that doesn’t occur, exit.
  3. when movement did occur in the hallway expect movement in the bathroom within X seconds. If that doesn’t occur, exit.
  4. after the last movement in the bathroom, within X seconds expect movement in the hallway or the bedroom. If that doesn’t occur, send an alert. If that does occur, exit.

1 is easy to handle using a condition. Just set up a “between times” condition in the UI rule. If insisting on using text based rules, add code to the beginning of the rule to exit if it’s not night time.

For 2, trigger the rule based on the bedroom motion detection. If the condition passes, take a timestamp and create a timer to clear out the timestamp after X seconds. If the timestamp and timer already exist for this motion sensor, take a new timestamp and reschedule the timer.

Trigger the same rule with the hall motion sensor. If the timestamp and timer doesn’t exist for the bedroom motion sensor, exit. If the timestamp and timer do exist for the bedroom motion sensor, take a new timestamp in a different variable and create a new timer for the hall motion. When the timer expires clear out the timestamp. If the timestamp and timer already exist, save the new timestamp and reschedule the timer.

For 3, repeat the above only checking the hall motion sensor’s timestamp and timer and creating a new timestamp and timer for the bathroom motion sensor. The only difference here is in addition to clearing out the timestamp, this timer needs to generate the alert (use the timestamp to know when the last motion was detected).

For 4, when the rule triggers with the hall or bedroom motion sensor, look to see if there is a timestamp and timer scheduled for the bathroom motion sensor (probably needs to be the first thing the rule does). If they exist, cancel the bathroom motion sensor’s timer and clear out the timestamp.

This could be implemented using just one trigger: when movement detected in the toilet.

When it’s triggered, check if it’s within the time range that you want to monitor

Next, check if there was recently movement in the bedroom, followed by hallway. You can just check the motion sensors last update time.

If that condition is met, start a timer.

Within the timer’s code, again check the last update of the motion sensors for toilet vs hallway. If hallways last update is before the toilet’s send an alert.

The problem is when your mom is still in the toilet and someone else triggered the motion sensor in the hallway or bedroom… The timer code won’t trigger an alert.

Hi Rich,

Thank you very much for your reply. Your description of the requirements are indeed exactly what i want to achieve.
Point 1 is indeed very simple.
Triggering the rule is also simple, however being newbee : "If the condition passes, take a timestamp and create a timer to clear out the timestamp after X seconds. "
can you explain a bit more in detail on how to do this, or point me to the doc?

Thks

Rudy

Hi Jim,

thks. Correct, i was indeed thinking indeed that the toilet movement could be the starting point. And since she’s living alone no pets, i don’t have to worry about other movements.
Rich his approach has the advantage that I also monitor the hallway, should she fall there.

Come to think of it, it seems that the rule could be very simple: When you detect motion in either the toilet or the hallway, set a timer. In that timer, check if motion in the bedroom occurred later than the last motion detected in the other areas, then she’s safe, otherwise, alert

Here’s the rule in jruby. Yes it looks very simple, much much simpler than if you had written it in any other language. The timer syntax here (with id) means that if another motion is detected (whether it’s in the hallway or the toilet), it will cancel the previous timer and start a new one automatically for you.

rule "Possible fall alert" do
  changed Hallway_Motion, Toilet_Motion, to: ON # or however you detect motion
  between "7pm".."7am" # or use different conditions accordingly, e.g. when livingroom lights are off
  run do |event|
    after(10.minutes, id: :fall_alert) do
      next if Bedroom_Motion.last_update > event.item.last_update # no need to alert, she made it to the bedroom

      room_name = event.item.name.split("_").first # This will give you either "Hallway" or "Toilet"
      notify("Alert! Last detected motion was in the #{room_name} at #{event.item.last_update}. She didn't make it to the bedroom.")
    end
  end
end

Thank you!

Will test this right away.

It depends on how you want to write rules. See the Getting Started Tutorial in the Docs as well as the new Rules page under the Concepts section of the docs (only available in the 3.4 version of the docs right now). Then choose a language you want to write rules in and see that language’s reference page for details.

The syntax will be different.