Sunday, August 22, 2021

Control Sunforce Solar String Lights with Raspberry Pi

I recently picked up these Sunforce 35' Solar String Lights with a remote control from Costco


 

After some initial research, and looking up the FCC ID 2AX4R-101015 the remote control operates on 433.92MHz. There are plenty of tutorials about using either a Raspberry Pi or an Arduino ESP32 to make a transmitter and receiver, and a lot of programs to help decode the signal. The remote control uses Amplitude Shift Keyring (ASK) which is just an on or off binary code repeated. Some 433MHz codes use a rolling code to change the code each time, but not any of the cheap stuff. You can find a number of these cheap remote controls on Amazon or AliExpress.

REMEMBER: This is just a guide for hobbyists, and is not intended for any malicious activity. Check with your local government before proceeding.

I ordered this Nooelec NESDR Mini dongle from Amazon, it worked with Ubuntu 20.04 out of the box. The first thing that we need to do is to use a dongle for Software Defined Radio (SDR) with a program called Universal Radio Hacker.

Installing URH:

$ sudo apt update && sudo apt install python3 # Install Python3
$ sudo python3 -m pip install --upgrade pip # Update your pip installation $ sudo python3 -m pip install urh # Install URH
$ urh # Launch URH

After launching URH, we can now capture the radio signal from the remote control by clicking File > Record Signal

URH will show the waveform and you can save it to a file to further analyze the signal.


You can see the signal here repeats itself and URH will show a proposed code, and you can zoom in one one of the repetitions to further analyze it. We'll need to note the length between the pauses, and the binary code that gets sent. Further analysis we can get the length of the codes from when the transmitter is switched on and off:



This is measured in micro seconds which will need to be converted into seconds, and find the pattern of the code that gets repeated.


After further investigation, the binary code seemed to be as follows from URH:

1 = 0111

0 = 0100

So for the code, I used the long_delay as 1 and short_delay as 0 and the final signal was found to be 1010101011111111111010001. Now we can wire up the Raspberry Pi 4 with the 433MHz transmitter from Amazon connecting it to GPIO pin 17.The Python Code can be found on GitHub and is originally from an Instructables tutorial. Be sure to install RPi.GPIO if it is not already installed


sudo python3 -m pip install RPi.GPIO

and put the user in the gpio group on the pi

sudo usermod -aG gpio ${USER}

To run the script enter the terminal via ssh and run

python3 /path/to/script/string_lights.py switch

I am not sure why the number of attempts is set at 6, but it works. Be sure to change the transmit pin to which ever you connect the transmitter to. Also, it doesn't have to be on GPIO pin 17 but that is what worked in my case.  Next project is to integrate it with MQTT and HomeAssistant.