- #16 Best Toners ever 2020-08-08
- #15 Eletronics Stuff 2020-08-05
- #14 Create SSH Reverse Tunnel in rapid way, reliable and programmaticaly 2019-08-08
- #13 Automate, silence smartphone at work 2019-07-07
- #12 Control your lights without sonoff or other things 2019-06-06
- #11 Google Home and IFTTT, turn on the stove 2019-05-05
- #10 Google Home Hack, send voice programmaticaly with Python 2019-04-04
- #9 Google Home Hack, hidden REST API 2019-03-03
- #8 1.05 A quick WebApp for your thermostat 2019-02-02
- #7 Root for my Huawei P8 Lite 2017 PRA-LX1 2019-01-01
- #6 1.04 Relais board and Thermostat script 2018-12-12
- #5 1.03 Reading the DS18B20, prepare some libraries 2018-11-11
- #4 1.02 Use temperature sensor DS18B20 2018-10-10
- #2 1.01 Initially setup your RaspberryPI 2018-09-25
- #3 1.00 The Silvano idea – the beginning 2018-09-23
- #1 Welcome 2018-09-21
Control your lights without sonoff or other things
Months ago I bought a new Raspberry…. and I put this object on rear the television in the living room. This zone is perfect because is near the electric box where I have relay for controlling 3 light… living room, kitchen and entrance. Now in this post, I want to explain how using a raspberry for controlling 3 light without “smart things” or sonoff. My system is complete integrated with my standard electrical system…. and following my motto “not hobby but real stuff” i made the system reliable.
The first thing, obviously is connect the raspberry to my lan with RJ45 (more reliable that wifi) and initialize this likehttp://www.gioexperience.com/initially-setup-your-raspberrypi/index.html\" title=\"\" style=\"box-sizing: border-box; border: 0px; font-variant: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-style: inherit; font-weight: inherit; outline: 0px; vertical-align: baseline; color: rgb(38, 38, 38);\"> this post . Now setup a static ip. I put 192.168.0.2 (my first raspberry is 192.168.0.1). Now, before explain the details, we can view a small review of how the lights are controlled by a relay in a standard electrical system.
Electrotechnical lesson
In this schema we can view a 220V system for control a single light from 4 points. The buttons is real and when i “click” a button connect the F (phase) to the pin number 4 of the relay. The solenoid-valve in the relay (3pin and 4pin) gets excited and connect the pin number 5 (phase) to the pin number 2 (violet cable). The light turn ON and rest ON. If I click another time a button I put phase on the 4-pin and disconnect the 5-pin to the 2-pin…. the light turn OFF.
This is the standard system and it works perfectly!
I used this particular relay (Finder 26.02) because it’s have 2 contact…. Only one contact (between pin 2 and 5) is for normal use… for use standard in this schema. I use the Finder 26.02 because it have also another contact between pin1 and pin6. I will use this contact for monitoring light with my Raspberry 😉
My additions
In my idea I can use a little 5V-Relay controlled by my raspberry for simulating a real-button. I can control the state of light using the pin1-pin6 contact… I put 3,3V to the pin1… and I monitor if the pin6 is at 0V (off) or 3,3V (ON).
I hope everything is much clearer with the scheme. I connect the mini relay5V to my raspberry and control it with a software. It’s clear that for change the light status is sufficient simulate a click… in other words excite the relay for 100ms and after de-excite. I can monitor the state of the light with the GPIO4 in this example…. if the GPIO4 have 0V… the light is off becase the contact pin1-pin6 is disconnected. If the GPIO2 read 3,3V the status of light is ON.
It’s all ok? Now I can write some code.
First of all, a PULSE script in C
First of all, for convenience i wrote a simple script that simulate a click. I called “gpio_pulse” and i write it in C language.
#include <stdio.h> #include <string.h> #include <errno.h> #include <stdlib.h> #include <wiringPi.h> #include <unistd.h> // compile // sudo gcc gpio_pulse.c -o /usr/local/bin/gpio_pulse -lwiringPi //******************************************************** //** launch with argument the bcm/gpio pin to monitor. //** The program pulse the pin from LOW, after HIGH for tot milliseconds, //** and after LOW //** //** Using >> gpio_pulse 5 //******************************************************** int pin=0; int main (int argc,char **argv) { if( argc==1 ) { fprintf (stderr, \"Error: pass the pin in GPIO/BMC\\n\") ; return 1 ; } pin=atoi(argv[1]); if (wiringPiSetupGpio() < 0) { fprintf (stderr, \"Errore: Unable to GPIO: %s\\n\", strerror (errno)) ; return 1 ; } pinMode (pin,OUTPUT); delay (10) ; digitalWrite(pin,0); delay (100) ; digitalWrite(pin,1); return 0; }
This script accepts as argument the PIN where launch the “click” simulation. Compile it, create the executable gpio_script and copy in the /usr/bin path
Now some setup
I suggest some things… In the /etc/rc.local write
gpio -g write 17 1 #this pin control the 5 relay... that work active-low gpio -g mode 17 out gpio -g mode 4 in gpio -g mode 4 down #this is the pulldown resistor
My 5v-relay board is active low…. this initial setup ensure to you that when your raspberryPi is rebooting your relay not excite. In other case every time you reboot your raspberry the 5v-relay do “click”…. very fastidious… and the light turn on and off, bleah.
As you can see, I use pin 17 (gpio) for write the 5v-relay, and pin 4 for reading the state of light.
Finally….
Now from your prompt you can write this for change state of light:
sudo gpio_pulse 17
and this for read the state of light…. it returns 0 for OFF and 1 for ON
sudo gpio -g read 4
Now, it’s clear that you can control your light with Google Home making a simple web API like i wrote http://www.gioexperience.com/1-05-a-quick-webapp-for-your-thermostat/index.html\" title=\"\" style=\"box-sizing: border-box; border: 0px; font-variant: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-style: inherit; font-weight: inherit; outline: 0px; vertical-align: baseline; color: rgb(38, 38, 38);\">in this post, and after use http://www.gioexperience.com/google-home-and-ifttt-turn-on-the-stove/index.html\" title=\"\" style=\"box-sizing: border-box; border: 0px; font-variant: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-style: inherit; font-weight: inherit; outline: 0px; vertical-align: baseline; color: rgb(38, 38, 38);\">IFTTT like in this post
My work
This is a photo of my “rear Television zone”. There is a raspberry PI with a relay board that control my 3 lights.
I connect also HDMI output for debugging reason. In this photo we can see that there is another things…. a infrared led! There is arguments for another post in future….