Sync button in app with relay status

It is one function in the code an one timer in setup that attatched to that. Thats my relay.

I do not set the time to ten minutes when testing. Then i will grow old before my project is finnished.

1 Like

I assume you mean this function…

I’m not really sure what you expect this to do.
Are you doing a Blynk.virtualWrite to V1 expecting it to trigger the BKYNK_WRITE(V1) callback and turn off the relay?
If so then this won’t work, as BLYNK_WRITE(V1) won’t be triggered when V1 is updated via a Blynk.virtualWrite from your code. All it will do is to update the status of your button attached to V1. To torn the relay off you need to do a digitalWrite(coffeeSwitch, HIGH) as well as the Blynk.viirtualWrite(V1).

If this isn’t your issue then maybe you can explain in more specific terms.


Thanks :slight_smile:

I will check that.

But do i need to use the “BLYNK_WRITE(V1)” in the code, when i can put all in that function?

“In code” and “that function” could be interpreted in many ways. What EXACTLY is your question?


In my code i have booth BLYNK_WRITE(V1) and void buttonUpdate(). Do i need to use booth in my situation?

By the way, i think i’m going to figure it out on my own. I have seen several videos of other doing it and i just feel that i do not get any help here. Look at the video i posted over. I want to do that. But you claim it not possible.

It’s also an language barriere here. Therfore i keep my self short. My explanation is possible not the best because of that, but i did not feel you even tries to help me here.

So because of that, i’m going to ask for help other places. I’m going to post the finished code in here when i finished for eventually help others.

Ahh, I thought you just wanted feedback of the GPIO state. Just because the relay coil power is OFF does not mean the signal GPIO is also OFF (or ON if using an active LOW relay).

And of course losing power to the Wemos means NO coded routines will work :stuck_out_tongue:

If you want actual relay status, then you need additional hardware to monitor the relay coil current draw (of lack) and feed that state back to yet another GPIO and use that to adjust a switch state, error status indicator, or whatever.

Or perhaps something on whatever your relay is running… not as safe to wire up when dealing with AC, but possible with an AC to logic level hall effect current sensor.

Okay. I have an scenario.

Let’s say i’m on work, 500 miles from home. On my way home i start the coffee maker from the app. On the way home something happens that takes up my time. The 10 minute timer runs out and the coffee maker turns off.

I still want the coffee to be hot when i’m home so i want to turn it on again, but i’m not really shure the ten minutes has gone and the button in app still says “ON” (No feedback)

I want to be absolutely sure that button shows me the right state of the relay. ON when ON and OFF when OFF.

I know that if i loose power in the house where coffe maker is, the relay shuts down the coffee maker. Without power, no hot coffee (or other things).

My main problem i think, if i loose wifi after turing on the coffee maker and can’t get feedback of the state to the app. How can i code to prevent that?

1 Like

The sensible code flow would be:
Change the relay status with a digitalWrite
Change the Blynk widget status with a virtualWrite
Output a message to the serial monitor with a serial print.

It makes sense to do all of these in the same place, rather in different functions within the code.

I assume from this statement that the video you posted was made by someone else? That wasn’t clear from what you said - I assumed that it was your video, which I probably why I didn’t understand the issue,

I’ve not claimed that what happens in the video isn’t possible (it clearly is, and I do the same thing every day). What I said is that Blynk has no server-side method for updating widgets when a device goes offline, and that updating a widget in the case of a failure of the mains supply to the appliance being controlled by a relay would require additional hardware and code.

Figuring things out for yourself is ultimately the best way. It’s how most of us have learned the things we know. Documentation, sketch builder and other forum posts are a great way of figure things out, but often asking a question will save a lot of time.
If English isn’t your first language and you’re not explaining things well because of that then I’d rather see people use their own language to explain properly. Online translators generally do a pretty good job these days.

This is post 27 in this topic, and I’ve personally spent a lot of time trying to understand your issue. If anything, I’d say that you haven’t tried hard enough to explain what it is that you’re trying to achieve,

There is a reason why Blynk has its own forum. Most C++ coders don’t understand what Blynk is, how it works, and how to use the commands available in the Blynk library. The sensible question for them to ask would be “does Blynk have its own support forum, and if so why don’t you ask your question there?”

Anyway, good luck with your problem, whatever it actually is,



If this is all you I would do a Lambda timer in the BLYNK_WRITE function.

if param.asInt()
    digitalWrite(coffeemaker, LOW);
    timer.setTimeout(600000, []()              //will execute the following after 10mins
         digitalWrite(coffeemaker, HIGH);
         Blynk.virtualWrite(V1, LOW);          //turns the button off on the app

That idea look up Lambda timer for proper syntax.

Is this what you’re looking for?

That code didn’t work.

I think i’m going to try in another forum and see if someone there can help me.

Thanks for all help so far btw.

This is the only Blynk forum :stuck_out_tongue:

But then as I already suspect, your issue (as confusing as it is) is not solvable by code alone, at least not as you explain it.

So, assuming starting and monitoring the coffee maker, after work and while on your 500 mile commute home, is really worth it… :rofl: … perhaps look at hiring someone to wire it for you as well as code it?

Time will show :slight_smile:

I will post the code here when i make it work :slight_smile:

That is fine… perhaps then we will also understand exactly what you are looking for :slight_smile:

1 Like

Good luck with any forum where you post a comment like that without any further explanation.

The guys over at are very nice, and have lots of patience :dizzy_face:


By the way.

Read my first post. Remove the part with button update when powerloss etc.

I just want th button in the app to give me the "“OFF” status to the button when relay do not power my coffee maker.

I do not want my coffe maker to be on when i lose connection. I want to alway now that if something happens thats wrong, that is turns off.

And that is the key… NO connection = NO notifications, NO button state change, NO awareness of what is happening with the relay… and possibly NO house :coffee: :fire: :house:

Not that you have seemingly appreciated any of our attempts to assist… I recommend you start from ground up with your project (before needing to do same with house :stuck_out_tongue_winking_eye: ) and implement a “keeps running without Blynk connection” routine that has fail safes built in, along with electrical/mechanical solutions that WILL shut off everything in case of disconnection to server (assuming whatever shutdown the device communication didn’t also shut off the coffee maker).


Sorry, I’ve been there myself. Unable to explain my issue, unable to understand the advice, code. Very frustrating. There’s an old adage “if at first you don’t succeed try, try again”. Often I’ve gone on to something else and built my knowledge and later I realize the solution.

1 Like

Ok. let’s keep it simple for now…

Lets say i just want the button to show “OFF” when the timer shuts down the Coffee maker after 10 minutes.

Now, it’s just shows “ON” after i turned the Cofee maker on from the app and it shuts down after 10 minutes.

Probably because you coded somthing incorrectly, are not using ONLY virtual pins (mixing in some direct GPIO widgets), or some other strangeness…

Then that timed function code has already been provided above by @daveblynk

  • BLYNK_WRITE(vPin) functions are called when a Widget using that vPin changes state.

  • Blynk.virtualWrite(vPin, state) can change that widgets state (without again calling the function.

And sometimes this command is handy to let the code update and/or almost act like it is controlling itself. Good for when the device code makes programmed changes, instead of you pushing buttons on the App…

  • Blynk.syncVirtual(vPin) with cause the server to call the BLYNK_WRITE(vPin) function with the current state of the vPin.

Combos of these commands, along with other code, can do all the things while providing feedback as required (assuming MCU, Server and App are properly connected of course).

Anyhow… I feel my sanity slipping :crazy_face: … time to binge on Netflix for another long forum free break :wink:

Are you using virtual button on switch mode? If you’re not sure post a snapshot of your app button settings.