Help in modifying the motion lights example

I want to use the motion light example if someone (usually me) is in the basement during the weekend. I have setup a binary_switch (PIR Sensor) that is working and have it controlled with an appdaemon app based on the motion_lights example.

My question is in addition to just checking the motion sensor I would like to build in some logic around keeping the switch on for some amount of time. Checking something like every 15 mins to see if motion has been detected in that time and I am thinking reset a timer?

I see a line in the code: self.cancel_timer(self.handle), but I am not sure what that does exactly.

1 Like

you can set the delay in the configfile to 900 (is 60*15)

the lights will go out only after 15 minutes if there was no motion detected.

so you dont even have to modify the app for that.

that would work. @aimc what is the cancel_timer line for in that example?

It’s to handle retriggers - if motion is detected while the timer is ticking. It will be cancelled and the timer will be restarted for the full amount of time.

@smolz – This sounds exactly like what I’m wanting to do for my home office LIFX bulbs. If you get this working can you please share the config? Thank you!

@brianjking do you have appdaemon installed?
and do you have the motion light app (from the examples) copied to your app dir?
then follow the instructions that are at the top off the app and use a delay from 900

@ReneTode – No, I do not yet have AppDaemon installed. I just re-did my install about two weeks ago to start fresh and plan to add my Z-Wave USB Z-Stick in the next day or two and the motion sensor as I never had these on my prior (initial) setup with Home Assistant.

Here’s my repo.

Thanks!

what @smolz is talking about is an appdaemon app.
you need to install appdaemon and use the app from the examples.

That is what worked for me. The only thing I added was a constrain_days = sat, sun in my appdaemon.cfg

Yup, start here: https://home-assistant.io/ecosystem/appdaemon/installation/

@ReneTode @smolz

I’m using the Fabric All-in-One Installer. Should I install into the same virtualenv that Home Assistant installs into if I install using pip3?

It’s up to you - I am just using the global environment for my install.

Yeah, it doesnt really matter. I know some are even running everything in separate docker containers

i dont have any virtual env and no docker.
my RPI is home assistant dedicated, so i really dont see any advantage from virtualenv.

I have appdaemon and HA in the same virtualenv, but now I know how it works, I would create a separate virtualenv for each.

I can see there could be a situation where I would do not want to upgrade one or the other, which means they could be dependent on different versions of libraries.