flic2hass
flic2hass copied to clipboard
It all happens too fast!
The signal to ok happen so quickly that if you trigger an automation in HA, the value is no longer in the sensor. I am wondering if there is a way to put a delay in between the signal of the push and the ok message.
I made this change...
console.log(btntopic+"/battery: \t"+button.batteryStatus);
sleep(2500);
mqtt.publish(btntopic + "/action", "ok");
});
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
Why do you find a delay to be necessary?
My Home Assistant actions are activated on the transitions, so I'm not sure why you would want to check state if it's the state change that caused the event?
Now that Home Assistant 2023.8 will have UI-enabled Event triggers, I'm thinking of supporting those in the next release. That should hopefully be a better fix than adding delays.
Why I want this is because in my setup it happens so fast that by the time an automation is triggered the value of the button has returned to ok after about 1-2 steps. To make my life easier I created component automations that branch on the value...of it is just "ok" they dont work and it makes my scripts way more complex.