Node-Red - Blynk - MQTT (Dark side)

Well after thinking about it I decided to learn node-red and work together with blynk to make an all-in-1 dashboard as I always wanted and thus continue using BLYNK as a backend.

I have a query I did something basic to start learning.

Create a topic with mqtt “casa/habitaciones/cuartokevin/luz” inside node-red, that topic I send to the write event of node iot.

Then i use MQTTX for make pub to that topic node-red recive all its ok but

In the blynk dashboard and the mobile app the “PIN” is updated but does not do the typical blynk function:

   livingstatus = param.asInt ();
   digitalWrite (luzliving, estaoluzliving);
   Blynk.virtualWrite (V50, luzlivingstate);

For the relay to activate.

I don’t know what I’m doing wrong or that is where I started with the left foot, I saw many videos where they used the arduino to create the SUBs, I don’t know if that’s the case? or as if someone could give me a BASIC example, that’s where I start.


In screens if any can see “Switch Luz Living” updated, but i think blynk code from arduino dont digitalwrite to relay.

Arduino Code:

#define BLYNK_DEVICE_NAME "Living"

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
#include <RCSwitch.h>

AsyncWebServer server(80);

RCSwitch ReceptorRF = RCSwitch();

IPAddress local_IP(192, 168, 1, 228);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8);
IPAddress secondaryDNS(8, 8, 4, 4);

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "";
char pass[] = "";

const int timbre = D7;
const int btntimbre = D8;

const int btnluzliving = D13;
const int luzliving = D6;
const int luzgarage = D4;

int estadotimbre = LOW;
int estadobtntimbre = LOW;
int estadobtnluzliving = LOW;
int estadoluzliving = LOW;
int estadoluzgarage = LOW;

BlynkTimer timer;
void CheckBotonTimbre();
void CheckBotonLuzLiving();


  estadoluzliving = param.asInt();
  digitalWrite(luzliving, estadoluzliving);
  Blynk.virtualWrite(V50, estadoluzliving);
  estadoluzgarage = param.asInt();
  digitalWrite(luzgarage, estadoluzgarage);
  estadotimbre = param.asInt();
  digitalWrite(timbre, estadotimbre);

void CheckBotonTimbre()
  if (digitalRead(btntimbre) == LOW) {
    if (estadobtntimbre != LOW) {
      estadotimbre = !estadotimbre;
    estadobtntimbre = LOW;
  } else {
    estadobtntimbre = HIGH;

void CheckBotonLuzLiving()
  if (digitalRead(btnluzliving) == LOW) {
    if (estadobtnluzliving != LOW) {
      estadoluzliving = !estadoluzliving;
      digitalWrite(luzliving, estadoluzliving);
      Blynk.virtualWrite(V0, estadoluzliving);
    estadobtnluzliving = LOW;
  } else {
    estadobtnluzliving = HIGH;

void SonarTimbre()
  digitalWrite(timbre, LOW);
  Blynk.virtualWrite(V2, LOW);
  timer.setTimeout(500L, ApagarTimbre);

void ApagarTimbre()
  digitalWrite(timbre, HIGH);
  Blynk.virtualWrite(V2, HIGH);

void setup()

  // Debug console
  if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    Serial.println("STA Failed to configure");

  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {

  Serial.print("WiFi: ");
  Serial.print("Direccion IP: ");

  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(200, "text/plain", "Hola, Devs Home Automation V1.2 - Wemos Living");


  pinMode(luzliving, OUTPUT);
  pinMode(luzgarage, OUTPUT);
  pinMode(timbre, OUTPUT);

  pinMode(btntimbre, INPUT_PULLUP);
  pinMode(btnluzliving, INPUT_PULLUP);

  timer.setInterval(100L, CheckBotonTimbre);
  timer.setInterval(200L, CheckBotonLuzLiving);

  digitalWrite(timbre, HIGH);


void loop()

That’s the normal behaviour.
A Blynk.virtualWrite(vPin,value) command in a C++ sketch doesn’t trigger the corresponding BLYNK_WRITE(vPin) callback function to trigger, and it’s the same when using Node-Red.
In C++, if you wanted the BLYNK_WRITE(vPin) callback to trigger you’d need to use a Blynk.suncVirtual(vPin) command top get the server to send the latest value for the vPin, triggering the BLYNK_WRITE(vPin) callback, and it’s the same with Node-Red.

In Node-Red you could do this…

Which is the C++ version of


In C++ this will cause the server to send-back the value you’ve just written to V0, triggering BLYNK_WRITE(V0)

However, that’s approaching the problem in the wrong way in my opinion.
I don’t run any Blynk code on my devices. My device code connects to WiFi and to the MQTT server. It then subscribes to a series of MQTT topics, and publishes data to a number of other topics.
The subscriptions are a bit like BLYNK_WRITE(vPin) callbacks. They are triggered when data is written to those topics, and the value(s) written to those topics are extracted, in a similar way to using param.asInt(), and you then take the appropriate actions (such as turning on a relay) depending on what value was sent.

I guess that should be MQTT.fx ?
My preferred MQTT tool is MQTT Explorer…

it makes viewing and publishing test values to topics much easier than MQTT.fx

This is the sort of information that I publish via MQTT regarding each device…


The RSSI, Free RAM, and Uptime is update around every 5 seconds and the rest of the data is either published at boot time with the MQTT Retain flag set, or updated when it changes.

There’s more info my approach here…


Thx for your time pete.

What about automations ?
you just use Arduino NodeRed & MQTT ? its good idea but i need see codes for do this.

Thx when i come back from my work i gonna read all ur post and check all things!

OH, where are u from ?

Node-Red is far more powerful than Blynk automations at the moment. If you want to trigger event x when condition y is met then that’s very simple in Node-Red. If you want to do scheduling then contribs like Big Timer offer extremely powerful scheduling that can be overridden by inputs from the Blynk dashboard very easily.

I live in London, but we have a holiday home in Spain and I use Node-Red and Blynk to allow me to monitor and control things when I’m away from home.


1 Like


I just wanted to “confirm” the greatness of Node-RED for home automation.
I have been thinking about it for a long time and was finally pushed by Pete to “jump”. Thanks for that.

Node -RED has become my new “central” where everything is controlled. It is superior in integrating different systems, including my own ESP-systems. Most often via MQTT, sometimes via REST api’s or other ways.
And it also features a “true” dashboard which i want.

What is not so good, is lack of an app. But, is here blynk comes in. Just send from node-red to blynk to display. And, of course, send back push Buttons etc.
In other words, use blynk as an app for Node-red.

This is the way i am going for my private home automation system.

// All runs on a raspberry pi 4, mosquitto mqtt and node-red. Soon to be added is an external SSD, influx dB and grafana. ( Node-red seems to get very slow when you have lots of data to plot in graphs, which i hope influx/grafana will solve. )

1 Like

I’m glad that we have another convert to the dark side!

I agree with everything you’ve said, except…

I’ve tried several times to like the Node-Red dashboard, but I just can’t bring myself to use it.
It’s the only thing I don’t like about N-R though.

The external SSD is a great move, because the SD cards have a limited life and are slow.

I also like to use WebMin as a web-based admin system for my Pi, it makes some operations - such as monitoring memory and disk space, and installing updates - very easy…

I also run ZeroTier, which lets me have remote access to both of my HA systems (one in the UK and one in Spain) from anywhere in the world without any drama.


1 Like

I dont think dashboard is too bad. This is the dashboard on a tablet (screenshot from desktop) on the wall in the hallway. (Then I have other small TFT screens controlled by my own d1 minis showing just room temp and possible up-down-arrows etc.)

1 Like