How Too Peripherals Python Tutorials

Remote lights switch

Post Reply
raspberrypi / howtoo     Views: 263Prev .. Next
Remote lights switchPosted: Sunday, February 10, 2019 [21:59:28] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 195
While remote lights switches available in many shapes and forms here is another solution.
Using RPi Zero W to control micro servo to flip the switch physically.

Still working on a part that will report the state of the switch.
Switch used in this project is $2 Leviton decora model S11-5601-2IS available in Home Depot.There's no place like ~
Servo plate for this projectPosted: Sunday, February 10, 2019 [22:06:05] - 2
rootPosted by:rootMember Since:
June 16 2010
Posts: 195
Servo plate adapter (red part) STL file:'s no place like ~
testing actual switchPosted: Tuesday, February 12, 2019 [00:31:32] - 3
rootPosted by:rootMember Since:
June 16 2010
Posts: 195
Actually testing switch with servo and manually.

and it worksThere's no place like ~
RE: Remote lights switchPosted: Friday, March 15, 2019 [13:50:05] - 4
rootPosted by:rootMember Since:
June 16 2010
Posts: 195
Version 2 of the switch with with position reporting VIA MQTT and registering it in Node-Red Dashboard.

Video do not show indicator color change, so we added screen recording on laptop, that is not exactly synchronized but it gives an idea.
Did not work-out switch change on a dashboard, but indication works.


Node-Red schematics

To be able to pack switch with indicator on one line switch uses 4x1 size and indicator 2x1 (see image below).

based on a input we trigger on or off SSH connection.

Switch triggers an passwordless SSH connection to RPi to actuate servo.

Switch position indicator starts with MQTT in node

Then it passes data to a function node, where we issue indicator color based on the input with :
View Codemsg.color = (msg.payload === "On")?"lime":"WhiteSmoke";
return msg;

then template node creates custom LED indicator based on msg.color

View Code<style>
#circle1 {
stroke: none;
fill: {{msg.color}};

<circle id="circle1" cx="10" cy="20" r="10"/>

MQTT client to report switch position:
View Code
import paho.mqtt.client as mqttClient
import RPi.GPIO as GPIO
import time
bpin = 26

def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to broker")
global Connected #Use global variable
Connected = True #Signal connection
print("Connection failed")

Connected = False
client = mqttClient.Client("switches_main")
client.connect(broker_address, port=port)
while Connected != True: #Wait for connection


GPIO.setup(bpin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
inputValue = GPIO.input(bpin)
if (inputValue == False):
value = "On"
else :
value = "Off"

except KeyboardInterrupt:

This is a test code to verify the project.There's no place like ~
Base for Raspberry Pi with Power supplyPosted: Monday, April 1, 2019 [14:55:20] - 5
rootPosted by:rootMember Since:
June 16 2010
Posts: 195
Just finished case for Raspberry Pi Zero and power supply.
Power supply 5V 3A purchased on eBay for $3 delivered.

it was removed from the case and power wires were soldered to fit this application.

Also a custom header made for easy wiring:

and putting it all together in a case for Raspberry Pi Zero and power supply. Case was 3D printed.

Next is checking all wiring and wall mounting.There's no place like ~
Bench testing complete systemPosted: Friday, April 5, 2019 [23:37:04] - 6
rootPosted by:rootMember Since:
June 16 2010
Posts: 195
All assembly tested on a bench to make sure all switches work and power supply works as designed.

Next, wall installation..There's no place like ~
Lights switches installedPosted: Monday, April 8, 2019 [16:11:04] - 7
rootPosted by:rootMember Since:
June 16 2010
Posts: 195
Light switches tested, installed and functioning. Wire connection between switches and Raspberry Pi Zero routed in-wall.

Installation stages:

RPi is placed under the lower shelf and not immediately visible. It is powered by BackUPS, so it won't lose the power in case of the power outage.

Switch box wiring had to be completely re-done to free-up some space for the enlarged switches.There's no place like ~
raspberrypi / howtooPrev .. Next
Post Reply
Home - Raspberrypi: How Too Peripherals Python Tutorials