Problem z przekaźnikami na mysensor w HA

Witam serdecznie forumowiczów
jestem świeżym użytkownikiem HA i mam taki problem
Stworzyłem z kilku przykładów działające na Andino mega projekt na 21 przekaźników i 21 przycisków ( komunikacja serial) połączonych z HA i niestety jak było ich 4 to wszystko działało jak należy ale jak jest ich 21 to niestety już nie :frowning:
Problem polega na tym ze przełącznik od wszystkich encji w HA działa tylko na pierwsze 7 i dziesiąty ale przy wyłączeniu już dziesiątego nie wyłączy :frowning: działa to tak jak by cos się zapychało gdzieś na serialu
Mój kod do arduino Mega:

//#define MY_DEBUG
 
#define MY_NODE_ID 97
// Enable and select radio type attached
//#define MY_RADIO_RF24
//#define MY_RADIO_NRF5_ESB
//#define MY_RADIO_RFM69
//#define MY_RADIO_RFM95
 
// Set LOW transmit power level as default, if you have an amplified NRF-module and
// power your radio separately with a good regulator you can turn up PA level.
//#define MY_RF24_PA_LEVEL RF24_PA_LOW
 
// Enable serial gateway
#define MY_GATEWAY_SERIAL
 
// Define a lower baud rate for Arduinos running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
#if F_CPU == 8000000L
#define MY_BAUD_RATE 38400
#endif
 
// Enable inclusion mode
//#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
//#define MY_INCLUSION_BUTTON_FEATURE
 
// Inverses behavior of inclusion button (if using external pullup)
//#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
 
// Set inclusion mode duration (in seconds)
#define MY_INCLUSION_MODE_DURATION 60
// Digital pin used for inclusion mode button
//#define MY_INCLUSION_MODE_BUTTON_PIN  3
 
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
 
// Inverses the behavior of leds
//#define MY_WITH_LEDS_BLINKING_INVERSE
 
// Flash leds on rx/tx/err
// Uncomment to override default HW configurations
//#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
//#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
//#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED

#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h>

#define RELAY_PIN0  22  // Arduino Digital I/O pin number for relay 
#define RELAY_PIN1  23
#define RELAY_PIN2  24
#define RELAY_PIN3  25
#define RELAY_PIN4  26  // Arduino Digital I/O pin number for relay 
#define RELAY_PIN5  27
#define RELAY_PIN6  28
#define RELAY_PIN7  29
#define RELAY_PIN8  30  // Arduino Digital I/O pin number for relay 
#define RELAY_PIN9  31
#define RELAY_PIN10  32
#define RELAY_PIN11  33
#define RELAY_PIN12  34  // Arduino Digital I/O pin number for relay 
#define RELAY_PIN13  35
#define RELAY_PIN14  36
#define RELAY_PIN15  37
#define RELAY_PIN16  38
#define RELAY_PIN17  39  // Arduino Digital I/O pin number for relay 
#define RELAY_PIN18  40
#define RELAY_PIN19  41
#define RELAY_PIN20  42

#define BUTTON_PIN0  A0  // Arduino Digital I/O pin number for button 
#define BUTTON_PIN1  A1  // Arduino Digital I/O pin number for button 
#define BUTTON_PIN2  A2  // Arduino Digital I/O pin number for button 
#define BUTTON_PIN3  A3  // Arduino Digital I/O pin number for button 
#define BUTTON_PIN4  A4  // Arduino Digital I/O pin number for button 
#define BUTTON_PIN5  A5  // Arduino Digital I/O pin number for button 
#define BUTTON_PIN6  A6  // Arduino Digital I/O pin number for button 
#define BUTTON_PIN7  A7  // Arduino Digital I/O pin number for button 
#define BUTTON_PIN8  A8  // Arduino Digital I/O pin number for button 
#define BUTTON_PIN9  A9  // Arduino Digital I/O pin number for button 
#define BUTTON_PIN10  A10 // Arduino Digital I/O pin number for button 
#define BUTTON_PIN11  A11 // Arduino Digital I/O pin number for button 
#define BUTTON_PIN12  A12 // Arduino Digital I/O pin number for button 
#define BUTTON_PIN13  A13 // Arduino Digital I/O pin number for button 
#define BUTTON_PIN14  A14 // Arduino Digital I/O pin number for button
#define BUTTON_PIN15  43 // Arduino Digital I/O pin number for button 
#define BUTTON_PIN16  44 // Arduino Digital I/O pin number for button 
#define BUTTON_PIN17  45 // Arduino Digital I/O pin number for button 
#define BUTTON_PIN18  46 // Arduino Digital I/O pin number for button 
#define BUTTON_PIN19  47 // Arduino Digital I/O pin number for button 
#define BUTTON_PIN20  48 // Arduino Digital I/O pin number for button 


