Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lights off #34

Open
satlover1 opened this issue Jan 20, 2024 · 2 comments
Open

lights off #34

satlover1 opened this issue Jan 20, 2024 · 2 comments

Comments

@satlover1
Copy link

i use cron on boot and for shutdown.
i use the cron command 30 23 * * * /sbin/shutdown -h now,but when the pi shutdown to red light the lights of christmas tree freezes,they did not turn off,can you please advise me a simple cron command to auto turn them off ?

@bennuttall
Copy link
Member

The shutdown command means you lose control of the Python process and the lights stay on. You're probably better off managing the shutdown from Python, or a minute before cron shutdown, turn the lights off in Python.

You can use gpiozero's TimeOfDay to turn the lights off:

https://gpiozero.readthedocs.io/en/stable/api_internal.html#timeofday

And if you want to manage shutdown too, you could do this after turning the lights off:

https://gpiozero.readthedocs.io/en/stable/recipes.html#shutdown-button

@stroggprog
Copy link

I added the following code in the interrupt section:

except KeyboardInterrupt:
    tree.off()
    tree.close()

In my crontab I added this line:

0 0 6 1 * /usr/bin/killall -s SIGINT randomsparkles.py

Obviously change the times to suit yourself and whatever script you are running. My cron turns the tree on on Dec 1st and off on Jan 6th, with a bash script checking the date on reboot in case the machine reboots during the 'on' period. I uploaded the scripts here: https://github.com/stroggprog/xmas-tree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants