Raspberry Pi 3 + Livolo and Sonoff Switches + RF

Hello!

I’'m on a project that using a RPi 3 and an RF transmitter to create an Apple HomeBridge to control Livolo switches (almost 50 gangs) and Sonoff switches through the Home application and by voice control (Siri).

I think the initial idea is quite simple, but I’m finding it very difficult to complete, since my knowledge of RPi is few.

I bought a RPi 3 kit with Screen, receiver and RF transmitter, Livolo wireless switches (several with 3 gangs each) and Livolo remote control (VL-RMT-04) that controls up to 27 circuits.

Because of QuickPi videos on YouTube, I know how to install HomeBridge on Raspberry Pi, Hap-NodeJs and how to control Sonoff.

My problem now is how to controll the Livolo switches.

In this site (http://www.instructables.com/id/Controlling-a-Livolo-RF-Light-Switch-Using-a-Raspb/) they teaches how to control 1 gang 1 way switch, but I have several 3 gangs 2 ways and I need to control 27 circuits plus scene mode.

I alread located this files on GitHub:





But my problem is that I can’t get the RPi to controll all my 50 circuits.

Please, someone can help me? I’m sure thats your answer can help a lot of people.

Thanks.

what RF trasmitter you are using?

You may consider in buying a Broadlink RMPRO for transmitting

I use livolo switches in my set up. I have been using them for about 2 years and they work perfectly every time. I use an arduino code library to control my switches. I discovered the code library on this forum There is a file that you can download in the first comment. The codes are set up as follows.

Remote id’s 6400; 19303; 10550; 8500; 7400: 6550; 7400; 8500;
Button Numbers #1: 0, #2: 96, #3: 120, #4: 24, #5: 80, #6: 48, #7: 108, #8: 12, #9: 72; #10: 40, #OFF: 106

I use it like this on my arduino:

  server.on("/bulb5", [](){
    livolo.sendButton(8500, 120);
    server.send(200, "text/plain", "Kitchen light on");
  });   
  
    server.on("/bulb6", [](){
    livolo.sendButton(8500, 106);
    server.send(200, "text/plain", "Kitchen light off");
  }); 
      
  server.on("/bulb7", [](){
    livolo.sendButton(19303, 120);
    server.send(200, "text/plain", "Bedroom light on");
  });   
  
    server.on("/bulb8", [](){
    livolo.sendButton(19303, 106);
    server.send(200, "text/plain", "Bedroom light off");
  });

Each light switch has its own remote id number then I use the all off command when I want the light to switch off and toggle command when I want the light to come on. This saves toggling the light back on when the light was off.

Now your issue is to control over 50 lights. The way that the liviolo lights are set up you can make hundreds of remotes. Here is the formula

Fullsize remote ID has this pattern: remoteID = 1 + N*3;
where N is any integer number you choose starting from 0 to 21884 (so that the output doesn't exceed 65535)
the result are as examples: 1,4,7,10,13,...,6400,6403,6406....

This was taken from comment 95

I see you are using a raspberry pi. I believe you can still uses these codes with the github crankru/nodejs-livolo code.

Hope this helps

Hi, Claudio.

A very cheap one: http://s.aliexpress.com/mmeyy2Af

I don’t believe that’s my problem. The first gang of livolo switch accept the command for Raspberry, but not the second, the third…

Thank you very much, Michael!

Can you write down here your full command script?

Thanks!

Hi

Here is my full Arduino code. It is used on a nodemcu that controls my heaters (infrared) livolo light switches (433mhz) and Energenie switches (443mhz) it also has temperature and light sensors on it. it is all controlled by visiting a page eg 192.168.1.91/bulb1 will turn on one of my livolo lights. I have one of these devices in each room collecting temperature and light data. As well as controlling my environment.

Michael

#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include "DHT.h"
#include <livolo.h>
#include <RCSwitch.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <IRremoteESP8266.h>

RCSwitch mySwitch = RCSwitch();

IRsend irsend(13);
unsigned int raw[277] = {9864,948,492,904,496,908,496,908,496,916,488,916,1188,1620,484,912,496,904,492,912,492,912,496,912,492,912,492,916,1168,1012,404,1000,416,1620,480,908,492,912,496,916,488,924,1192,996,404,1620,480,904,488,920,496,916,488,912,488,924,1184,1620,1188,1600,504,908,496,912,492,920,480,912,1196,1600,1212,1600,496,924,484,908,496,904,1180,1024,404,1000,404,1604,500,900,488,920,1200,1604,500,904,1204,1604,1204,1616,488,904,500,904,1184,1620,1208,1616,480,908,500,908,496,908,496,904,1204,1616,472,920,500,904,1200,984,392,1012,420,984,420,984,420,988,404,996,420,992,400,992,424,984,420,980,408,1012,404,984,420,988,420,980,412,992,420,984,420,1000,404,984,420,980,420,984,420,988,416,988,416,1000,404,988,416,984,420,984,420,984,428,976,416,988,416,988,416,988,416,984,416,988,420,984,420,984,416,992,416,984,416,988,424,980,400,1004,416,988,400,1004,416,984,424,980,420,984,404,1000,420,984,420,984,400,1004,420,984,416,988,420,980,424,980,424,980,424,980,420,988,416,984,420,984,416,988,416,988,404,1004,412,988,400,1004,412,992,412,1628,472,928,476,924,1180,1636,468,936,464,940,464,936,468,940,1168,1640,460,940,464,944,460,944,460,940,460,944,1144,1044,384,};
unsigned int raw2[277] = {9896,916,496,908,496,908,480,920,496,912,492,908,1192,1632,480,908,496,908,492,924,480,916,488,912,464,936,468,940,1168,1028,400,1004,404,1624,480,912,488,924,480,924,460,932,1196,996,404,1624,480,912,468,948,480,924,452,952,480,924,1176,1632,1184,1608,492,924,484,908,492,908,496,912,488,912,492,924,480,928,480,920,480,912,492,908,496,908,1172,1652,1184,1600,500,904,472,936,1200,1604,1204,980,420,1608,496,908,496,912,492,912,492,924,480,908,492,912,1196,1604,500,908,500,904,496,904,1200,1612,496,908,496,904,1176,1632,1200,984,388,1020,416,988,412,1004,400,984,420,988,420,980,420,992,412,992,412,988,416,984,420,980,424,980,424,984,416,992,412,988,416,988,416,984,396,1008,420,980,424,988,412,988,388,1016,412,988,420,984,420,984,420,988,416,984,416,984,396,1008,392,1012,420,984,400,1008,416,984,392,1012,420,980,420,984,420,984,420,984,420,988,416,984,396,1004,420,988,416,988,416,988,416,988,416,984,416,988,420,984,420,984,420,988,416,984,420,984,408,1000,416,984,416,988,408,992,420,1004,396,1000,404,996,408,992,408,996,408,1008,368,1032,396,1632,1176,1632,1172,1632,472,936,1168,1016,388,1636,464,940,464,936,1168,1644,1164,1020,360,1044,384,1020,384,};



Livolo livolo(4); // transmitter connected to pin #4

#define ONE_WIRE_BUS 5
 
#define WLAN_SSID "put your SSID here"
#define WLAN_PASS "put your password her"

ESP8266WebServer server(80);
 
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

float temp_c, light, temp_c2;

int lightPin = A0;  //define a pin for Photo resistor

void ReadSensor() {
  sensors.requestTemperatures(); 
  // Read temperature as Celsius
  temp_c = sensors.getTempCByIndex(0)- 2;
  temp_c2 = sensors.getTempCByIndex(1)- 2;
  light = analogRead(lightPin)/2;
  


  // Check if any reads failed and exit early (to try again).
  if isnan(temp_c) {
    Serial.println("Failed to read from DHT sensor :-(");
    return;
  }


}


void setup() {
  irsend.begin();
  Serial.begin(115200);
  delay(10);
  mySwitch.enableTransmit(4);


  
  // Connecting to wifi
  WiFi.begin(WLAN_SSID, WLAN_PASS);

  // Set a static IP (optional)  
  IPAddress ip(192, 168, 1, 91);
  IPAddress gateway(192, 168, 1, 1);
  IPAddress subnet(255, 255, 255, 0);
  WiFi.config(ip, gateway, subnet);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
 
  Serial.println("");
  Serial.print("Connected to wifi with IP ");  
  Serial.println(WiFi.localIP());

  // Define capabilities of our little web server

  server.on("/heaton", [](){
    irsend.sendRaw(raw,277,38);
    delay(2000);
    server.send(200, "text/plain", "Heater On");
  });

  server.on("/heatoff", [](){
    irsend.sendRaw(raw2,277,38);
    delay(2000);
    server.send(200, "text/plain", "Heater Off");
  });
    
  server.on("/temp_c2", [](){
    ReadSensor();
    server.send(200, "text/plain", String(temp_c2));
  });
  
  server.on("/temp_c", [](){
    ReadSensor();
    server.send(200, "text/plain", String(temp_c));
  });
  
  server.on("/light", [](){
    ReadSensor();
    server.send(200, "text/plain", String(light));
  }); 
  
  server.on("/bulb1", [](){
    livolo.sendButton(6550, 120);
    server.send(200, "text/plain", "Livingroom 1 light On");
  }); 
    
  server.on("/bulb2", [](){
    livolo.sendButton(6550, 106);
    server.send(200, "text/plain", "Livingroom 1 light Off");
  }); 
      
  server.on("/bulb3", [](){
    livolo.sendButton(7400, 120);
    server.send(200, "text/plain", "Livingroom 2 light On");
  }); 
      
  server.on("/bulb4", [](){
    livolo.sendButton(7400, 106);
    server.send(200, "text/plain", "Livingroom 2 light Off");
  }); 
      
  server.on("/bulb5", [](){
    livolo.sendButton(8500, 120);
    server.send(200, "text/plain", "Kitchen light on");
  });   
  
    server.on("/bulb6", [](){
    livolo.sendButton(8500, 106);
    server.send(200, "text/plain", "Kitchen light off");
  }); 
      
  server.on("/bulb7", [](){
    livolo.sendButton(19303, 120);
    server.send(200, "text/plain", "Bedroom light on");
  });   
  
    server.on("/bulb8", [](){
    livolo.sendButton(19303, 106);
    server.send(200, "text/plain", "Bedroom light off");
  }); 
  
  server.on("/bulb9", [](){
    livolo.sendButton(10550, 120);
    server.send(200, "text/plain", "Spare Bedroom light on");
  });   
  
    server.on("/bulb10", [](){
    livolo.sendButton(10550, 106);
    server.send(200, "text/plain", "Spare Bedroom light off");
  });     
  
    server.on("/bulb11", [](){
    livolo.sendButton(6400, 106);
    server.send(200, "text/plain", "All lights off");
  }); 
  
    server.on("/energenie1on", [](){
    mySwitch.send(5122515, 24);
    server.send(200, "text/plain", "Lights on");
  }); 
  
    server.on("/energenie1off", [](){
    mySwitch.send(5122514, 24);
    server.send(200, "text/plain", "Lights off");
  });   
  
    server.on("/energenie2on", [](){
    mySwitch.send(5122507, 24);
    server.send(200, "text/plain", "Lights on");
  }); 
  
    server.on("/energenie2off", [](){
    mySwitch.send(5122506, 24);
    server.send(200, "text/plain", "Lights off");
  });
  
    server.on("/energenie3on", [](){
    mySwitch.send(5122511, 24);  
    server.send(200, "text/plain", "Lights on");
  });
    
    server.on("/energenie3off", [](){
    mySwitch.send(5122510, 24);
    server.send(200, "text/plain", "Lights off");
  });
  
    server.on("/energenie4on", [](){
    mySwitch.send(5122503, 24);
    server.send(200, "text/plain", "Lights on");
  }); 
  
    server.on("/energenie4off", [](){
    mySwitch.send(5122502, 24);
    server.send(200, "text/plain", "Lights off");
  });
  
    server.on("/energenieallon", [](){
    mySwitch.send(5122513, 24);
    server.send(200, "text/plain", "Lights on");
  }); 
  
    server.on("/energeniealloff", [](){
    mySwitch.send(5122512, 24);
    server.send(200, "text/plain", "Lights off");
  });     
   
    server.on("/energenielivon", [](){
    mySwitch.send(5122591, 24);
    server.send(200, "text/plain", "Lights on");
  }); 
  
    server.on("/energenielivoff", [](){
    mySwitch.send(5122590, 24);
    server.send(200, "text/plain", "Lights off");
  });
   
    server.on("/energeniebedon", [](){
    mySwitch.send(5122583, 24);
    server.send(200, "text/plain", "Lights on");
  }); 
  
    server.on("/energeniebedoff", [](){
    mySwitch.send(5122582, 24);
    server.send(200, "text/plain", "Lights off");
  });
  
    server.on("/energeniebathon", [](){
    mySwitch.send(5122587, 24);
    server.send(200, "text/plain", "Lights on");
  }); 
  
    server.on("/energeniebathoff", [](){
    mySwitch.send(5122586, 24);
    server.send(200, "text/plain", "Lights off");
  });

    server.on("/", [](){
    server.send(200, "text/plain", "McArthur Home Automation - /heaton /heatoff /temp_c /bulb1 /bulb2 /bulb3 /bulb4 /bulb5 /bulb6 /energenie1on /energenie1off  /energenie2on /energenie2off /energenie3on /energenie3off  /energenie4on /energenie4off /energenieallon /energeniealloff /energenielivon /energenielivoff /energeniebedon /energeniebedoff  ");
  });  
  

  server.begin();
  Serial.println("HTTP server started");

  sensors.begin();
}

void handle_root() {
  server.send(200, "text/plain", "All systems go. Read data from /temp or or /temp_c or /humidity or /heatindex.");
  delay(100);
}

void loop() {
  server.handleClient();

}

Thank you very much!

I will try something like that. :smiley:

@anon35356645
Let me ask you something, please.

I read in other sites that you are using a Broadlink to control your lights. It’s that correct?

I’m trying to not use the Broadlink because I think that will be one problem more to deal with it, coz as I see, it serves only to send the RF code.

Because I’m trying to made a HomeBridge with Raspberry Pi I’m afraid to the Broadlink be one more issue.

Could you share with me what are using to control your lights?

Thanks.

I use broadlink RM Pro for controlling tc2 switches (for lights) and some cheap 433 power plugs that controls various electric appliances
It is very stable.

Homebridge for?

To control everything with the IPhone, Ipad and Mac, using the App Home.

How do you control your lights with Broadling?

Could you share with us your setup?

Thank you.

actually the RMPRO controls the TC2, RF433 switches, which in turn control lights. Code is very simple

  - platform: broadlink
    host: 192.168.1.90
    mac: 'b4:43:0d:dxxxxxxx'
    switches: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CRYJFgkWCRYJFgkWCRYWCQkWFgkJFhYJCRYJFhYJFgkWCQkWFgkJFhYJCRYJFhYJCRYJFgkWCQABSOkURgDfCRYJCRYJFhYJCRYJFgkWCRYJFgkWCRYJFhYJCRYWCQkWFgkJFgkWFgkWCRYJCRYWCQkWFgkJFgkWFgkJFgkWCRYJAAFI'
        friendly_name: 'Kitchen'

Thank you! But I think that not gonna help me. I will try again with @michaelmcarthur code.

But thanks again for your help.

Hi @Playboybra, have you figured out how to control your livolo switches using just the raspi and a cheap rf transmitter? I would like to accomplish the same thing, including home bridge. But still cannot control one gang with the simple midorineko script. I thought the rf transmitter was defective, but using an rf receiver I see it’s actually transmitting. I think if that doesn’t work something should be defective in my setup

Hi, do you use Livolo dimmer? Are you able to dim with the remote and with HASS?