How Too Peripherals Python Tutorials

Remote lights switch

Post Reply
raspberrypi / howtoo     Views: 446Prev .. Next
Remote lights switchPosted: Sunday, February 10, 2019 [21:59:28] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 209
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.

Post 49853968 Image 1

Post 49853968 Image 2

Post 49853968 Image 3

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: 209
Servo plate adapter (red part) STL file:
www.codemacs.com/download..There's no place like ~
testing actual switchPosted: Tuesday, February 12, 2019 [00:31:32] - 3
rootPosted by:rootMember Since:
June 16 2010
Posts: 209
Actually testing switch with servo and manually.

Post 49949492 Image 1

Post 49949492 Image 2

Post 49949492 Image 3

Post 49949492 Image 4

Post 49949492 Image 5

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: 209
Version 2 of the switch with with position reporting VIA MQTT and registering it in Node-Red Dashboard.


https://www.youtube.com/watch?v=e6ZgRNYB4u4


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.

Post 52672205 Image 1

Post 52672205 Image 2

Post 52672205 Image 3

Post 52672205 Image 4

Post 52672205 Image 5

Programming:

Post 52672205 Image 6

Node-Red schematics

Post 52672205 Image 7

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

Post 52672205 Image 8
based on a input we trigger on or off SSH connection.
Post 52672205 Image 9
Switch triggers an passwordless SSH connection to RPi to actuate servo.

Switch position indicator starts with MQTT in node

Post 52672205 Image 10

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

Post 52672205 Image 11
Template:
View Code<style>
#circle1 {
stroke: none;
fill: {{msg.color}};
}
</style>

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


MQTT client to report switch position:
View Code
#!/usr/bin/python
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
else:
print("Connection failed")

Connected = False
broker_address="RPI_IP_ADDRESS"
port=1883
client = mqttClient.Client("switches_main")
client.on_connect=on_connect
client.connect(broker_address, port=port)
client.loop_start()
while Connected != True: #Wait for connection
time.sleep(0.1)

GPIO.setmode(GPIO.BCM)

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

try:
while True:
inputValue = GPIO.input(bpin)
if (inputValue == False):
print(bpin)
value = "On"
client.publish(str(bpin),value)
else :
value = "Off"
client.publish(str(bpin),value)
time.sleep(3)

except KeyboardInterrupt:
GPIO.cleanup()
client.disconnect()
client.loop_stop()



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: 209
Just finished case for Raspberry Pi Zero and power supply.
Power supply 5V 3A purchased on eBay for $3 delivered.

Post 54144920 Image 1

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

Post 54144920 Image 2

Also a custom header made for easy wiring:

Post 54144920 Image 3

Post 54144920 Image 4

Post 54144920 Image 5

Post 54144920 Image 6

Post 54144920 Image 7

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

Post 54144920 Image 8

Post 54144920 Image 9

Post 54144920 Image 10

Post 54144920 Image 11

Post 54144920 Image 12

Post 54144920 Image 13

Post 54144920 Image 14

Post 54144920 Image 15

Post 54144920 Image 16

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: 209
All assembly tested on a bench to make sure all switches work and power supply works as designed.


https://www.youtube.com/watch?v=eRbfuDB5R2I



Post 54521824 Image 1

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: 209
Light switches tested, installed and functioning. Wire connection between switches and Raspberry Pi Zero routed in-wall.


https://www.youtube.com/watch?v=k77S33ddP-I


Installation stages:

Post 54754264 Image 1

Post 54754264 Image 2

Post 54754264 Image 3

Post 54754264 Image 4

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.

Post 54754264 Image 5

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