Livolo RF433 Switches

Hum, i got.
There is something wrong in the presentation or initial value sent for the HA with these sketch…

I’ll try copy the other sketch’s way to do that and see the results…

Thanks

Yes, now I got the switch.livolo_19_1 in the entity list of the HA

but no boolean switch work yet.

16-09-26 22:38:26 homeassistant.components.mysensors: Adding new devices: <Entity Livolo 19 1: off>
16-09-26 22:38:26 homeassistant.components.mysensors: Livolo 19 1: value_type 2, value = 0
16-09-26 22:38:57 homeassistant.components.mysensors: Update sensor_update: node 19
16-09-26 22:38:57 homeassistant.components.mysensors: Livolo 19 1: value_type 2, value = 0
16-09-26 22:38:57 homeassistant.components.mysensors: Update sensor_update: node 19
16-09-26 22:38:57 homeassistant.components.mysensors: Livolo 19 1: value_type 2, value = 0
16-09-26 22:38:57 homeassistant.components.mysensors: Update sensor_update: node 19
16-09-26 22:38:57 homeassistant.components.mysensors: Livolo 19 1: value_type 2, value = 0
16-09-26 22:38:58 homeassistant.components.mysensors: Update sensor_update: node 19
16-09-26 22:38:58 homeassistant.components.mysensors: Livolo 19 1: value_type 2, value = 0
16-09-26 22:38:58 homeassistant.components.mysensors: Update sensor_update: node 19
16-09-26 22:38:58 homeassistant.components.mysensors: Livolo 19 1: value_type 2, value = 0

how can I check if the daemon is working?

by putting in the log lines in the app.

import appdaemon.appapi as appapi
import datetime
import time

class RFSwitch(appapi.AppDaemon):

  def initialize(self):
    self.listen_state(self.switch, "input_boolean")
  
  def switch(self, entity, attribute, old, new, kwargs):
     self.log("the rfswitch app is triggered","INFO")
     for counter in range(1,int(self.args["total_switches"])+1):
        boolean_name_start= self.args["switchcode" + str(counter)][0:4]
        switch_type = self.args["switchcode" + str(counter)][4:6]
        switch_code = self.args["switchcode" + str(counter)][6:]
        switch=self.args["switch" + switch_type]
        device, entity_name = self.split_entity(entity)

        if entity[14:18] == boolean_name_start:
          if new == "on":
            self.log("id did send " + switch_code + "t to sensor " + switch,"INFO")  
            self.call_service("switch/mysensors_send_ir_code", entity_id = switch, V_IR_SEND=switch_code + "t")
          else:
          self.log("id did send " + switch_code + "f to sensor " + switch,"INFO")  
          self.call_service("switch/mysensors_send_ir_code", entity_id = switch, V_IR_SEND=switch_code + "f")

you should see info lines in your log or terminal screen every time you turn a switch.
and off course dont forget to make sure that appdaemon is running when you try that.

The mysensors IRSwitch requires the V_IR_SEND value to have the device added as an entity in HA. You only sent V_LIGHT in your sketch.

We should explain this in the docs.

thx, i forgot to mention and look at that part because it is hidden in my HA and i dont do anything with it :wink:

Ok, now I got the appdaemon running after sending from terminal the command line
$ cd appdaemon
$ appdaemon -c conf/appdaemon.cfg

Do I need to run it manually???

After that I got a log when pressed the boolean switches
But nothing happened neither on the lights nor on the node serial monitor

