@Reza Your code isn´t easy to understand. More Comments within your code would be very helpful.
So I will try a little mind reading.....
Basic concept seems to be decoupling switches/pushbuttons from the relais part and to control the relais action through your controller.
Management of switches/pushbuttons is done in loop().
"Master of states" is your controller (software).
Actions are performed by receive().
At last a clean soloution - but some parts aren´t that clean.
The only reference to stateX is within receive() directly before digital_write(X). So any change to stateX from within the sketch will not have any effekt. So the introduction of the stateX variable isn´t actually necessary.
digitalWrite(message.sensor + 2, message.getBool() ? RELAY_ON : RELAY_OFF);
should work to. This eliminates thes risk of double originals which can get very tricky if things go wrong. (i.e. there should be only one set of stateX variables in your system because keeping copied sets tidy is a huge amount of work and prone to errors).
In the first part of loop() you try to instantiate some basic mechanisms to accomplish this mission but I fear it will not succeed.
Within loop you begin with a chain of modulo-operations which might be intended to send the state variable to your controller once every hour (?) with 1 second interval. This will fail eternally if your loop starts accidentally with millis() at xxxxxx1 and loop duration is xxxxxx2. The remainder of % operation will always be 1 (or more) but never zero. Precise timing down to 1 millisecond would be too critical to little errors and is not necessary.
Spacing send() to one second should not be necessary either - MySensors framework can deal with lot of send() in a row.
So maybe a statement like
if (millis() >= lasttime+INTERVALL) {.....}
could fit your needs. It isn´t that precise - but precise enough and robust.
if (trigger == 0) {...;trigger=1;}
This part is executed only once because you never reset trigger to zero. If you intend to reset your controller variables you might move this part to setup() - or better leave it to your controller.
But if you omit stateX copying this whole section could be skipped.
The rest of loop() consists of switch management which seems ok to me. Nevertheless a little proposal for optimisation:
send(msgA.set(stateA ? true : false), true);
There is no really need for the trinary operator ? because stateA is bool, it may be send directly like
send(msgA.set(stateA ), true);
debouncerA.update();
I am not very familiar with debounce(). But omitting "&&valueA==0" will cause your statement to react to pressing your button as well as to releasing your button. So this statement will act twice on one keystroke -- so far I remember the debounce() function.
Because stateA is not likely to be changed in this short amount of time, this statement will send stateA twice - which causes unnecessary traffic.
These are surely no crucial points but I think the sketch woud be more robust.
wdt_enable(WDTO_4S);
Please don´t do this - it may have terrible side effects and may make you mad while searching for errors.
So over all your sketch isn´t that bad for a first proof of concept and should be functional for your basic needs.
So missing send should be due to the qualitiy of your connection. Maybe a longer log of debug messages (both sides?) would be helpful.
.