I have struggled with this for hours now, an i just can’t get it to work.
So here is what i want:
I want to switch on/off an relay from blynk app. I have an ordinary ON/OFF button and so long all works fine. I can turn ON/OFF Relay. Jey!!
But i want the button to tell me the status of the relay. For example if i removes power from relay or it looses power etc.
When that happens i want the button state to change from ON to OFF.
I will also add an timer that turns off the relay after 10 minutes automaticly in code. That part i know how to do. But i also want the button to show OFF when timer turns off the relay.
Can somebody here help me with that?
Here is my code so far. It works, but without timer as i mentioned and the button status change.
In your timer you need a virtualWrite sending the relay state to Blynk. If you want to know the actual state of the relay get another “mains” relay hook the coil to the other relay. Run one pin from the Arduino through the contacts and when the contacts open virtualWrite that state to the Blynk app.
Perhaps a timed function like this? Untested, but should work.
void buttonupdate() {
Blynk.virtualWrite(V1, digitalRead(coffeeSwitch)); // If already the same state nothing really changes. If NOT same, vPin reverts to physical state
}
Either wait for other check timer to run… or simply add this to your “turn off physical pin” function…
Blynk.virtualWrite(V1,0); // EDIT - Or 1 if relay is Active Low
I have tried som more now and reversed the values etc. I just can’t get the button to sync with relay status. When i power off my Wemos the button in app stil says the relay is high…
The current version of Blynk doesn’t have any server-side functionality that enables widget values to be updated if the hardware goes offline. The only functionality is the alert at the top of the app that tells you that the device is offline.
I still don’t see the 10 minute relay thing you referred to, and it seems that you’re talking about a system where power is lost to your Wemos or relay.
As I said earlier, Blynk has no server-side process for changing widget values when your Wemos goes offline.
If there is a scenario where the mains power to the device controlled by the relay goes off, but the Wemos is still online, then you’d need to be monitoring power consumption or supply voltage to identify this.