2016-09-27 12:00:45.965385 INFO AppDaemon Version 1.3.4 starting
2016-09-27 12:00:46.663942 INFO Got initial state
2016-09-27 12:00:46.670742 INFO Loading Module: /home/pi/appdaemon/conf/apps/hello.py
2016-09-27 12:00:46.682405 INFO Loading Object hello_world using class HelloWorld from module hello
2016-09-27 12:00:46.690805 INFO hello_world: Hello from AppDaemon
2016-09-27 12:00:46.694116 INFO hello_world: You are now ready to run Apps!
2016-09-27 12:00:46.698635 INFO Loading Module: /home/pi/appdaemon/conf/apps/RFSwitch.py
2016-09-27 12:00:46.711085 INFO Loading Object schakelaars using class RFSwitch from module RFSwitch
2016-09-27 12:00:46.716475 INFO Waiting for App initialization: 1 remaining
2016-09-27 12:00:47.724877 INFO App initialization complete
2016-09-27 12:01:22.165885 INFO schakelaars: the rfswitch app is triggered
2016-09-27 12:01:22.172287 INFO schakelaars: id did send A5504B16t to sensor switch.livolo_19_1
2016-09-27 12:01:26.394278 INFO schakelaars: the rfswitch app is triggered
2016-09-27 12:01:26.416080 INFO schakelaars: id did send A5504B8t to sensor switch.livolo_19_1
2016-09-27 12:01:28.514189 INFO schakelaars: the rfswitch app is triggered
2016-09-27 12:01:28.582062 INFO schakelaars: id did send A17035B16t to sensor switch.livolo_19_1
2016-09-27 12:01:31.242931 INFO schakelaars: the rfswitch app is triggered
2016-09-27 12:01:31.252039 INFO schakelaars: id did send A5504B56t to sensor switch.livolo_19_1
2016-09-27 12:01:33.404435 INFO schakelaars: the rfswitch app is triggered
2016-09-27 12:01:33.492950 INFO schakelaars: id did send A17035B56t to sensor switch.livolo_19_1
2016-09-27 12:01:36.136793 INFO schakelaars: the rfswitch app is triggered
2016-09-27 12:01:36.192301 INFO schakelaars: id did send A7849B8t to sensor switch.livolo_19_1
2016-09-27 12:01:37.627408 INFO schakelaars: the rfswitch app is triggered
2016-09-27 12:01:37.667896 INFO schakelaars: id did send A17035B8t to sensor switch.livolo_19_1
2016-09-27 12:01:39.373929 INFO schakelaars: the rfswitch app is triggered
2016-09-27 12:01:39.408810 INFO schakelaars: id did send A7849B19t to sensor switch.livolo_19_1
2016-09-27 12:01:40.674907 INFO schakelaars: the rfswitch app is triggered
2016-09-27 12:01:40.704219 INFO schakelaars: id did send A7849B56t to sensor switch.livolo_19_1

Have you confirmed that you have the device as an entity in home assistant and that you can send IR codes to the device using the mysensors service in the development tools?

you can start appdaemon automaticly like HA.
i think it is described somewhere on the appdaemon github site, but i havent used that till now.
@aimc can probably help you with that.

like martin said you need to make sure that you have 2 entitys in HA active:

  1. the switch (and we know you have that)
  2. the sensor which transports the code.

at least we are now sure that the app is up and running.
when the sensor also is visible in HA all there is left is to get the sketch right.

Where is this sensor supposed to be visible? as another entity?
I only have one entity which is linked with this work
switch.livolo_19_1

in the available services there is
switch/mysensors_send_ir_code

and I don’t know how to send anything through the development tools to test the communication with the node.
How do I do that?

Domain
switch

Service
mysensors_send_ir_code

service data (JSON, optional)

Click on the service, enter JSON data (see below) in textbox, click run/send (don’t remember what it says).

{'V_IR_SEND': '0xC284'}

This should send the code to all IRSwitch entities. You can specify one or more entities in the JSON if you want to limit the targets.

Also I suggest using the example sketch when testing a new platform. You might have to adapt it to version 2.0 of mysensors. Then when you know how the platform works, you add your specific functionality to the sketch.

yes the sensor is supposed to be vissible as another entity.
so you should see in ha:
switch.livolo_19_1
sensor.livolo_19_1

for now i think your sketch doesnt create the sensor.

i think this sketch should activate switch 6400,120 (the splitting out part can we do after that)

#define MY_DEBUG 
#define MY_RADIO_NRF24
#include <SPI.h>
#include <MySensors.h>
#include <livolo.h>

#define CHILD_ID 1

Livolo livolo(8);

bool initialValueSent = false;
char code[11]="A17035B420t";

MyMessage msg(CHILD_ID, V_LIGHT);
MyMessage msgCode(CHILD_ID, V_IR_SEND );
MyMessage msgCodeRec(CHILD_ID, V_IR_RECEIVE);

void setup() {
  
}

void presentation()  {   
  sendSketchInfo("Livolo", "1.0");
  present(CHILD_ID, S_IR);
}

void loop() {
  int value = 0;
  if (!initialValueSent) {
    Serial.println("Sending initial value");
    send(msg.set(value==HIGH ? 1 : 0));
    send(msgcode.set(value==code));
    send(msgcoderec.set(value==code));
    Serial.println("Requesting initial value from controller");
    request(CHILD_ID, V_LIGHT);
    wait(2000, C_SET, V_LIGHT);
  }
}

void receive(const MyMessage &message) {
  if (message.type==V_IR_SEND) {
   String codestring = message.getString();
    if (message.sensor==CHILD_ID){
      livolo.sendButton(6400, 120);
    }
    if (!initialValueSent) {
      Serial.println("Receiving initial value from controller");
      initialValueSent = true;
    }
  }
}


im sorry that i cant try it out for you and till now all my sketches are version 1.5
so it is a little bit off a struggle to give you a working version from a 2.0 version from a switch i dont own :wink:

