Introduction: Controlling a Livolo RF Light Switch Using a Raspberry Pi 3 B in Python
Controlling RF switches with a Raspberry Pi is a mainstay in home automation. I used this wonderful instructable to set up RF sockets in my room. However, controlling my Livolo light switch was more challenging. I spent a few days searching deep into google trying to find a simple solution. Since I couldn't find one, I made one. Enjoy :)!
Step 1: Wire Up a 433mhz RF Transmitter to Raspberry Pi
In my code we use GPIO 24, so either wire it to 24 or change the code to 22.
Step 2: Get the Python Code
https://github.com/midorineko/rpi_automation/blob/...
This is the livolo transmission code I use for home automation. It features an 'off' function which is all livolo lights off and one other frequency 'on' which is actually a lightswitch toggle.
However, in the code comments I provide many other possible frequencies, which can all be saved as variables and used if you need.
In case I change the file name or location the contents are bellow.
import time
import sys import RPi.GPIO as GPIO
off = '1242424352424342424242424242425342524342' on = '124242435242434242424242424242425243424242'
if sys.argv[1:] == 'off': NUM_ATTEMPTS = 1000 else: NUM_ATTEMPTS = 200
TRANSMIT_PIN = 24
def transmit_code(code): '''Transmit a chosen code string using the GPIO transmitter''' GPIO.setmode(GPIO.BCM) GPIO.setup(TRANSMIT_PIN, GPIO.OUT) for t in range(NUM_ATTEMPTS): for i in code: if i == '1': GPIO.output(TRANSMIT_PIN, 1) time.sleep(.00055); GPIO.output(TRANSMIT_PIN, 0) elif i == '2': GPIO.output(TRANSMIT_PIN, 0) time.sleep(.00011); GPIO.output(TRANSMIT_PIN, 1) elif i == '3': GPIO.output(TRANSMIT_PIN, 0) time.sleep(.000303); GPIO.output(TRANSMIT_PIN, 1) elif i == '4': GPIO.output(TRANSMIT_PIN, 1) time.sleep(.00011); GPIO.output(TRANSMIT_PIN, 0) elif i == '5': GPIO.output(TRANSMIT_PIN, 1) time.sleep(.00029); GPIO.output(TRANSMIT_PIN, 0) else: continue GPIO.output(TRANSMIT_PIN, 0) GPIO.cleanup()
if __name__ == '__main__': for argument in sys.argv[1:]: exec('transmit_code(' + str(argument) + ')')
# How to use:: I am putting this here, because it seems few people have figured out livolo switches. # Hold down livolo light switch for 5 seconds and wait for a beep. # Run ```python livolo.py on``` # Livolo light switch should beep again, signalling it is paired # Now running ```python livolo.py on``` will toggle the switch. # ```python livolo.py off``` is global to all switches and should work out of box.
# The following lines are possible RF codes which can be learned by the switch. # Just make them strings and save them to variables similarly to 'on' or 'off'. # I only have 1 switch so multiple RF freqs werent necessary. # 1, 2, 4, 2, 4, 2, 4, 3, 5, 2, 4, 2, 4, 3, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2 # 1, 2, 4, 2, 4, 2, 4, 3, 5, 2, 4, 2, 4, 3, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 5, 3, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2 # 1, 2, 4, 2, 4, 2, 4, 3, 5, 2, 4, 2, 4, 3, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 5, 3, 5, 3, 4, 2, 4, 2, 4, 2 # 1, 2, 4, 2, 4, 2, 4, 3, 5, 2, 4, 2, 4, 3, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 5, 3, 4, 2, 4, 2, 4, 2 # 1, 2, 4, 2, 4, 2, 4, 3, 5, 2, 4, 2, 4, 3, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 5, 2, 4, 3, 4, 2, 4, 2, 4, 2, 4, 2 # 1, 2, 4, 2, 4, 2, 4, 3, 5, 2, 4, 2, 4, 3, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 5, 3, 4, 2, 4, 2, 4, 2, 4, 2 # 1, 2, 4, 2, 4, 2, 4, 3, 5, 2, 4, 2, 4, 3, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 5, 3, 4, 2, 5, 3, 4, 2, 4, 2 # 1, 2, 4, 2, 4, 2, 4, 3, 5, 2, 4, 2, 4, 3, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 5, 3, 4, 2, 4, 2 # 1, 2, 4, 2, 4, 2, 4, 3, 5, 2, 4, 2, 4, 3, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 5, 2, 4, 2, 4, 3, 4, 2, 4, 2, 4, 2 # 1, 2, 4, 2, 4, 2, 4, 3, 5, 2, 4, 2, 4, 3, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 5, 2, 4, 3, 4, 2, 4, 2, 4, 2
Step 3: Teaching the Switch
Right now with the python script you should be able to safely turn off any and all livolo lights by running.
```python livolo.py off```
To get the switch toggle working we need to teach the switch one of our RF codes, in this case 'on'.
1) Hold the livolo gang down for ~5 seconds and you will hear a beep.
2) Enter ```python livolo.py on```
3) Hear a second beep
4) If you hear a beep, run ```python livolo.py on``` to toggle your switch on/off. Else repeat steps 1-3.
Step 4: Toggling the Livolo Switch
Depending on the power of your transmitter and the distance from your livolo switch you may have to raise or lower the number of attempts in the code.
Livolo unfortunately does not support a single ON function only a TOGGLE function and all OFF function.
Warning: Double clicks on lights are bound to happen since we are sending a code 200 times to a toggle switch. However, Livolo actual remote uses a similar crappy pattern.
16 Comments
3 years ago
Great tutorial! Worked on the first try! Is there something similar with nodejs?
4 years ago
Actually there has to be a way to generate only ON code, since there's a remote controller (https://www.amazon.com/LIVOLO-Wireless-Controller-Accessories-RMT04/dp/B01M99JSPM) which has buttons called "scenes" - those buttons actually turn on switches (not toggling) - I'm pretty sure about that, because I've got this remote :-)
4 years ago
How to calculate new codes? can you help with that?
5 years ago
Should this also work with Raspberry Pi Zero?
6 years ago
I have my entire house with Livolo switches. I already have the broadlink product to control the switches via 433mhz but it is very unreliable.
What RF module are you using with your raspberry?
How do you find it in terms of range and reliability?
Thank you so much!!
6 years ago
Please, I need some help. I have 9 Livolo's Switches with 3 gang each. Could you teach how to configure more than one switche? Thank you.
6 years ago
Is there a way to get a switch state. In case where controller will power cycle, the switch state can changed. Thanks.
Reply 6 years ago
There is no way to track state
7 years ago
Very cool, thanks for sharing how you did this!
Reply 7 years ago
No problem, an instructable is what got me this far. I thought I should give back to the community :)
Reply 7 years ago
Very cool! Would it be possible to code 2 livolo dimmer to work on the same switch? I am delaying our kitchen remodel while trying to decide whether to yank all the 3-gang boxes so I can replace with 1-gang for livolo switches, but I can't justify the time/effort/cost if it means having to choose between dimming or 2nd switch location... (2 months without a kitchen, GF is not happy)...
I've tried to find other panel switches that can dim and work as 3-way, but nothing comes up that looks close to livolo...
Reply 6 years ago
I am not exactly sure the wave patterns for the dimmer calls, however this technique can definitely be used to control dimming. It should be able to have seperate dimmers for swtiches, but idk if livolo programs different calls for dimming on each swtich.
6 years ago
Is Livolo just for Europe ?
I am based in US, will this work for standard US sockets ?
Do you know some places I can refer to ?
Reply 6 years ago
Never mind I found it
https://www.amazon.com/Standard-VL-C303-81-110~250V-Crystal-Control/dp/B00GPDRS92/ref=pd_rhf_se_s_cp_1?ie=UTF8&pd_rd_i=B00GPDRS92&pd_rd_r=HSAXM1Y2Y5KSZTWDB7JM&pd_rd_w=f1vAq&pd_rd_wg=tWqoe&psc=1&refRID=HSAXM1Y2Y5KSZTWDB7JM
Reply 6 years ago
Well it still does not answer the question if that is certified in US.
Reply 6 years ago
Yes it owrked in standard US sockets.