#define CHILD0_ID 100   // Id of the sensor child
#define CHILD1_ID 101   // Id of the sensor child
#define CHILD2_ID 102   // Id of the sensor child
#define CHILD3_ID 103   // Id of the sensor child
#define CHILD4_ID 104   // Id of the sensor child
#define CHILD5_ID 105   // Id of the sensor child
#define CHILD6_ID 106   // Id of the sensor child
#define CHILD7_ID 107   // Id of the sensor child
#define CHILD8_ID 108   // Id of the sensor child
#define CHILD9_ID 109   // Id of the sensor child
#define CHILD10_ID 110   // Id of the sensor child
#define CHILD11_ID 111   // Id of the sensor child
#define CHILD12_ID 112   // Id of the sensor child
#define CHILD13_ID 113   // Id of the sensor child
#define CHILD14_ID 114   // Id of the sensor child
#define CHILD15_ID 115   // Id of the sensor child
#define CHILD16_ID 116   // Id of the sensor child
#define CHILD17_ID 117   // Id of the sensor child
#define CHILD18_ID 118   // Id of the sensor child
#define CHILD19_ID 119   // Id of the sensor child
#define CHILD20_ID 120   // Id of the sensor child

#define RELAY_ON 1
#define RELAY_OFF 0

Bounce debouncerA = Bounce();
Bounce debouncerB = Bounce();
Bounce debouncerC = Bounce();
Bounce debouncerD = Bounce();
Bounce debouncerE = Bounce(); //5
Bounce debouncerF = Bounce();
Bounce debouncerG = Bounce();
Bounce debouncerH = Bounce();
Bounce debouncerI = Bounce();
Bounce debouncerJ = Bounce(); //10
Bounce debouncerK = Bounce();
Bounce debouncerL = Bounce();
Bounce debouncerM = Bounce();
Bounce debouncerN = Bounce();
Bounce debouncerO = Bounce(); //15
Bounce debouncerP = Bounce();
Bounce debouncerR = Bounce();
Bounce debouncerS = Bounce();
Bounce debouncerT = Bounce(); 
Bounce debouncerW = Bounce(); //20
Bounce debouncerX = Bounce();

int oldValueA = 1;
int oldValueB = 1;
int oldValueC = 1;
int oldValueD = 1;
int oldValueE = 1; //5
int oldValueF = 1; 
int oldValueG = 1;
int oldValueH = 1;
int oldValueI = 1;
int oldValueJ = 1; //10
int oldValueK = 1; 
int oldValueL = 1;
int oldValueM = 1;
int oldValueN = 1;
int oldValueO = 1; //15
int oldValueP = 1; 
int oldValueR = 1;
int oldValueS = 1;
int oldValueT = 1;
int oldValueW = 1; //20
int oldValueX = 1;

bool stateA = false;
bool stateB = false;
bool stateC = false;
bool stateD = false;
bool stateE = false; //5
bool stateF = false; 
bool stateG = false;
bool stateH = false;
bool stateI = false;
bool stateJ = false; //10
bool stateK = false; 
bool stateL = false;
bool stateM = false;
bool stateN = false;
bool stateO = false; //15
bool stateP = false; 
bool stateR = false;
bool stateS = false;
bool stateT = false;
bool stateW = false; //20
bool stateX = false;

bool initialValueSent = false;

MyMessage msgA(CHILD0_ID, V_LIGHT);
MyMessage msgB(CHILD1_ID, V_LIGHT);
MyMessage msgC(CHILD2_ID, V_LIGHT);
MyMessage msgD(CHILD3_ID, V_LIGHT);
MyMessage msgE(CHILD4_ID, V_LIGHT); //5
MyMessage msgF(CHILD5_ID, V_LIGHT); 
MyMessage msgG(CHILD6_ID, V_LIGHT);
MyMessage msgH(CHILD7_ID, V_LIGHT);
MyMessage msgI(CHILD8_ID, V_LIGHT);
MyMessage msgJ(CHILD9_ID, V_LIGHT); //10
MyMessage msgK(CHILD10_ID, V_LIGHT); 
MyMessage msgL(CHILD11_ID, V_LIGHT);
MyMessage msgM(CHILD12_ID, V_LIGHT);
MyMessage msgN(CHILD13_ID, V_LIGHT);
MyMessage msgO(CHILD14_ID, V_LIGHT); //15
MyMessage msgP(CHILD15_ID, V_LIGHT); 
MyMessage msgR(CHILD16_ID, V_LIGHT);
MyMessage msgS(CHILD17_ID, V_LIGHT);
MyMessage msgT(CHILD18_ID, V_LIGHT);
MyMessage msgW(CHILD19_ID, V_LIGHT); //20
MyMessage msgX(CHILD20_ID, V_LIGHT);