I tried sending a code using development as @martinhjelmare taught, but no response, but we knew that would not work because my sketch is not configuring the sensor.

I tried with the example IR switch mysensors sketch from HA components and there is no sensor entity and could not sending using development as well.

@ReneTode, the new sketch are generating two errors, which I tried to correct but didn’t get it.

initializer-string for array of chars is too long [-fpermissive]
char code[11] = “A17035B420t”;

warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]
send(msgCode.set(value==code));

tried make the " " shorter like the example sketch, which uses a 10 string, but the error persists.

and the other error I think is about setting a char to a variable that once were number… am I right?

thank you guys for not losing hope in my project…

Your char array need to have place for one more character than the text that you enter into it. See:
https://www.arduino.cc/en/Reference/String

I solved the comparison issue in the example sketch like this:

String(code) != String(oldCode)

Disclaimer: I’m not very experienced arduino or C programmer, so I don’t know that it’s the best way.

If the communication is not working when using the example sketch, I strongly suggest you troubleshoot that without changing the sketch first. You might have a hardware issue, in which case any further changes to the sketch will just make it harder to troubleshoot.

Can you post the example sketch as you have modified it for version 2.0?

this is my 2.0 modified example, which i just realized is not showing the switch on HA (noticed after reboot ha, the switch that was been showed was from the last sketch)

/*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* http://www.mysensors.org/build/ir
*/
#define MY_DEBUG
#define MY_RADIO_NRF24
#include <MySensors.h>
#include <SPI.h>
#include <IRLib.h>

#define SN "IR Sensor"
#define SV "1.0"
#define CHILD_ID 1

char code[10] = "abcd01234";
char oldCode[10] = "abcd01234";
MyMessage msgCodeRec(CHILD_ID, V_IR_RECEIVE);
MyMessage msgCode(CHILD_ID, V_IR_SEND);
MyMessage msgSendCode(CHILD_ID, V_LIGHT);

void setup()
{
  sendSketchInfo(SN, SV);
  present(CHILD_ID, S_IR);
  // Send initial values.
  send(msgCodeRec.set(code));
  send(msgCode.set(code));
  send(msgSendCode.set(0));
}

void loop()
{
  // IR receiver not implemented, just a dummy report of code when it changes
  if (String(code) != String(oldCode)) {
    Serial.print("Code received ");
    Serial.println(code);
    send(msgCodeRec.set(code));
    strcpy(oldCode, code);
  }
}

void incomingMessage(const MyMessage &message) {
  if (message.type==V_LIGHT) {
    // IR sender not implemented, just a dummy print.
    if (message.getBool()) {
      Serial.print("Sending code ");
      Serial.println(code);
    }
    send(msgSendCode.set(message.getBool() ? 1 : 0));
    // Always turn off device
    wait(100);
    send(msgSendCode.set(0));
  }
  if (message.type == V_IR_SEND) {
    // Retrieve the IR code value from the incoming message.
    String codestring = message.getString();
    codestring.toCharArray(code, sizeof(code));
    Serial.print("Changing code to ");
    Serial.println(code);
    send(msgCode.set(code));
  }
}

i think that code should work.
and i dont think there is a hardware problem because the switch was active in HA.

to make sure there is no hardware problem, you could take a normal lightswitch sketch and then a looking if you get input in the arduino, but i am 99% sure there is no hardware problem.

i have an 2.0 gateway setup in 1 part off my house right now.
i will try to make a 2.0 code working this weekend (i need to do that anyway)
if i got a working code i will post that here.

I have just concluded this code is not working, because I reboot everything, waited until HA and Gateway ready and only after turned the node on, and the switch didn’t appear.

I am sure there is no hardware problem because I got all working using that first method @ReneTode told me, with this sketch, where I configured 9 switches directly on arduino node and set all the remote and button codes using a chair []

#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

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++) { 
    present(sensor, S_BINARY);
  }
}

void loop() {
  for (int sensor=1; sensor<=9; sensor++) {  
    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]);
       }  
       Serial.println(message.sensor);  
       break;
  }
}

But I do agree the way we are trying is much better, once I will never need to change sketch again…
We will get it working!!!

1 Like

Initial values must be sent in the loop for mysensors 2.0. Move that from setup to loop, within an if statement as my example on the main mysensors doc page. Check for the values in receive function.

Hi,

I’m using Livolo switches with raspberry pi and connected simple rf transmitter without using arduino.
I use the transmitter code from LamPi project.

read the instructions there to calc a remote id and key id. then for each switch I use a different remote id. if the switch has multiple gongs I use same remote id and different key id.

then from hass I use command line to execute the transmitter with the right code.

i am using LIVOLO switches… just use the command componenet …thats all
like ant other command line switch
something like: /home/pi/livolo/transmiter/codesend …