Use of Timers within OH 3

A few things I notice:

  1. var Bath_Timer gets recreated every time the rule runs. You need to save that variable so the Timer gets preserved between runs.

    this.Bath_Timer = (this.Bath_Timer === undefined) ? null: this.Bath_Timer;

  2. Why are you pulling the Item from the registry just to get it’s state? items["MotionSensorPresence_Bath1"] will give you the Item’s state.

  3. You probably want to use null instead of undefined and in either case you need to use ===, not ==.

2 Likes