void setup()
{
  // Setup the button
  pinMode(BUTTON_PIN0, INPUT_PULLUP);
  pinMode(BUTTON_PIN1, INPUT_PULLUP);
  pinMode(BUTTON_PIN2, INPUT_PULLUP);
  pinMode(BUTTON_PIN3, INPUT_PULLUP);
  pinMode(BUTTON_PIN4, INPUT_PULLUP); //5
  pinMode(BUTTON_PIN5, INPUT_PULLUP); 
  pinMode(BUTTON_PIN6, INPUT_PULLUP);
  pinMode(BUTTON_PIN7, INPUT_PULLUP);
  pinMode(BUTTON_PIN8, INPUT_PULLUP);
  pinMode(BUTTON_PIN9, INPUT_PULLUP); //10
  pinMode(BUTTON_PIN10, INPUT_PULLUP); 
  pinMode(BUTTON_PIN11, INPUT_PULLUP);
  pinMode(BUTTON_PIN12, INPUT_PULLUP);
  pinMode(BUTTON_PIN13, INPUT_PULLUP);
  pinMode(BUTTON_PIN14, INPUT_PULLUP); //15
  pinMode(BUTTON_PIN15, INPUT_PULLUP); 
  pinMode(BUTTON_PIN16, INPUT_PULLUP);
  pinMode(BUTTON_PIN17, INPUT_PULLUP);
  pinMode(BUTTON_PIN18, INPUT_PULLUP);
  pinMode(BUTTON_PIN19, INPUT_PULLUP); //20
  pinMode(BUTTON_PIN20, INPUT_PULLUP);
  
  // After setting up the button, setup debouncer
  debouncerA.attach(BUTTON_PIN0);
  debouncerA.interval(5);
  debouncerB.attach(BUTTON_PIN1);
  debouncerB.interval(5);
  debouncerC.attach(BUTTON_PIN2);
  debouncerC.interval(5);
  debouncerD.attach(BUTTON_PIN3);
  debouncerD.interval(5);
  debouncerE.attach(BUTTON_PIN4); //5
  debouncerE.interval(5);  
  debouncerF.attach(BUTTON_PIN5); 
  debouncerF.interval(5);  
  debouncerG.attach(BUTTON_PIN6);
  debouncerG.interval(5);  
  debouncerH.attach(BUTTON_PIN7);
  debouncerH.interval(5);  
  debouncerI.attach(BUTTON_PIN8);
  debouncerI.interval(5);  
  debouncerJ.attach(BUTTON_PIN9); //10
  debouncerJ.interval(5);  
  debouncerK.attach(BUTTON_PIN10); 
  debouncerK.interval(5);  
  debouncerL.attach(BUTTON_PIN11);
  debouncerL.interval(5);  
  debouncerM.attach(BUTTON_PIN12);
  debouncerM.interval(5);  
  debouncerN.attach(BUTTON_PIN13);
  debouncerN.interval(5);  
  debouncerO.attach(BUTTON_PIN14); //15
  debouncerO.interval(5);  
  debouncerP.attach(BUTTON_PIN15); 
  debouncerP.interval(5);  
  debouncerR.attach(BUTTON_PIN16);
  debouncerR.interval(5);
  debouncerS.attach(BUTTON_PIN17);
  debouncerS.interval(5);
  debouncerT.attach(BUTTON_PIN18);
  debouncerT.interval(5);
  debouncerW.attach(BUTTON_PIN19); //20
  debouncerW.interval(5);
  debouncerX.attach(BUTTON_PIN20);
  debouncerX.interval(5);

  // Make sure relays are off when starting up
  digitalWrite(RELAY_PIN0, RELAY_OFF);
  digitalWrite(RELAY_PIN1, RELAY_OFF);
  digitalWrite(RELAY_PIN2, RELAY_OFF);
  digitalWrite(RELAY_PIN3, RELAY_OFF);
  digitalWrite(RELAY_PIN4, RELAY_OFF); //5
  digitalWrite(RELAY_PIN5, RELAY_OFF); 
  digitalWrite(RELAY_PIN6, RELAY_OFF);
  digitalWrite(RELAY_PIN7, RELAY_OFF);
  digitalWrite(RELAY_PIN8, RELAY_OFF);
  digitalWrite(RELAY_PIN9, RELAY_OFF); //10
  digitalWrite(RELAY_PIN10, RELAY_OFF); 
  digitalWrite(RELAY_PIN11, RELAY_OFF);
  digitalWrite(RELAY_PIN12, RELAY_OFF);
  digitalWrite(RELAY_PIN13, RELAY_OFF);
  digitalWrite(RELAY_PIN14, RELAY_OFF); //15
  digitalWrite(RELAY_PIN15, RELAY_OFF); 
  digitalWrite(RELAY_PIN16, RELAY_OFF);
  digitalWrite(RELAY_PIN17, RELAY_OFF);
  digitalWrite(RELAY_PIN18, RELAY_OFF);
  digitalWrite(RELAY_PIN19, RELAY_OFF); //20
  digitalWrite(RELAY_PIN20, RELAY_OFF);
  
  // Then set relay pins in output mode
  pinMode(RELAY_PIN0, OUTPUT);
  pinMode(RELAY_PIN1, OUTPUT);
  pinMode(RELAY_PIN2, OUTPUT);
  pinMode(RELAY_PIN3, OUTPUT);
  pinMode(RELAY_PIN4, OUTPUT); //5
  pinMode(RELAY_PIN5, OUTPUT); 
  pinMode(RELAY_PIN6, OUTPUT);
  pinMode(RELAY_PIN7, OUTPUT);
  pinMode(RELAY_PIN8, OUTPUT);
  pinMode(RELAY_PIN9, OUTPUT); //10
  pinMode(RELAY_PIN10, OUTPUT); 
  pinMode(RELAY_PIN11, OUTPUT);
  pinMode(RELAY_PIN12, OUTPUT);
  pinMode(RELAY_PIN13, OUTPUT);
  pinMode(RELAY_PIN14, OUTPUT); //15
  pinMode(RELAY_PIN15, OUTPUT); 
  pinMode(RELAY_PIN16, OUTPUT);
  pinMode(RELAY_PIN17, OUTPUT);
  pinMode(RELAY_PIN18, OUTPUT);
  pinMode(RELAY_PIN19, OUTPUT); //20
  pinMode(RELAY_PIN20, OUTPUT);


  // Set relay to last known state (using eeprom storage)
  stateA = loadState(CHILD0_ID);
  digitalWrite(RELAY_PIN0, stateA ? RELAY_ON : RELAY_OFF);

  stateB = loadState(CHILD1_ID);
  digitalWrite(RELAY_PIN1, stateB ? RELAY_ON : RELAY_OFF);

  stateC = loadState(CHILD2_ID);
  digitalWrite(RELAY_PIN2, stateC ? RELAY_ON : RELAY_OFF);

  stateD = loadState(CHILD3_ID);
  digitalWrite(RELAY_PIN3, stateD ? RELAY_ON : RELAY_OFF);

  stateE = loadState(CHILD4_ID);
  digitalWrite(RELAY_PIN4, stateE ? RELAY_ON : RELAY_OFF);

  stateF = loadState(CHILD5_ID);
  digitalWrite(RELAY_PIN5, stateF ? RELAY_ON : RELAY_OFF);

  stateG = loadState(CHILD6_ID);
  digitalWrite(RELAY_PIN6, stateG ? RELAY_ON : RELAY_OFF);

  stateH = loadState(CHILD7_ID);
  digitalWrite(RELAY_PIN7, stateH ? RELAY_ON : RELAY_OFF);

  stateI = loadState(CHILD8_ID);
  digitalWrite(RELAY_PIN8, stateI ? RELAY_ON : RELAY_OFF);

  stateJ = loadState(CHILD9_ID);
  digitalWrite(RELAY_PIN9, stateJ ? RELAY_ON : RELAY_OFF);

  stateK = loadState(CHILD10_ID);
  digitalWrite(RELAY_PIN10, stateK ? RELAY_ON : RELAY_OFF);

  stateL = loadState(CHILD11_ID);
  digitalWrite(RELAY_PIN11, stateL ? RELAY_ON : RELAY_OFF);

  stateM = loadState(CHILD12_ID);
  digitalWrite(RELAY_PIN12, stateM ? RELAY_ON : RELAY_OFF);

  stateN = loadState(CHILD13_ID);
  digitalWrite(RELAY_PIN13, stateN ? RELAY_ON : RELAY_OFF);

  stateO = loadState(CHILD14_ID);
  digitalWrite(RELAY_PIN14, stateO ? RELAY_ON : RELAY_OFF);

  stateP = loadState(CHILD15_ID);
  digitalWrite(RELAY_PIN15, stateP ? RELAY_ON : RELAY_OFF);

  stateR = loadState(CHILD16_ID);
  digitalWrite(RELAY_PIN16, stateR ? RELAY_ON : RELAY_OFF);

  stateS = loadState(CHILD17_ID);
  digitalWrite(RELAY_PIN17, stateS ? RELAY_ON : RELAY_OFF);

  stateT = loadState(CHILD18_ID);
  digitalWrite(RELAY_PIN18, stateT ? RELAY_ON : RELAY_OFF);

  stateW = loadState(CHILD19_ID);
  digitalWrite(RELAY_PIN19, stateW ? RELAY_ON : RELAY_OFF);

  stateX = loadState(CHILD20_ID);
  digitalWrite(RELAY_PIN20, stateX ? RELAY_ON : RELAY_OFF);
}

