Motion turns on a switch (for alert), then won't do it again for x hours?

I’m seeking an app that turns on a switch for a minute when it senses motion, but will “disable itself” for a number of minutes/hours afterwards.

The switch is to a spoken audio alarm, and I don’t want it talking that frequently.

Any pointers?

You can do this with a virtual switch that “stands in” for the real switch so that an app can apply the logic you want. Motion would turn on the virtual switch. If it’s the “first time”, it turns on the real switch for a minute, or whatever you want. Then it runs runIn for the time you want it disabled, setting a state variable for “disable” which gets cleared later. Pretty straight forward. The app would have you specify the real switch, the virtual switch, and the disable period. The motion portion of this would be in Lights & Switches, and does the turn on and the turn off after x minutes. Essentially, this little app simply disables the motion as an activator of the real switch for some specified period. PM me if you need help…

There’s probably a lot of ways to do this. Seems like another way would be to:

Subscribe to motion initially.
In the motion handler, switch on, unsubscribe (to start a period of time where motion is ignored), use runIn to schedule and handler to turn it off in one minute, schedule another handler to, after some number of minutes/hours, subscribe again to motion.

I had not thought of subscribing and unsubscribing in the code but I saw someone do that ‘accidentally’ so it made me think this might a good solution for your problem.

I’ve got code for this but it’s not working in the simulator. I think the problem might be the simulator, though. If you are interested in testing in the real world, I can post the code for you.

That’s a nice approach, simpler than using a virtual switch! I’ve had requests for variations on this theme. I have a house guest who wants to disable motion whenever they want to (to keep light from waking babies). Again, I used a virtual dimmer. If the guest simply turns off the light while it is on, that disables motion. It gets re-enabled when the lights get turned back on, and allowed to turn off from the motion turn off.

Thanks for the comments. Regarding the variation,seems like a useful application. I wonder if there is a way to subscribe to the manual turning on and off of a dimmer switch. I haven’t really messed with this aspect. If you could, seems like the app would be pretty straighforward.

Anyway, as mention, I have code that addresses the OP’s request but it doesn’t work in the simulator. It’s super simple and I don’t see why it’s not working. Could be an issue with the simulator itself. Seems like I’ve run into that before. I won’t have much time through the holiday’s to sort this out so I’m posting the code I have in case anyone else wants a go at it. It might just work if loaded and run on an actual system. Maybe I’ve just messed up some syntax or type casting (no errors, however). Happy holidays!

UPDATE! Code works now. I searched and found discussion of a lower limit for the time used in the runIn method. I revised the code to make the smallest on time 1 minute. This resolved the issue. I had been testing with 10 seconds. Would be nice, @Jim, if this were documented here.

That’s so great! Seemed like it was working, then I wanted to tweak it a bit and play, and realized that in the tutorials and video it’s showing a nifty “Simulator” but I’m not seeing that. Anyone know how to turn that on?

In the IDE, pull up the SmartApp then click on Set Location on the right. That will bring up the simulator.

Thank you all! Appreciating this community.

Simulator is pretty amazing when it works. I have to reload the page every time I save new code.

Now if I can get past the pesky syntax errors. Looking forward to their IFTTT-like interface.