In one of the previous posts I have shown how to control the socket’s with pilight and an RF transmitter.
Since the pilight protocol which will be able to control my outlets (quigg_gt9000) is not finished yet, I wrote a simple command which sniffs out the raw codes (with pilight-debug) and a bash script to use send these raw codes to control the outlets (with pilight-send).
The XY-MK-5V receiver must be wired to:
Transmitter:
Purple cable – RPi PIN 2 (5V) -> FS1000A VCC (tested and working on PIN 1 3.3V too)
Blue cable – RPi PIN 9 (GND) –> FS1000A GND
Green cable – RPi PIN 11 (GPIO 17/WiringPi Pin 0) –> FS1000A DATA
Receiver:
Yellow cable – RPi PIN 4 (5V) -> XY-MK-5V VCC
Orange cable – RPi PIN 12 (GPIO 18/WiringPi Pin 1) –> XY-MK-5V DATA
Red cable – RPi PIN 14 (GND) –> XY-MK-5V GND
For my Lidl outlets, I have sniffed the raw codes like this:
First, stop the pilight service, pilight-debug works only then:
sudo service pilight stop
Use this command to sniff the raw codes (push all buttons on the remote one after the other -> A:ON, A:OFF, B:ON, B:OFF, C:ON, C:OFF, D:ON, D:OFF, ALL:ON, ALL:OFF) and note the raw codes which appear:
pi@433v2:~ $ sudo pilight-debug | grep -B6 -A3 -E "pulselen:\s220"
What do the pilight-debug data mean?
If we feed the XY-MK-5V receiver 5V voltage, we get a lot of noise, but my command filters the shite out by grepping to the necessary info.
For my Lidl outlets, pulselenght must be “220” to work, so we grep for that:
-E and \s is to ignore the whitespace between the “pulselen:” and “220”
B6 is printing 6 lines before the grep match line, needed for printing details: time, hardware, pulse, rawlen, pulselen
A3 is printing 3 lines after the grep match line, this is needed to print out the raw code itself
The control script:
You need to paste in the corresponding raw codes into the script, and make the script executable by:
chmod +x lidl433control.sh
The script is written in Bash, and it needs 2 arguments, like the next example shows, this switches my ‘B’ socket on:
./lidl433control.sh b on
#!/bin/bash
letter="$1"
state="$2"
echo
SERVICE='pilight'
if ps ax | grep -v grep | grep $SERVICE > /dev/null; then
echo "$SERVICE service running, everything is fine, carry on..."
else
echo "$SERVICE is needed for this script, but it's not running!"
echo "Do you want to start $SERVICE? (y/n)"
read -e startservice
if [ "$startservice" = "y" -o "$startservice" = "Y" -o "$startservice" = "yes" -o "$startservice" = "YES" ]; then
sudo service pilight start
echo "Starting $SERVICE now!"
else
echo "The script cannot continue without running $SERVICE, exiting..."
exit 1
fi
fi
echo
echo "Requested command ($1:$2)"
echo
if [ "$letter" = 'a' -a "$state" = 'on' ]; then
echo "A: ON"
sudo pilight-send -p raw -c "1065 639 1065 639 1065 639 1065 639 426 1065 426 1065 1065 639 426 1065 426 1065 426 1065 1065 639 1065 639 1065 639 426 1065 426 1065 1065 639 426 1065 1065 639 426 1065 1065 639 1065 639 1065 639 426 1065 639 1065 2982 7242"
elif [ "$letter" = 'a' -a "$state" = 'off' ]; then
echo "A: OFF"
sudo pilight-send -p raw -c "1065 639 1065 639 1065 639 1065 639 426 1065 426 1065 1065 639 1065 639 1065 639 426 1065 426 1065 426 1065 1065 639 1065 639 1065 639 426 1065 1065 639 426 1065 1065 639 1065 639 1065 639 1065 639 426 1065 426 1065 2982 7242"
elif [ "$letter" = 'b' -a "$state" = 'on' ]; then
echo "B: ON"
sudo pilight-send -p raw -c "1065 639 1065 639 1065 639 1065 639 426 1065 426 1065 426 1065 426 1065 1065 639 1065 639 426 1065 426 1065 426 1065 426 1065 1065 639 1065 639 426 1065 426 1065 1065 639 1065 639 426 1065 1065 639 426 1065 1065 639 2982 7242"
elif [ "$letter" = 'b' -a "$state" = 'off' ]; then
echo "B: OFF"
sudo pilight-send -p raw -c "1065 639 1065 639 1065 639 1065 639 1065 639 1065 639 426 1065 1065 639 1065 639 426 1065 1065 639 426 1065 1065 639 1065 639 426 1065 426 1065 1065 639 426 1065 426 1065 1065 639 426 1065 1065 639 426 1065 1065 639 2982 7242"
elif [ "$letter" = 'c' -a "$state" = 'on' ]; then
echo "C: ON"
sudo pilight-send -p raw -c "1065 639 1065 639 1065 639 1065 639 1065 639 1065 639 426 1065 426 1065 426 1065 426 1065 1065 639 426 1065 426 1065 426 1065 1065 639 426 1065 1065 639 426 1065 426 1065 426 1065 1065 639 1065 639 1065 639 426 1065 2982 7242"
elif [ "$letter" = 'c' -a "$state" = 'off' ]; then
echo "C: OFF"
sudo pilight-send -p raw -c "1065 639 1065 639 1065 639 1065 639 426 1065 426 1065 1065 639 426 1065 426 1065 426 1065 1065 639 1065 639 1065 639 426 1065 426 1065 1065 639 426 1065 1065 639 426 1065 1065 639 1065 639 1065 639 1065 639 426 1065 2982 7242"
elif [ "$letter" = 'd' -a "$state" = 'on' ]; then
echo "D: ON"
sudo pilight-send -p raw -c "1065 639 1065 639 1065 639 1065 639 426 1065 1065 639 426 1065 1065 639 426 1065 426 1065 426 1065 1065 639 426 1065 1065 639 426 1065 426 1065 1065 639 1065 639 426 1065 1065 639 426 1065 1065 639 1065 639 1065 639 2982 7242"
elif [ "$letter" = 'd' -a "$state" = 'off' ]; then
echo "D: OFF"
sudo pilight-send -p raw -c "1065 639 1065 639 1065 639 1065 639 426 1065 426 1065 426 1065 426 1065 1065 639 1065 639 426 1065 426 1065 426 1065 426 1065 852 639 1065 639 426 1065 426 1065 1065 639 1065 639 426 1065 1065 639 1065 639 1065 639 2982 7242"
elif [ "$letter" = 'all' -a "$state" = 'on' ]; then
echo "ALL: ON"
elif [ "$letter" = 'all' -a "$state" = 'off' ]; then
echo "A: OFF"
else
echo "Invalid command"
fi
exit