Announcement

Collapse
No announcement yet.

Jim Doolittle's Moition sensor script Question about Timing

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Jim Doolittle's Moition sensor script Question about Timing

    Jim,

    Let me start by thanking you for your scripts they are extremely useful and powerful.

    I am just digging in to understanding how they work and it there is something I am not understanding. When you are calculating the amount of time since motion was detected it appears you are actually looking at the last action from the detector (time), which in most cases will be the "OFF" signal. Depending on the delay for a given sensor the time since motion was detected is off by at least a minute. Am I right about this?

    I know this seems a picky point, but I am trying to automate the bathroom lights and rather than using the off signal I was using your scripts to dim then turn off light and every time I ran it it seemed to be delayed a minute longer than I set it for.

    What are your thoughts?

    ChimpWare
    "Software so easy to use a monkey could do it..."

    #2
    This is a rather lengthy response but I think it may help quite a few of you. If anyone sees some error in my explanation, let me know.

    There are several sources that could cause timing issues. The two most obvious sources are the timing of the motion sensors OFF command and the timing of the recurring motion sensor event.

    I suppose I never mentioned in the instructions for the motion sensor script package (I will in the future) that I would recommend leaving the delay after which the motion sensor sends an OFF to the default of 1 minute (it can be set to 256 minutes maximum). Any longer, and you will definitely increase timing offsets. However, there are occasions that you do want to increase this time.

    My infamous "Laundry Room" motion sensors are set at 8 minutes since I control the Laundry Room lights directly with them and only monitor the results with the motion sensor scripts. I found 8 minutes to be a good number that would prevent "false" OFFs if someone (my wife) is standing still long enough while doing laundry. If someone can recommend a X10 "occupancy" sensor that senses the presence of a person but does not require movement, let me know.

    So, the motion sensor itself can induce up to a 1 minute timing offset at its lowest setting.

    The other source of timing offsets is the recurring motion sensor script. The default setting for the scripts is 2 minutes which is what I use. I didn't need "one minute accuracy" and I thought I would reduce the load on HomeSeer.

    The bottom line is that you could have up to a three minute timing offset with the "default" settings. If you set the recurring script to a 1 minute recurrence, you could drop this to a 2 minute maximum timing offset. On a good note, you would not see this long of an offset on average.

    To minimize the offset to a 1 minute maximum, I would either create an event within HomeSeer that specifically works off of the motion sensor's OFF command or, if you want to keep it within the motion scripts, put the necessary code in the NoMotionAction procedure within my_motion_custom.txt.

    If you want to make stuff happen x number of minutes after an OFF command, I would either adjust the motion sensors delayed OFF setting and/or work with delayed events. Remember, if you work with the motion sensor's delayed action procedures, you will be at the mercy of the timing of the recurring script.

    Jim Doolittle
    Jim Doolittle

    My Twitter
    My Hardware & Software

    Comment


      #3
      Jim,

      Sorry for the additional questions, but doesn't any motion detector event, by default, trigger the my_motionsensor.txt script?

      In that case couldn't we improve on the time resolution of the system by actually recording the last ON each sensor sent and using that for comparison in terms of last motion detected?

      This could potentially improve the resolution of the motion sensors to 10-15 seconds from 1 minute or more. I know that this would likely trigger some false alarms, but would allow us to use this better resolution if good, reliable signals were available.

      What do you think?

      I am going to take a shot at modifying the script to do this.

      ChimpWare
      "Software so easy to use a monkey could do it..."

      Comment


        #4
        Oops. I wrote the previous message forgetting about some of the things that happen when the motion sensor sends an OFF command.

        When the motion sensor sends an OFF command and you use the NoMotionAction procedure, time offsets are almost exclusively due to the OFF setting of the motion sensor itself. Other sources of the time offset are HomeSeer/CPU processing and hardware limitations.

        If you rely on the NoMotionDelayedAction procedure, then time offsets are due to the OFF setting of the motion sensor and the recurring event timing. It is the recurring event that is what is used to check how long a motion sensor has been OFF.

        Now, it is possible to improve the scripts by relying on the time since the last ON command was detected and avoiding issues with when motion sensors send OFF commands. Plus I also determine the no motion time to the nearest minute which could be improved by doing the calculation to the nearest second. The scripts started life as a way of knowing how long motion had not been detected and then I started adding code to do other things. I can see that it would be good to improve response time.

        Earlier I had mentioned the possibility of creating delayed events that would better handle timing. I think this is the easiest way to go without extensively modifying the scripts. I would add code within the MotionAction procedure within the my_motion_custom.txt script. The code would look similar to the following pseudo-code:

        where the delayed event is set to delete upon execution. This scenario should create very minimal timing delays. Again, I think that this would be better than changing the rest of the code to obtain sub-minute timing.

        If you do incorporate this idea please share and I will add it to the script package. I like to keep sections of code (commented out) within the my_motion_procs.txt script so that others can use as an example of how to do their own customization. Come to think of it, this approach could eliminate the need for the Ctrl variable

        Jim Doolittle
        Jim Doolittle

        My Twitter
        My Hardware & Software

        Comment


          #5
          Well, I decided to update the motion scripts rather than pull CAT5 through my attic [img]/infopop/emoticons/icon_smile.gif[/img]. My solution to timing issues is to use delayed events. This approach renders the NoMotionDelayedAction function within my_motion_custom.txt obsolete. All references to MotionControl become obsolete as well. Instead, the code from NoMotionDelayedAction is put into the MotionAction function. Below is a before and after comparison. I am testing this now and would welcome comments before supplying a new version of the script package.

          Timing delays are minimized. I chose "No Motion" as the Event Group so that you can easily see pending events. If motion is detected before event is executed it is simply deleted and recreated.

          UPDATE: This works great! Thanks ChimpWare. I only hope that it is not too difficult for others to upgrade.

          Jim Doolittle

          [This message was edited by Jim Doolittle on Saturday, 30 March 2002 at 05:08 PM.]
          Jim Doolittle

          My Twitter
          My Hardware & Software

          Comment


            #6
            I use your motion scripts extensively, so I'm looking forward to testing this new "feature". In the meantime, I have a functionality question that I just can't seem to get my brain around.

            I have a SwitchLinc wall switch to control my overhead flourescents in the garage and I use a motion detector, with your scripts, to turn on the the lights when someone enters, turn them off if no motion is detected for 30 minutes, and close the garage door if no motion for 60 minutes.

            I've noticed that if I turn off the light manually (force of habit!), then return to the garage within the next 30 minutes, the light doesn't come on automatically. Of course, it shouldn't because it's supposed to already be on. I know I can test for the status of the Switchlinc, but I can't seem to figure out the rest of the logic to make this work.

            Pulling CAT5 hunh? I started that project last winter, and I still have a 500' roll of cable and a cable puller stuck in a top-plate hole in the attic. [img]/infopop/emoticons/icon_biggrin.gif[/img] Both are free to anyone who can remove them! [img]/infopop/emoticons/icon_razz.gif[/img]

            Regards,

            Comment


              #7
              Latest version of motion scripts are available here.

              This incorporates delayed trigger events to handle some functions x number of minutes since the motion detector last saw motion. Will be much better with respect to timing than the original NoMotionDelayedAction function.

              Jim Doolittle
              Jim Doolittle

              My Twitter
              My Hardware & Software

              Comment


                #8
                Mechanic,

                I do not have 2-way devices so I am not sure how often one should poll to find out the status. But, I think once you have the status and HomeSeer knows it, the motion scripts should handle the rest.

                I think you could use the latest version of my motion scripts to do this easily. In the new version of my_motion_custom.txt (actually you could have done this in previous versions), you can create a delayed trigger event in the MotionAction function that runs a script that polls your garage fluorescents (updating the status) just before the 30 minutes are up. If motion is detected again before the time is up, the previous trigger is deleted and a new one is created. Email me if you need help setting this up.

                Jim Doolittle
                Jim Doolittle

                My Twitter
                My Hardware & Software

                Comment


                  #9
                  for the offer to assist. I think I found the problem.

                  I was taking great care to document my setup in an e-mail to you when I realized that I had never reset the motion sensor NoMotion delay after I installed your scripts. The motion sensor itself was set for a NoMotion delay of 32 minutes.

                  My guess is that this means the motion sensor never sends "Motion Detected" until the delay timer expires. This causes the lights to remain off (when manually turned off) until motion is detected AFTER the 32 minutes have expired. [img]/infopop/emoticons/icon_razz.gif[/img]

                  The solution, still in testing, is to set the motion detector to a 1-minute delay and see what happens. Thanks again.

                  Comment


                    #10
                    Jim,

                    Finally had a chance to look at you modifications and it looks good. The one issue is that your applications are around long time delays. The issue I have been trying to solve is the infamous "Nightime Wife Uses Bathroom" Scenario.

                    I believe based on some minor modifcations to your scripts I have it solved. First I needed to move the Call to NoMotion outside of the check for NormalElapsedTime to remove delay in calling event. Next I used Delayed Events rather than NewTimeEvent. The only problem is that you need to set up the events to be called elsewhere (I have manual events set up). Using this method I am able to reduce the time resolution to about 20 seconds (limits on re-triggger of HawkEye). What I do is have 3 events:

                    1) Lights Dim to 100%
                    2) Lights Dim to 50% delayed by 1 minute (Warning Dim)
                    3) Lights Dim to 0% delayed by 2 minutes.

                    This seems to work very well and eliminates virtual devices required for non-script based implementation.

                    The only issue is that you have continuous calls to the Light Dim to 100% script everytime motion is detected, but this does not seem to be a problem.

                    If anyone is interested in this solution I can post the minor modifications.

                    ChimpWare
                    "Software so easy to use a monkey could do it..."

                    Comment


                      #11
                      Chimpware,

                      Once you get your system set up, email me what you changed. As long as it doesn't break something else, I can make it a standard revision.

                      I do not have short time application requirements because I do not trust Hawkeye/EagleEyes to let me know when someone is not in a room. Last time I did, the lights went out while I was reading a book and I didn't have an X10 remote handy to turn them back on. Had to result to the old-fashioned way of tripping over the kids toys and toggling the light manually [img]/infopop/emoticons/icon_smile.gif[/img]. So, my stratgey is that if someone hasn't moved in over 30 minutes, then they are either asleep, not in the room or ready to push up daisies.

                      Jim Doolittle
                      Jim Doolittle

                      My Twitter
                      My Hardware & Software

                      Comment

                      Working...
                      X