Switch mysensors does not work

Yes, I change it too, if I change one I have to change everything, but according to homeassistant all the sketsch are fine, I am trying to get another Raspberry and make a clean installation only with homeassistant

What I understand, the problem is that the switch, in the home assistant GUI, doesnā€™t remain toggled, after toggling it. The cause, is that thereā€™s no feedback from the device to home assistant about the state change. The solution, is that we need to feedback the new state to home assistant after changing the relay state in the receive function. Use the send function to feedback the state.

See the example sketch here:

Man my sketch is more complete, but I do not see the difference of how it says homeassistant and mysensors.
Iā€™m trying to live a rasberry just to try from 0 what is left for me to try, unless you tell me where is my error because I do not see it, above you have my sketch

Add a send(msgR1.set(state1), state1); to your first IF state ment, and a send(msgR1.set(state2), state2); to your second IF statement.

This will tell Home Assistant that the relay has be toggled on/off after the command is received.

Like so:

void receive(const MyMessage &message) { 
  if (message.type == V_STATUS) {
    switch (message.sensor) {
      case MS_RELE_CHILD_ID_1:    
        state1 = message.getBool();                 
        send(msgR1.set(state1), state1);
        setRelayState(RELAY_PIN_1, state1);                                             // Cambia el estado del rele
        saveState(MS_RELE_CHILD_ID_1, state1);                                          // Almacena el estado en la eeprom
        printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, MS_RELE_CHILD_ID_1, state1);  // Escribe la informacion en el debug
      break; 
      case MS_RELE_CHILD_ID_2:    
        state2 = message.getBool();                 
        send(msgR1.set(state2), state2);
        setRelayState(RELAY_PIN_2, state2);                                             // Cambia el estado del rele
        saveState(MS_RELE_CHILD_ID_2, state2);                                          // Almacena el estado en la eeprom
        printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, MS_RELE_CHILD_ID_2, state2);  // Escribe la informacion en el debug
      break; 
    }
  }
}

Ok thank you, Iā€™ll try and Iā€™ll tell you

20035 TSF:MSG:SEND,3-3-6-0,s=2,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
Sensor cambiado por:  Cambio por radio, Sensor nĀŗ: 2
20300 TSF:MSG:READ,0-6-3,s=2,c=1,t=2,pt=1,l=1,sg=0:1
20356 TSF:MSG:ACK
20376 TSF:MSG:SEND,3-3-6-0,s=2,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
Sensor cambiado por:  Cambio por radio, Sensor nĀŗ: 2
20639 TSF:MSG:READ,0-6-3,s=2,c=1,t=2,pt=1,l=1,sg=0:1
20695 TSF:MSG:ACK
20715 TSF:MSG:SEND,3-3-6-0,s=2,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1
Sensor cambiado por:  Cambio por radio, Sensor nĀŗ: 2
20980 TSF:MSG:READ,0-6-3,s=2,c=1,t=2,pt=1,l=1,sg=0:1
21036 TSF:MSG:ACK

I added it, and in R1 it seems to work, but in R2 it goes crazy.

void receive(const MyMessage &message) { 
  if (message.type == V_STATUS) {
    switch (message.sensor) {
      case MS_RELE_CHILD_ID_1:    
        state1 = message.getBool();                 
        send(msgR1.set(state1), state1);                                                // Mensaje para HomeAsistant
        setRelayState(RELAY_PIN_1, state1);                                             // Cambia el estado del rele
        saveState(MS_RELE_CHILD_ID_1, state1);                                          // Almacena el estado en la eeprom
        printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, MS_RELE_CHILD_ID_1, state1);  // Escribe la informacion en el debug
      break; 
      case MS_RELE_CHILD_ID_2:    
        state2 = message.getBool();                 
        send(msgR2.set(state2), state2);                                                // Mensaje para HomeAsistant
        setRelayState(RELAY_PIN_2, state2);                                             // Cambia el estado del rele
        saveState(MS_RELE_CHILD_ID_2, state2);                                          // Almacena el estado en la eeprom
        printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, MS_RELE_CHILD_ID_2, state2);  // Escribe la informacion en el debug
      break; 
    }
  }
}

