DavidW522
Posts: 9
Joined: Sun Aug 12, 2012 1:34 pm

Pi switch based on a schedule

Sat Aug 23, 2014 11:35 pm

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

sprinkmeier
Posts: 410
Joined: Mon Feb 04, 2013 10:48 am
Contact: Website

Re: Pi switch based on a schedule

Sun Aug 24, 2014 12:47 am

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?

DavidW522
Posts: 9
Joined: Sun Aug 12, 2012 1:34 pm

Re: Pi switch based on a schedule

Sun Aug 24, 2014 3:31 am

Yea I have a B, will look into that thanks.

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Pi switch based on a schedule

Sun Aug 24, 2014 6:20 am

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" :)

Return to “Beginners”