void presentation()  {
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("21 Relay & button", "1.5");

  // Register all sensors to gw (they will be created as child devices)
  present(CHILD0_ID, S_LIGHT);
  present(CHILD1_ID, S_LIGHT);
  present(CHILD2_ID, S_LIGHT);
  present(CHILD3_ID, S_LIGHT);
  present(CHILD4_ID, S_LIGHT); //5
  present(CHILD5_ID, S_LIGHT);
  present(CHILD6_ID, S_LIGHT);
  present(CHILD7_ID, S_LIGHT);
  present(CHILD8_ID, S_LIGHT);
  present(CHILD9_ID, S_LIGHT); //10
  present(CHILD10_ID, S_LIGHT);
  present(CHILD11_ID, S_LIGHT);
  present(CHILD12_ID, S_LIGHT);
  present(CHILD13_ID, S_LIGHT);
  present(CHILD14_ID, S_LIGHT); //15
  present(CHILD15_ID, S_LIGHT);
  present(CHILD16_ID, S_LIGHT);
  present(CHILD17_ID, S_LIGHT);
  present(CHILD18_ID, S_LIGHT);
  present(CHILD19_ID, S_LIGHT); //20
  present(CHILD20_ID, S_LIGHT);
}

/*
   Example on how to asynchronously check for new messages from gw
*/
void loop()
{
  if (!initialValueSent) {
    Serial.println("Sending initial value");
    send(msgA.set(stateA?RELAY_ON:RELAY_OFF));
    send(msgB.set(stateB?RELAY_ON:RELAY_OFF));
    send(msgC.set(stateC?RELAY_ON:RELAY_OFF));
    send(msgD.set(stateD?RELAY_ON:RELAY_OFF));
    send(msgE.set(stateE?RELAY_ON:RELAY_OFF));
    send(msgF.set(stateF?RELAY_ON:RELAY_OFF));
    send(msgG.set(stateG?RELAY_ON:RELAY_OFF));
    send(msgH.set(stateH?RELAY_ON:RELAY_OFF));
    send(msgI.set(stateI?RELAY_ON:RELAY_OFF));
    send(msgJ.set(stateJ?RELAY_ON:RELAY_OFF));
    send(msgK.set(stateK?RELAY_ON:RELAY_OFF));
    send(msgL.set(stateL?RELAY_ON:RELAY_OFF));
    send(msgM.set(stateM?RELAY_ON:RELAY_OFF));
    send(msgN.set(stateN?RELAY_ON:RELAY_OFF));
    send(msgO.set(stateO?RELAY_ON:RELAY_OFF));
    send(msgP.set(stateP?RELAY_ON:RELAY_OFF));
    send(msgR.set(stateR?RELAY_ON:RELAY_OFF));
    send(msgS.set(stateS?RELAY_ON:RELAY_OFF));
    send(msgT.set(stateT?RELAY_ON:RELAY_OFF));
    send(msgW.set(stateW?RELAY_ON:RELAY_OFF));    
    send(msgX.set(stateX?RELAY_ON:RELAY_OFF));
    
 /*   Serial.println("Requesting initial value from controller");
   
    request(CHILD0_ID, V_STATUS);    
    request(CHILD1_ID, V_STATUS);    
    request(CHILD2_ID, V_STATUS);    
    request(CHILD3_ID, V_STATUS);
    request(CHILD4_ID, V_STATUS);
    request(CHILD5_ID, V_STATUS);
    request(CHILD6_ID, V_STATUS);
    request(CHILD7_ID, V_STATUS);
    request(CHILD8_ID, V_STATUS);
    request(CHILD9_ID, V_STATUS);
    request(CHILD10_ID, V_STATUS);
    request(CHILD11_ID, V_STATUS);
    request(CHILD12_ID, V_STATUS);    
    request(CHILD13_ID, V_STATUS);
    request(CHILD14_ID, V_STATUS);
    request(CHILD15_ID, V_STATUS);
    request(CHILD16_ID, V_STATUS);
    request(CHILD17_ID, V_STATUS);
    request(CHILD18_ID, V_STATUS);
    request(CHILD19_ID, V_STATUS);
    request(CHILD20_ID, V_STATUS);   
    wait(2000, C_SET, V_STATUS);
    */
  }
  
  debouncerA.update();
  // Get the update value
  int valueA = debouncerA.read();
  if (valueA != oldValueA && valueA == 0 ) {
    send(msgA.set(stateA ? false : true), true); // Send new state and request ack back
    stateA = !stateA;
    digitalWrite(RELAY_PIN0, stateA ? RELAY_ON : RELAY_OFF);
    saveState(CHILD0_ID, stateA);
  }
  oldValueA = valueA;

  debouncerB.update();
  // Get the update value
  int valueB = debouncerB.read();
  if (valueB != oldValueB && valueB == 0) {
    send(msgB.set(stateB ? false : true), true); // Send new state and request ack back
    stateB = !stateB;
    digitalWrite(RELAY_PIN1, stateB ? RELAY_ON : RELAY_OFF);
    saveState(CHILD1_ID, stateB);
  }
  oldValueB = valueB;

  debouncerC.update();
  // Get the update value
  int valueC = debouncerC.read();
  if (valueC != oldValueC && valueC == 0) {
    send(msgC.set(stateC ? false : true), true); // Send new state and request ack back
    stateC = !stateC;
    digitalWrite(RELAY_PIN2, stateC ? RELAY_ON : RELAY_OFF);
    saveState(CHILD2_ID, stateC);    
  }
  oldValueC = valueC;

  debouncerD.update();
  // Get the update value
  int valueD = debouncerD.read();
  if (valueD != oldValueD && valueD == 0) {
    send(msgD.set(stateD ? false : true), true); // Send new state and request ack back
    stateD = !stateD;
    digitalWrite(RELAY_PIN3, stateD ? RELAY_ON : RELAY_OFF);
    saveState(CHILD3_ID, stateD);
  }
  oldValueD = valueD;

  debouncerE.update();
  // Get the update value
  int valueE = debouncerE.read();
  if (valueE != oldValueE && valueE == 0) {
    send(msgE.set(stateE ? false : true), true); // Send new state and request ack back
    stateE = !stateE;
    digitalWrite(RELAY_PIN4, stateE ? RELAY_ON : RELAY_OFF);
    saveState(CHILD4_ID, stateE);
  }
  oldValueE = valueE;

  debouncerF.update();
  // Get the update value
  int valueF = debouncerF.read();
  if (valueF != oldValueF && valueF == 0) {
    send(msgF.set(stateF ? false : true), true); // Send new state and request ack back
    stateF = !stateF;
    digitalWrite(RELAY_PIN5, stateF ? RELAY_ON : RELAY_OFF);
    saveState(CHILD5_ID, stateF);
  }
  oldValueF = valueF;

  debouncerG.update();
  // Get the update value
  int valueG = debouncerG.read();
  if (valueG != oldValueG && valueG == 0) {
    send(msgG.set(stateG ? false : true), true); // Send new state and request ack back
    stateG = !stateG;
    digitalWrite(RELAY_PIN6, stateG ? RELAY_ON : RELAY_OFF);
    saveState(CHILD6_ID, stateG);
  }
  oldValueG = valueG;

  debouncerH.update();
  // Get the update value
  int valueH = debouncerH.read();
  if (valueH != oldValueH && valueH == 0) {
    send(msgH.set(stateH ? false : true), true); // Send new state and request ack back
    stateH = !stateH;
    digitalWrite(RELAY_PIN7, stateH ? RELAY_ON : RELAY_OFF);
    saveState(CHILD7_ID, stateH);
  }
  oldValueH = valueH;

  debouncerI.update();
  // Get the update value
  int valueI = debouncerI.read();
  if (valueI != oldValueI && valueI == 0) {
    send(msgI.set(stateI ? false : true), true); // Send new state and request ack back
    stateI = !stateI;
    digitalWrite(RELAY_PIN8, stateI ? RELAY_ON : RELAY_OFF);
    saveState(CHILD8_ID, stateI);
  }
  oldValueI = valueI;

  debouncerJ.update();
  // Get the update value
  int valueJ = debouncerJ.read();
  if (valueJ != oldValueJ && valueJ == 0) {
    send(msgJ.set(stateJ ? false : true), true); // Send new state and request ack back
    stateJ = !stateJ;
    digitalWrite(RELAY_PIN9, stateJ ? RELAY_ON : RELAY_OFF);
    saveState(CHILD9_ID, stateJ);
  }
  oldValueJ = valueJ;

  debouncerK.update();
  // Get the update value
  int valueK = debouncerK.read();
  if (valueK != oldValueK && valueK == 0) {
    send(msgK.set(stateK ? false : true), true); // Send new state and request ack back
    stateK = !stateK;
    digitalWrite(RELAY_PIN10, stateK ? RELAY_ON : RELAY_OFF);
    saveState(CHILD10_ID, stateK);
  }
  oldValueK = valueK;

  debouncerL.update();
  // Get the update value
  int valueL = debouncerL.read();
  if (valueL != oldValueL && valueL == 0) {
    send(msgL.set(stateL ? false : true), true); // Send new state and request ack back
    stateL = !stateL;
    digitalWrite(RELAY_PIN11, stateL ? RELAY_ON : RELAY_OFF);
    saveState(CHILD11_ID, stateL);
  }
  oldValueL = valueL;

  debouncerM.update();
  // Get the update value
  int valueM = debouncerM.read();
  if (valueM != oldValueM && valueM == 0) {
    send(msgM.set(stateM ? false : true), true); // Send new state and request ack back
    stateM = !stateM;
    digitalWrite(RELAY_PIN12, stateM ? RELAY_ON : RELAY_OFF);
    saveState(CHILD12_ID, stateM);
  }
  oldValueM = valueM;

  debouncerN.update();
  // Get the update value
  int valueN = debouncerN.read();
  if (valueN != oldValueN && valueN == 0) {
    send(msgN.set(stateN ? false : true), true); // Send new state and request ack back
    stateN = !stateN;
    digitalWrite(RELAY_PIN13, stateN ? RELAY_ON : RELAY_OFF);
    saveState(CHILD13_ID, stateN);
  }
  oldValueN = valueN;

  debouncerO.update();
  // Get the update value
  int valueO = debouncerO.read();
  if (valueO != oldValueO && valueO == 0) {
    send(msgO.set(stateO ? false : true), true); // Send new state and request ack back
    stateO = !stateO;
    digitalWrite(RELAY_PIN14, stateO ? RELAY_ON : RELAY_OFF);
    saveState(CHILD14_ID, stateO);
  }
  oldValueO = valueO;

  debouncerP.update();
  // Get the update value
  int valueP = debouncerP.read();
  if (valueP != oldValueP && valueP == 0) {
    send(msgP.set(stateP ? false : true), true); // Send new state and request ack back
    stateP = !stateP;
    digitalWrite(RELAY_PIN15, stateP ? RELAY_ON : RELAY_OFF);
    saveState(CHILD15_ID, stateP);
  }
  oldValueP = valueP;

  debouncerR.update();
  // Get the update value
  int valueR = debouncerR.read();
  if (valueR != oldValueR && valueR == 0) {
    send(msgR.set(stateR ? false : true), true); // Send new state and request ack back
    stateR = !stateR;
    digitalWrite(RELAY_PIN16, stateR ? RELAY_ON : RELAY_OFF);
    saveState(CHILD16_ID, stateR);
  }
  oldValueR = valueR;

  debouncerS.update();
  // Get the update value
  int valueS = debouncerS.read();
  if (valueS != oldValueS && valueS == 0) {
    send(msgS.set(stateS ? false : true), true); // Send new state and request ack back
    stateS = !stateS;
    digitalWrite(RELAY_PIN17, stateS ? RELAY_ON : RELAY_OFF);
    saveState(CHILD17_ID, stateS);
  }
  oldValueS = valueS;

  debouncerT.update();
  // Get the update value
  int valueT = debouncerT.read();
  if (valueT != oldValueT && valueT == 0) {
    send(msgT.set(stateT ? false : true), true); // Send new state and request ack back
    stateT = !stateT;
    digitalWrite(RELAY_PIN18, stateT ? RELAY_ON : RELAY_OFF);
    saveState(CHILD18_ID, stateT);
  }
  oldValueT = valueT;

  debouncerW.update();
  // Get the update value
  int valueW = debouncerW.read();
  if (valueW != oldValueW && valueW == 0) {
    send(msgW.set(stateW ? false : true), true); // Send new state and request ack back
    stateW = !stateW;
    digitalWrite(RELAY_PIN19, stateW ? RELAY_ON : RELAY_OFF);
    saveState(CHILD19_ID, stateW);
  }
  oldValueW = valueW;

  debouncerX.update();
  // Get the update value
  int valueX = debouncerX.read();
  if (valueX != oldValueX && valueX == 0) {
    send(msgX.set(stateX ? false : true), true); // Send new state and request ack back
    stateX = !stateX;
    digitalWrite(RELAY_PIN20, stateX ? RELAY_ON : RELAY_OFF);
    saveState(CHILD20_ID, stateX);
  }
  oldValueX = valueX;
}



