Tinkster Logo
advancedSmart Home & IoT

Voice control of lights through Alexa

Author
Savva
Tashkent, UZ
1 day
--
0
Cover
Friends, spring has arrived, which means it's time to hack radio-controlled sockets and add Alexa voice control to them. :) As you know, I don't use wireless connections at home, so WiFi sockets are automatically out of the question. We'll use 433.92MHz radio-controlled sockets, scan the codes from their remote, and then connect it all to Alexa. At this stage, you should already have the operating system installed Raspbian Buster Lite and Alexa compiled from AVS SDK. How to do this can be read in the guide "Voice Assistant Alexa on Raspberry Pi".

Steps

1

Remote control codes scanning

Receiver connection diagram to RPi
433MHz receiver. Model RWS-371F V1.00
Connect the receiver to the RPi according to the diagram:
Turn on the RPi and access it via SSH:
1
ssh pi@192.168.0.XXX
Next, install the program rpi-rf. In the terminal, enter:
1
sudo pip3 install rpi-rf
By default, the program uses GPIO17 for the transmitter and GPIO27 for the receiver.
Launch the program to receive remote control codes:
1
rpi-rf_receive
It will say:
1
[INFO] rpi-rf_receive: Listening for codes on GPIO 27
Point the socket remote at the receiver and press the buttons On и Off for each socket, recording their codes. In the terminal, you should see something like:
1
[INFO] receive: 5330691 [pulselength 174, protocol 1]
Copy this data for each socket and save it to a file.
That's it, the scanning of socket codes is now complete, turn off the RPi and remove the receiver. We won't need it anymore.
2

Installation of 433.92MHz transmitter

433.92 MHz transmitter. Model — TWS-BS V1.02
Transmitter connection diagram to RPi
Connect the transmitter according to the diagram:
Also, in the side grill of my RPi case, I drilled a 6.5mm diameter hole and secured an SMA connector in it. Next, cut an RG316 cable to the required length and solder one end to the SMA connector and the other to the antenna output on the transmitter. The transmitter chip itself can be glued to the inside of the RPi case with thermal adhesive, and the wires can be tied with cable ties. Also, apply thermal adhesive to the soldering points of the antenna cable. Carefully close the RPi case and screw the antenna onto the SMA connector. Turn on the RPi and access it via SSH:
1
ssh pi@192.168.0.XXX
By default, rpi-rf uses GPIO17 for the transmitter, but mine was already occupied, so I changed it to GPIO22. To do this, enter the command in the terminal:
1
sudo nano /usr/local/bin/rpi-rf_send
And replace this line:
1
parser.add_argument('-g', dest='gpio', type=int, default=17,
2
help="GPIO pin (Default: 17)")
with
1
parser.add_argument('-g', dest='gpio', type=int, default=22,
2
help="GPIO pin (Default: 22)")
Plug the radio-controlled socket into the 220-volt outlet and connect a desk lamp to it. Try turning it on with the command in the terminal:
1
rpi-rf_send -p 174 -t 1 5330691
Where 174 is the pulselength, 1 is the protocol, and 5330691 is the socket's code for turning on.
After pressing Enter, the socket should turn on.
Let's check turning off the socket. Enter in the terminal:
1
rpi-rf_send -p 174 -t 1 5330694
Do the same for the 2nd and 3rd sockets to make sure everything works.
3

We are linking voice control with Alexa

For the first socket, I assigned control to the desk lamp and wrote this code in PHP:
1
<?
2
if (isset($_POST['code'])) $code = $_POST['code']; else $code = "";
3
4
$code_lamp_light_on = "UKfX1aAC";
5
$code_lamp_light_off = "zPEGnFPz";
6
7
$cmd_lamp_light_on = "rpi-rf_send -p 174 -t 1 5330691";
8
$cmd_lamp_light_off = "rpi-rf_send -p 174 -t 1 5330694";
9
10
if ($code == $code_lamp_light_on) exec($cmd_lamp_light_on);
11
if ($code == $code_lamp_light_off) exec($cmd_lamp_light_off);
12
?>
Next, go toIFTTTand create personal applets for controlling the sockets. You can read about how to do this in the instructions "I am a universal IR remote with Alexa voice control".
Now the lamp can be turned on with the command: "Alexa, trigger light on…»
Profit :)

Discussion (0)

No comments yet. Be the first!

Maker

Avatar
Savva
Tashkent, UZ

Anton is the Managing Partner of Tinkster. He studied oil and gas engineering in the United States and also holds two honors degrees from Tomsk Polytechnic University.