Perfect @BartE !!!
Great job you did... you contributed greatly to a breakthrough in inexpensive home automation.
Now we can buy the cheapest good finished glass RF in-wall home switches from Livolo and got total integration with All Home Automation Controllers, using one mysensors node.
here is the final code, I added the remote code var
// This skecth was created by @BartE from mysensors forum.
// it was created to control 9 switches
// livolo.h library necessary to work.
// Just use a simple node + chinese cheap RF433 transmitter DATA plugged on Pin D8.
#define MY_DEBUG
#define MY_RADIO_NRF24
#include <SPI.h>
#include <MySensors.h>
#include <livolo.h>
#define CHILD_ID 1
Livolo livolo(8); //Digital pin you plugged your transmitter
// now config your remote and button codes. Livolo codes are composed by "remote code, button code"
// There are many codes already discovered, and you can test new codes or get your remote's code using the daleldalel skectch
bool initValSent[] = {false, false, false, false, false, false, false, false, false}; //as many as your switch number
int livoloRemCode[] = {5504, 5504, 5504, 7849, 7849, 7849, 17035, 17035, 17035}; //set remote livolo codes here
int livoloSensCode[] = {16, 56, 8, 16, 8, 56, 16, 56, 8}; // Set buttons livolo codes here
MyMessage msg(CHILD_ID, V_STATUS);
void setup() {
}
void presentation() {
sendSketchInfo("Livolo", "1.0");
for (int sensor=1; sensor<=9; sensor++) { // change number 9 for the total switches number you want
// (presents each sensor, S_BINARY type)
present(sensor, S_BINARY);
}
}
void loop() {
for (int sensor=1; sensor<=9; sensor++) { // change number 9 for the total switches number you want
if (!initValSent[sensor-1]) {
msg.setSensor(sensor);
send(msg.set(false));
Serial.print("Requesting initial value for sensor: ");
Serial.println(sensor);
request(sensor, V_STATUS);
wait(2000, C_SET, V_STATUS);
}
}
}
void receive(const MyMessage &message) {
switch (message.type) {
case V_LIGHT:
if (!initValSent[message.sensor-1]) {
Serial.print("Receiving initial value from controller for sensor: ");
initValSent[message.sensor-1] = true;
} else {
Serial.print("Receiving new value for sensor: ");
livolo.sendButton(livoloRemCode[message.sensor-1], livoloSensCode[message.sensor-1]); // coded for each switch
}
Serial.println(message.sensor);
break;
}
}