Hello I got the problem like on the video: switches animation ON-OFF-ON or OFF-ON-OFF in HA interface. is there i can do it about it? the video shows the problem. I used debounce node but didnt help ;/
got this function: it receives feedback from a relay board e.g. 0000 turn off 0001 turn on relay and animates the entity node in HA interface
const relays = [];
// loops through the 8 relays and creates a msg property
// object to send to the entity node to turn it on/off
for(let i = 0;i < 8;i++) {
relays[i] = {
// msg.payload.substr(i * 4, 4) same as you had original to parse out the string
// Number() converts the string '0001' or '0000' to a number 1 or 0
// !! convert the number to a boolean - true or false
enable: !!Number(msg.payload.substr(i * 4, 4))
}
}
// check if any really is on then sets the relayall to on
// if not to off
relays[8] = { enable: relays.every((r) => r.enable) };
return relays;
my loop () function in esp8266:
void loop() {
mb.task();
yield();
if (!client.connected()) {
reconnect();
}
client.loop();
// send msg with relays' statuses
long now = millis();
if (now - lastMsg > 2600) {
lastMsg = now;
mb.readHreg(SLAVE_ID, 0x0001, status, 8, cbWrite);
char buf[256] = { 0 };
for (int i = 0; i < 8; i++) {
sprintf(buf + strlen(buf), "%04X", status[i]);
Serial.println(buf);
}
client.publish("device1/relaysChannelStatus", buf);
}
}