This is the code that I could manage.
- I am using WEMOS D1 mini and a 6 channel relay board.
- I want to control all the 6 channels separately
- Alexa and blynk app, both would be used to control the 6 channel relay
Will this work?
UPDATE: IT WORKS
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <WiFiManager.h>
#include <ESP8266WebServer.h>
#include <BlynkSimpleEsp8266.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include "WemoSwitch.h"
#include "WemoManager.h"
#include "CallbackFunction.h"
char auth[] = "19be8f39f3f24ddca102c396d7506f07";
//on/off callbacks
void bedroomlightson();
void bedroomlightsoff();
void loungelightson();
void loungelightsoff();
void gymlightson();
void gymlightsoff();
void tvon();
void tvoff();
void chargeron();
void chargeroff();
void switch1on();
void switch1off();
WemoManager wemoManager;
WemoSwitch *bedroomlights = NULL;
WemoSwitch *loungelights = NULL;
WemoSwitch *gymlights = NULL;
WemoSwitch *tv = NULL;
WemoSwitch *charger = NULL;
WemoSwitch *switch1 = NULL;
const int RelayPin1 = D4;
const int RelayPin2 = D7;
const int RelayPin3 = D6;
const int RelayPin4 = D5;
const int RelayPin5 = D0;
const int RelayPin6 = D1;
void setup(){
pinMode(RelayPin1, OUTPUT);
digitalWrite(RelayPin1, LOW); // Turn relay OFF when unit is powered on
pinMode(RelayPin2, OUTPUT);
digitalWrite(RelayPin2, LOW); // Turn relay OFF when unit is powered on
pinMode(RelayPin3, OUTPUT);
digitalWrite(RelayPin3, LOW); // Turn relay OFF when unit is powered on
pinMode(RelayPin4, OUTPUT);
digitalWrite(RelayPin4, LOW); // Turn relay OFF when unit is powered on
pinMode(RelayPin5, OUTPUT);
digitalWrite(RelayPin5, LOW); // Turn relay OFF when unit is powered on
pinMode(RelayPin6, OUTPUT);
digitalWrite(RelayPin6, LOW); // Turn relay OFF when unit is powered on
Serial.begin(9600);
WiFiManager wifi; //WiFiManager intialization.
wifi.autoConnect("FakeWemo"); //Create AP, if necessary
wemoManager.begin();
// Format: Alexa invocation name, local port no, on callback, off callback
bedroomlights = new WemoSwitch("bedroom lights", 80, bedroomlightson, bedroomlightsoff);
loungelights = new WemoSwitch("lounge lights", 81, loungelightson, loungelightsoff);
gymlights = new WemoSwitch("gym lights", 82, gymlightson, gymlightsoff);
tv = new WemoSwitch("tv", 83, tvon, tvoff);
charger = new WemoSwitch("charger", 84, chargeron, chargeroff);
switch1 = new WemoSwitch("switch 1", 85, switch1on, switch1off);
wemoManager.addDevice(*bedroomlights);
wemoManager.addDevice(*loungelights);
wemoManager.addDevice(*gymlights);
wemoManager.addDevice(*tv);
wemoManager.addDevice(*charger);
wemoManager.addDevice(*switch1);
Blynk.config(auth);
ArduinoOTA.begin();
}
// Toggle the relay on
void bedroomlightson()
{
digitalWrite(RelayPin1, HIGH);
Blynk.virtualWrite(V1, HIGH); // Sync the Blynk button widget state
}
void loungelightson()
{
digitalWrite(RelayPin2, HIGH);
Blynk.virtualWrite(V2, HIGH); // Sync the Blynk button widget state
}
void gymlightson()
{
digitalWrite(RelayPin3, HIGH);
Blynk.virtualWrite(V3, HIGH); // Sync the Blynk button widget state
}
void tvon()
{
digitalWrite(RelayPin4, HIGH);
Blynk.virtualWrite(V4, HIGH); // Sync the Blynk button widget state
}
void chargeron()
{
digitalWrite(RelayPin5, HIGH);
Blynk.virtualWrite(V5, HIGH); // Sync the Blynk button widget state
}
void switch1on()
{
digitalWrite(RelayPin6, HIGH);
Blynk.virtualWrite(V6, HIGH); // Sync the Blynk button widget state
}
// Toggle the relay off
void bedroomlightsoff()
{
digitalWrite(RelayPin1, LOW);
Blynk.virtualWrite(V1, LOW); // Sync the Blynk button widget state
}
void loungelightsoff()
{
digitalWrite(RelayPin2, LOW);
Blynk.virtualWrite(V2, LOW); // Sync the Blynk button widget state
}
void gymlightsoff()
{
digitalWrite(RelayPin3, LOW);
Blynk.virtualWrite(V3, LOW); // Sync the Blynk button widget state
}
void tvoff()
{
digitalWrite(RelayPin4, LOW);
Blynk.virtualWrite(V4, LOW); // Sync the Blynk button widget state
}
void chargeroff()
{
digitalWrite(RelayPin5, LOW);
Blynk.virtualWrite(V5, LOW); // Sync the Blynk button widget state
}
void switch1off()
{
digitalWrite(RelayPin6, LOW);
Blynk.virtualWrite(V6, LOW); // Sync the Blynk button widget state
}
// Handle switch changes originating on the Blynk app
BLYNK_WRITE(V1){
int SwitchStatus1 = param.asInt();
if (SwitchStatus1 == 1) {
digitalWrite(RelayPin1, LOW);
}
else {
digitalWrite(RelayPin1, HIGH);
}
}
BLYNK_WRITE(V2){
int SwitchStatus2 = param.asInt();
if (SwitchStatus2 == 1) {
digitalWrite(RelayPin2, LOW);
}
else {
digitalWrite(RelayPin2, HIGH);
}
}
BLYNK_WRITE(V3){
int SwitchStatus3 = param.asInt();
if (SwitchStatus3 == 1) {
digitalWrite(RelayPin3, LOW);
}
else {
digitalWrite(RelayPin3, HIGH);
}
}
BLYNK_WRITE(V4){
int SwitchStatus4 = param.asInt();
if (SwitchStatus4 == 1) {
digitalWrite(RelayPin4, LOW);
}
else {
digitalWrite(RelayPin4, HIGH);
}
}
BLYNK_WRITE(V5){
int SwitchStatus5 = param.asInt();
if (SwitchStatus5 == 1) {
digitalWrite(RelayPin5, LOW);
}
else {
digitalWrite(RelayPin5, HIGH);
}
}
BLYNK_WRITE(V6){
int SwitchStatus6 = param.asInt();
if (SwitchStatus6 == 1) {
digitalWrite(RelayPin6, LOW);
}
else {
digitalWrite(RelayPin6, HIGH);
}
}
void loop()
{
wemoManager.serverLoop();
Blynk.run();
ArduinoOTA.handle();
}