void receive(const MyMessage &message) {
  // We only expect one type of message from controller. But we better check anyway.
  if (message.type == V_LIGHT) {
    
    switch (message.sensor) {
      case CHILD0_ID:
        stateA = message.getBool();
        digitalWrite(RELAY_PIN0, stateA ? RELAY_ON : RELAY_OFF);
        saveState(CHILD0_ID, stateA);
        break;
        
      case CHILD1_ID:
        stateB = message.getBool();
        digitalWrite(RELAY_PIN1, stateB ? RELAY_ON : RELAY_OFF);
        saveState(CHILD1_ID, stateB);
        break;

      case CHILD2_ID:
        stateC = message.getBool();
        digitalWrite(RELAY_PIN2, stateC ? RELAY_ON : RELAY_OFF);
        saveState(CHILD2_ID, stateC);
        break;
        
      case CHILD3_ID:
        stateD = message.getBool();
        digitalWrite(RELAY_PIN3, stateD ? RELAY_ON : RELAY_OFF);
        saveState(CHILD3_ID, stateD);
        break;

      case CHILD4_ID:
        stateE = message.getBool();
        digitalWrite(RELAY_PIN4, stateE ? RELAY_ON : RELAY_OFF);
        saveState(CHILD4_ID, stateE);
        break;  //5
        
      case CHILD5_ID:
        stateF = message.getBool();
        digitalWrite(RELAY_PIN5, stateF ? RELAY_ON : RELAY_OFF);
        saveState(CHILD5_ID, stateF);
        break;
        
      case CHILD6_ID:
        stateG = message.getBool();
        digitalWrite(RELAY_PIN6, stateG ? RELAY_ON : RELAY_OFF);
        saveState(CHILD6_ID, stateG);
        break;

      case CHILD7_ID:
        stateH = message.getBool();
        digitalWrite(RELAY_PIN7, stateH ? RELAY_ON : RELAY_OFF);
        saveState(CHILD7_ID, stateH);
        break;
        
      case CHILD8_ID:
        stateI = message.getBool();
        digitalWrite(RELAY_PIN8, stateI ? RELAY_ON : RELAY_OFF);
        saveState(CHILD8_ID, stateI);
        break;

      case CHILD9_ID:
        stateJ = message.getBool();
        digitalWrite(RELAY_PIN9, stateJ ? RELAY_ON : RELAY_OFF);
        saveState(CHILD9_ID, stateJ);
        break;  //10
         
      case CHILD10_ID:
        stateK = message.getBool();
        digitalWrite(RELAY_PIN10, stateK ? RELAY_ON : RELAY_OFF);
        saveState(CHILD10_ID, stateK);
        break;
        
      case CHILD11_ID:
        stateL = message.getBool();
        digitalWrite(RELAY_PIN11, stateL ? RELAY_ON : RELAY_OFF);
        saveState(CHILD11_ID, stateL);
        break;

      case CHILD12_ID:
        stateM = message.getBool();
        digitalWrite(RELAY_PIN12, stateM ? RELAY_ON : RELAY_OFF);
        saveState(CHILD12_ID, stateM);
        break;
        
      case CHILD13_ID:
        stateN = message.getBool();
        digitalWrite(RELAY_PIN13, stateN ? RELAY_ON : RELAY_OFF);
        saveState(CHILD13_ID, stateN);
        break;

      case CHILD14_ID:
        stateO = message.getBool();
        digitalWrite(RELAY_PIN14, stateO ? RELAY_ON : RELAY_OFF);
        saveState(CHILD14_ID, stateO);
        break;  //15
           
      case CHILD15_ID:
        stateP = message.getBool();
        digitalWrite(RELAY_PIN15, stateP ? RELAY_ON : RELAY_OFF);
        saveState(CHILD15_ID, stateP);
        break;
        
      case CHILD16_ID:
        stateR = message.getBool();
        digitalWrite(RELAY_PIN16, stateR ? RELAY_ON : RELAY_OFF);
        saveState(CHILD16_ID, stateR);
        break;

      case CHILD17_ID:
        stateS = message.getBool();
        digitalWrite(RELAY_PIN17, stateS ? RELAY_ON : RELAY_OFF);
        saveState(CHILD17_ID, stateS);
        break;
        
      case CHILD18_ID:
        stateT = message.getBool();
        digitalWrite(RELAY_PIN18, stateT ? RELAY_ON : RELAY_OFF);
        saveState(CHILD18_ID, stateT);
        break;

      case CHILD19_ID:
        stateW = message.getBool();
        digitalWrite(RELAY_PIN19, stateW ? RELAY_ON : RELAY_OFF);
        saveState(CHILD19_ID, stateW);
        break;  //20
        
      case CHILD20_ID:
        stateX = message.getBool();
        digitalWrite(RELAY_PIN20, stateX ? RELAY_ON : RELAY_OFF);
        saveState(CHILD20_ID, stateX);
        break;
        
    }
    
    // Write some debug info
   /* Serial.print("Incoming change for sensor:");
    Serial.print(message.sensor);
    Serial.print(", New status: ");
    Serial.println(message.getBool());
    */
    
  }
    if (message.type == V_STATUS) {
    if (!initialValueSent) {
      Serial.println("Receiving initial value from controller");
      initialValueSent = true;
      }
    }
    
}

Będę wdzięczny za każdą pomoc

Pętla loop zaczyna się od wysyłania danych do kontrolera ale wyłączyłeś odpytywanie request(CHILD0_ID, V_STATUS);
więc za każdym wykonaniem pętli loop będą wysyłane dane do kontrolera do czasu aż choć raz nie zapytasz o dane albo zostanie wysłany rozkaz z kontrolera

Dziękuje bardzo za podpowiedz pomogło :slight_smile:
Ale dodałem tylko jeden request(CHILD20_ID, V_STATUS); bo jak dodawałem dla każdego CHILD to przestawały działać fizyczne przyciski
Mam jeszcze jedno pytanko mam dodane #define MY_NODE_ID 97 a i tak w home assistant zgłasza się jako 0 wiec nie wiem do czego służy #define MY_NODE_ID 97