Page 1 of 1

Pi switch based on a schedule

Posted: Sat Aug 23, 2014 11:35 pm
by DavidW522
So I was wanting to setup my pi to turn my ringer off or on with my lan line phone based on a sched I put into it.

So I work from home and I always forget to turn my ringer back on when Im off so often will miss calls. I would like to setup the PI to only have the ringer on the phone on during a set time frame so I don't get calls while working or sleeping.

I'm sure I could connecting the phone ringer wires to some simple relay switch controlled by the PI but was not able to find anyone that's done something like this with my google searches yet.


Ideas? Thanks in advance

Re: Pi switch based on a schedule

Posted: Sun Aug 24, 2014 12:47 am
by sprinkmeier
If you've got a RasPi A or B then something like this: http://www.piface.org.uk/products/piface_digital/ should allow you to easily control relays from the Pi
If you have a B+ I'd recommend looking for a 'hat'.

Kind of a sledgehammer to crack a nut, but hey, why not?

Re: Pi switch based on a schedule

Posted: Sun Aug 24, 2014 3:31 am
by DavidW522
Yea I have a B, will look into that thanks.

Re: Pi switch based on a schedule

Posted: Sun Aug 24, 2014 6:20 am
by rpdom
For scheduling on Linux, look at cron and crontab. I'd probably set up three programs - just simple Bash scripts are enough. one would be something like "ring_off" which turns the relay off, one "ring_on", you can guess what that does, and the other would be "ring_init" which sets up the relay and gpio and either turns it on or off depending on when it was run.

Then in your crontab, something like:

Code: Select all

@reboot /home/pi/cron/ring_init
30 09 * * 1-5 /home/pi/cron/ring_on
00 18 * * 1-5 /home/pi/cron/ring_off
Which would set up everything when the Pi is started, turn the ringer on at 9:30am Monday to Friday, and turn it off at 6pm Monday to Friday. You can add other times with more lines.

Or you could have one script that runs every minute or five minutes and uses a configuration file to set on/off state. Depends how complex/flexible you want it.

I tend to start off with "simple" and then get to "horribly complex" before completely re-writing from scratch and ending up with "flexible and easy to manage" :)