Iā€™m still trying, because Iā€™m not worth

Good to hear youā€™re making progress, Iā€™m sure you figure out the issue causing R2 to go weird.

As save the state in the eeprom I thought that was the problem, but nothing, remains the same.
Thanks for everything

Try moving the send to the end of the commands.

Example:

void receive(const MyMessage &message) { 
  if (message.type == V_STATUS) {
    switch (message.sensor) {
      case MS_RELE_CHILD_ID_1:    
        state1 = message.getBool();                 
        setRelayState(RELAY_PIN_1, state1);                                             // Cambia el estado del rele
        saveState(MS_RELE_CHILD_ID_1, state1);                                          // Almacena el estado en la eeprom
        printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, MS_RELE_CHILD_ID_1, state1);  // Escribe la informacion en el debug
        send(msgR1.set(state1), state1);                                                // Mensaje para HomeAsistant
      break; 
      case MS_RELE_CHILD_ID_2:    
        state2 = message.getBool();                 
        setRelayState(RELAY_PIN_2, state2);                                             // Cambia el estado del rele
        saveState(MS_RELE_CHILD_ID_2, state2);                                          // Almacena el estado en la eeprom
        printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, MS_RELE_CHILD_ID_2, state2);  // Escribe la informacion en el debug
        send(msgR2.set(state2), state2);                                                // Mensaje para HomeAsistant
      break; 
    }
  }
}


If I also tried it moving it in several places, and all more or less the same.
At the end I thought and tried the Mysensor sketch of HomeAssistant and the result is the following ā€¦

43830 TSF:MSG:SEND,3-3-6-0,s=1,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1
44199 TSF:MSG:READ,0-6-3,s=2,c=1,t=2,pt=0,l=1,sg=0:1
44257 TSF:MSG:SEND,3-3-6-0,s=1,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1
44568 TSF:MSG:READ,0-6-3,s=2,c=1,t=2,pt=0,l=1,sg=0:1
44625 TSF:MSG:SEND,3-3-6-0,s=1,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1
44966 TSF:MSG:READ,0-6-3,s=2,c=1,t=2,pt=0,l=1,sg=0:1
45023 TSF:MSG:SEND,3-3-6-0,s=1,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1
45278 TSF:MSG:READ,0-6-3,s=2,c=1,t=2,pt=0,l=1,sg=0:1
45334 TSF:MSG:SEND,3-3-6-0,s=1,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1
45618 TSF:MSG:READ,0-6-3,s=2,c=1,t=2,pt=0,l=1,sg=0:1
45674 TSF:MSG:SEND,3-3-6-0,s=1,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1
45929 TSF:MSG:READ,0-6-3,s=2,c=1,t=2,pt=0,l=1,sg=0:1
45985 TSF:MSG:SEND,3-3-6-0,s=1,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:1

WWWWEEEEEEEEE
I already found the fault, it is not send (msgR2.set (state2), state2);
if send (msgR2.set (state2));

void receive(const MyMessage &message) { 
  if (message.type == V_STATUS) {
    switch (message.sensor) {
      case MS_RELE_CHILD_ID_1:    
        state1 = message.getBool();
        send(msgR1.set(state1));                                                        // Mensaje para HomeAsistant                  
        setRelayState(RELAY_PIN_1, state1);                                             // Cambia el estado del rele
        saveState(MS_RELE_CHILD_ID_1, state1);                                          // Almacena el estado en la eeprom
        printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, MS_RELE_CHILD_ID_1, state1);  // Escribe la informacion en el debug
      break; 
      case MS_RELE_CHILD_ID_2:    
        state2 = message.getBool();
        send(msgR2.set(state2));                                                        // Mensaje para HomeAsistant                 
        setRelayState(RELAY_PIN_2, state2);                                             // Cambia el estado del rele
        saveState(MS_RELE_CHILD_ID_2, state2);                                          // Almacena el estado en la eeprom
        printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, MS_RELE_CHILD_ID_2, state2);  // Escribe la informacion en el debug
      break; 
    }
  }
}
1 Like

Good job. :smiley:

1 Like