BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Help triggering a slider using webhooks

How do I control a slider with 4 states using webhooks? I would have controlsed the pins on the nodemcu directly but the physical pin controls 3 relays which is 3 states n d 4th is a combination of relay 1 and 2. With the slider I can achieve all four fan speeds. But I want to use webhooks. Pls help

I’d suggest that you start by providing some crucial information…

  1. Add details :
    • Hardware model + communication type. For example: Arduino UNO with Ethernet Shield
    • Smartphone OS (iOS or Android) + version
    • Blynk server or local server
    • Blynk Library version
    • Add your sketch code. :point_up:Code should be formatted as example below.

Simply paste your code between ``` If you don’t format your code, your topic can be deleted by moderators.

```cpp

Your code in here…

```

Screenshots of your widget setup would also be useful, as your description of a “slider with 4 states” is confusing. Do you mean a segmented switch widget?

Pete.

      • NodeMcu (esp8266 wifi)
      • Android v.8.1
      • Blynk server
    1. Blynk Library version 1.0.0 beta 3

                 CODE
      
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <WiFiClient.h>

BlynkTimer timer;

// Pins of Fan Regulator Knob
#define s1 13  //D7
#define s2 1//TX
#define s3 2  //D4
#define s4 3  //RX

// Pins of Relays
#define Speed1  5 //D1
#define Speed2 4 //D2
#define Speed4 14  //D5

// By default the mode is with_internet
int MODE = 0;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "...................";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "ADY";
char pass[] = "asdfghjkl";

bool speed1_flag = 1;
bool speed2_flag = 1;
bool speed3_flag = 1;
bool speed4_flag = 1;
bool speed0_flag = 1;


BLYNK_WRITE(V0)
{
  int fan_speed = param.asInt(); // assigning incoming value from pin V1 to a variable
  if (fan_speed == 0)
  {
    speed0();
  }
  if (fan_speed == 1)
  {
    speed1();
  }
  if (fan_speed == 2)
  {
    speed2();
  }
  if (fan_speed == 3)
  {
    speed3();
  }
  if (fan_speed == 4)
  {
    speed4();
  }
}


void setup()
{
  // put your setup code here, to run once:
  pinMode(s1, INPUT);
  pinMode(s2, INPUT);
  pinMode(s3, INPUT);
  pinMode(s4, INPUT);

  pinMode(Speed1, OUTPUT);
  pinMode(Speed2, OUTPUT);
  pinMode(Speed4, OUTPUT);

  Serial.begin(9600);
  WiFi.begin(ssid, pass);
  timer.setInterval(3000L, checkBlynk); // check if connected to Blynk server every 3 seconds
  Blynk.config(auth);//, ssid, pass);
}


void loop()
{

  if (WiFi.status() != WL_CONNECTED)
  {
    Serial.println("Not Connected");
  }
  else
  {
    Serial.println(" Connected");
    Blynk.run();
  }


  timer.run(); // Initiates SimpleTimer

  if (MODE == 0)
    with_internet();
  else
    without_internet();
  // put your main code here, to run repeatedly:
}


void with_internet()
{
  if (digitalRead(s1) == LOW && speed1_flag == 1)
  {
    speed1();
    Blynk.virtualWrite(V0, 1);
    Serial.println("SPEED 1");
    speed1_flag = 0;
    speed2_flag = 1;
    speed3_flag = 1;
    speed4_flag = 1;
    speed0_flag = 1;


  }
  if (digitalRead(s2) == LOW && digitalRead(s3) == HIGH && speed2_flag == 1)
  {
    speed2();
    Blynk.virtualWrite(V0, 2);
    Serial.println("SPEED 2");
    speed1_flag = 1;
    speed2_flag = 0;
    speed3_flag = 1;
    speed4_flag = 1;
    speed0_flag = 1;

  }
  if (digitalRead(s2) == LOW && digitalRead(s3) == LOW && speed3_flag == 1)
  {
    speed3();
    Blynk.virtualWrite(V0, 3);
    Serial.println("SPEED 3");
    speed1_flag = 1;
    speed2_flag = 1;
    speed3_flag = 0;
    speed4_flag = 1;
    speed0_flag = 1;
  }
  if (digitalRead(s4) == LOW  && speed4_flag == 1)
  {
    speed4();
    Blynk.virtualWrite(V0, 4);
    Serial.println("SPEED 4");
    speed1_flag = 1;
    speed2_flag = 1;
    speed3_flag = 1;
    speed4_flag = 0;
    speed0_flag = 1;
  }
  if (digitalRead(s1) == HIGH && digitalRead(s2) == HIGH && digitalRead(s3) == HIGH && digitalRead(s4) == HIGH  && speed0_flag == 1)
  {
    speed0();
    Blynk.virtualWrite(V0, 0);
    Serial.println("SPEED 0");
    speed1_flag = 1;
    speed2_flag = 1;
    speed3_flag = 1;
    speed4_flag = 1;
    speed0_flag = 0;
  }
}


void without_internet()
{
  if (digitalRead(s1) == LOW && speed1_flag == 1)
  {
    speed1();

    Serial.println("SPEED 1");
    speed1_flag = 0;
    speed2_flag = 1;
    speed3_flag = 1;
    speed4_flag = 1;
    speed0_flag = 1;


  }
  if (digitalRead(s2) == LOW && digitalRead(s3) == HIGH && speed2_flag == 1)
  {
    speed2();

    Serial.println("SPEED 2");
    speed1_flag = 1;
    speed2_flag = 0;
    speed3_flag = 1;
    speed4_flag = 1;
    speed0_flag = 1;

  }
  if (digitalRead(s2) == LOW && digitalRead(s3) == LOW && speed3_flag == 1)
  {
    speed3();

    Serial.println("SPEED 3");
    speed1_flag = 1;
    speed2_flag = 1;
    speed3_flag = 0;
    speed4_flag = 1;
    speed0_flag = 1;
  }
  if (digitalRead(s4) == LOW  && speed4_flag == 1)
  {
    speed4();

    Serial.println("SPEED 4");
    speed1_flag = 1;
    speed2_flag = 1;
    speed3_flag = 1;
    speed4_flag = 0;
    speed0_flag = 1;
  }
  if (digitalRead(s1) == HIGH && digitalRead(s2) == HIGH && digitalRead(s3) == HIGH && digitalRead(s4) == HIGH  && speed0_flag == 1)
  {
    speed0();

    Serial.println("SPEED 0");
    speed1_flag = 1;
    speed2_flag = 1;
    speed3_flag = 1;
    speed4_flag = 1;
    speed0_flag = 0;
  }
}


void speed0()
{
  digitalWrite(Speed1, HIGH);
  digitalWrite(Speed2, HIGH);
  digitalWrite(Speed4, HIGH);

}

void speed1()
{
  //Speed1 Relay On - Fan at speed 1

  digitalWrite(Speed1, HIGH);
  digitalWrite(Speed2, HIGH);
  digitalWrite(Speed4, HIGH);
  delay(500);
  digitalWrite(Speed1, LOW);
}

void speed2()
{
  //Speed2 Relay On - Fan at speed 2

  digitalWrite(Speed1, HIGH);
  digitalWrite(Speed2, HIGH);
  digitalWrite(Speed4, HIGH);
  delay(500);
  digitalWrite(Speed2, LOW);
}

void speed3()
{
  //Speed1 & Speed2 Relays On - Fan at speed 3

  digitalWrite(Speed1, HIGH);
  digitalWrite(Speed2, HIGH);
  digitalWrite(Speed4, HIGH);
  delay(500);
  digitalWrite(Speed1, LOW);
  digitalWrite(Speed2, LOW);

}

void speed4()
{
  //Speed4 Relay On - Fan at speed 4

  digitalWrite(Speed1, HIGH);
  digitalWrite(Speed2, HIGH);
  digitalWrite(Speed4, HIGH);
  delay(500);
  digitalWrite(Speed4, LOW);
}

void checkBlynk()
{
  bool isconnected = Blynk.connected();
  if (isconnected == false)
  {
    MODE = 1;
  }
  if (isconnected == true)
  {
    MODE = 0;
  }
}

You should be using library version 0.6.1

You screenshot doesn’t show how your slider widget is configured.
If it is connected to a digital pin then You should use virtual pins instead, which will remove the need to use webhooks (unless there is more to the project that you’ve not told us about).

Pete.

I am a new user and I was promoted that I could only upload one media file. The slider uses virtual pin V0. The slider has 4 positions ,. My questions is "is it possible to address those slider positions individually on webhooks? Cos I want to integrate Alexa voice commands to the project

The Blynk Webhooks widget isn’t going to help you with Alexa integration.

It’s very simple to change the slider position using an API call to update the V0 value to 0,1,2,3 or 4 (five positions, not four as you stated).

What 3rd party integration tool are you using?
If it’s IFTTT then a quick search of the forum will give you all the information you require to get this working.

Pete.

Wow thank you sir this has given me an insight as I was thinking I could only send 0 or 1