scutterry
Posts: 4
Joined: Sun Oct 26, 2014 12:46 am

How to control a light with physical switch and pi

Sun Oct 26, 2014 1:20 am

My room has a light with a physical switch. now I want to add a relay to control this light with my phone through wifi to via pi.
Is there any idea to do this, the physical switch cooperate with the pi, and the pi can detect the light state.
The light state to display on my phone's app.
Does my idea work? And how?

software:
as i am a software engineer. I use web.py as a server for providing some functions to call GPIO, my app calls these functions with HTTP request.

hardware:
i am a green in the part of hardware. i don't know how.

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: How to control a light with physical switch and pi

Sun Oct 26, 2014 7:56 am

You need to replace the switch with a relay. But, to do that you need to be qualified to work with 110V/230V (depending on your local standard).

Remember that MAINS VOLTAGES CAN KILL and if you don't know what you're doing you shouldn't play.

Start by working at low voltages, get your RPi to switch a relay that switches a 12V (or lower) lamp connected to a battery.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: How to control a light with physical switch and pi

Sun Oct 26, 2014 8:01 am

Let someone else worry about the hazards of mains electricity. Use a separate, free-standing light and control it with one of these kits - https://energenie4u.co.uk/index.php/cat ... NER002-2PI

toxibunny
Posts: 1382
Joined: Thu Aug 18, 2011 9:21 pm

Re: How to control a light with physical switch and pi

Sun Oct 26, 2014 9:30 am

a robotic finger.
note: I may or may not know what I'm talking about...

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: How to control a light with physical switch and pi

Sun Oct 26, 2014 11:41 am

toxibunny wrote:a robotic finger.
You mean something like https://www.youtube.com/watch?v=Z86V_ICUCD4?

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: How to control a light with physical switch and pi

Sun Oct 26, 2014 11:49 am

i am a green in the part of hardware. i don't know how
Don't start with mains - start with something that won't kill you. Hamilton started with go-karts before trying F1

For the theory bit (and it will work with low voltage, low current stuff, like LEDs) ...
A light-switch is just a moving bit of metal - when it's off, there's an air-gap; switch it on, the gap closes.
A relay does the same, except there's two air-gaps. The moving metal closes one gap and opens the other.
There's another sort of light-switch, a two-way one, which works like the relay - and quite often what's been installed is one of those, with the second part left unconnected. You may be lucky!

With an ordinary one-way switch, you could add a relay, but where you connect it depends on what you want to do.
If you put the relay in series, then you can switch the light off when it's on but not on when it's off - logical AND
If you put the relay in parallel, then you can switch the light on when it's off but not off when it's on - logical OR
If you want to do both - XOR - you need a two-way switch.

Now you need your Pi to detect whether the light is on or off. That's a whole new ball-game! Voltage sensing? what if the lamp is bust? Current-sensing? Light sensing?

Draw it out on paper, then try it with the Pi and LEDs then get your friendly neighbourhood electrician involved ...


Love that machine, DirkS! :D

User avatar
aTao
Posts: 1093
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: How to control a light with physical switch and pi

Sun Oct 26, 2014 11:57 am

scutterry wrote:My room has a light with a physical switch. now I want to add a relay to control this light with my phone through wifi to via pi.
Is there any idea to do this, the physical switch cooperate with the pi, and the pi can detect the light state.
The light state to display on my phone's app.
Does my idea work? And how?

software:
as i am a software engineer. I use web.py as a server for providing some functions to call GPIO, my app calls these functions with HTTP request.

hardware:
i am a green in the part of hardware. i don't know how.
Interesting, if this were software objects communication you would (should) see where you are confused, but as its real nuts and bolts it does not seem to gell.

Think, what happens if the switch says off and the phone says on? what should happen?

How do you monitor the switch?, by the lamp being on? what if the phone says off and that means the lamp is off, your phone will never receive "on" from the switch.

So, heres a solution:
Forget the wall switch (or leave it turned on) get a remote controlled light fitting and get control from your phone (might not need the RPi for this).
Then work out either how to get the RPi to switch the remote controlled light and talk to the phone
or get the RPi to send an isntruction to the phone to turn on the light then the phone does the work.
You end up with either the phone or the RPi being the master and it "knows" what state the light is in and does not need to monitor it.
This way your only connection to mains is via ready made equipment.

You can then investigate a using a non mains switch (or have an electrician remove the mains wiring from the existing switch) to send an on/off request to the RPi. But do rememebr to work out what happens when 2 control inputs differ.
>)))'><'(((<

scutterry
Posts: 4
Joined: Sun Oct 26, 2014 12:46 am

Re: How to control a light with physical switch and pi

Mon Oct 27, 2014 6:02 am

Thanks all, I'll try some leds first.

Return to “Automation, sensing and robotics”