Giter VIP home page Giter VIP logo

Comments (32)

kakopappa avatar kakopappa commented on August 9, 2024

Thanks

  1. I think you are thinking in terms of sonoff where there is a single relay to control AC. I made this project to control multiple relays connected to a single WeMos D1. For an example, I have a TV and a Fan connected to two power sockets so instead of using 2 WeMos D1s i just wanted to control both using a single WeMos D1. WeMos D1 has multiple IO pins. When you ask Alexa to discover devices, WeMos D1 will respond back as if two connected.

  2. Think you brought a WeMos D1 and a 4-Channel OMRON Solid-State-Relay (https://www.aliexpress.com/item/Sindax-5v-4-Channel-OMRON-SSR-G3MB-202P-Solid-State-Relay-Module-For-Arduino-z3-1pcs/32640442712.html) This gives you the power to control 4 mains by using 4 I/O pins in D1. So You can define 4 switches in the program to turn IO pins high or low accordingly to turn on/off

const int relayS1Pin = D1;
const int relayS2Pin = D2;
const int relayS3Pin = D3;
const int relayS4Pin = D4;

Switch *s1 = NULL;
Switch *s2 = NULL;
Switch *s3 = NULL;
Switch *s4 = NULL;

// Inside void setup() 
 pinMode(relayS1Pin, OUTPUT);
 pinMode(relayS2Pin, OUTPUT);
 pinMode(relayS3Pin, OUTPUT);
 pinMode(relayS4Pin, OUTPUT);

s1 = new Switch("office", 80, s1On, s1Off);
s2 = new Switch("kitchen", 81, s2On, s2Off);
s3 = new Switch("fan", 82, s3On, s23ff);
s4 = new Switch("tv", 83, s4On, s4Off);

upnpBroadcastResponder.addDevice(*s1);
upnpBroadcastResponder.addDevice(*s2);
upnpBroadcastResponder.addDevice(*s3);
upnpBroadcastResponder.addDevice(*s4);

....

void s1On() {
  digitalWrite(relayS1Pin, HIGH); // turn on relay with voltage HIGH 
}

void s1Off() {
  digitalWrite(relayS1Pin, LOW); // turn off relay with voltage HIGH 
}

void s2On() {

}

void s2Off() {

}

void s3On() {

}

void s3Off() {

}

void s4On() {

}

void s4Off() {

}
  1. Download the whole folder and open wemos.ino in Arduino IDE. It will open all the other files. Then compile.

from arduino-esp8266-alexa-multiple-wemo-switch.

joeman2116 avatar joeman2116 commented on August 9, 2024

That info helped.
I was able to compile and add a new switch --- working very cool!

I was wondering if there any way to see the status of the devices on a browers?

Thanks again...
Great talent , appreciate you sharing.....

Joe

from arduino-esp8266-alexa-multiple-wemo-switch.

cobra85ec avatar cobra85ec commented on August 9, 2024

how do i change the pins i want to control

from arduino-esp8266-alexa-multiple-wemo-switch.

joeman2116 avatar joeman2116 commented on August 9, 2024

from arduino-esp8266-alexa-multiple-wemo-switch.

cobra85ec avatar cobra85ec commented on August 9, 2024

i dont see where that is....

from arduino-esp8266-alexa-multiple-wemo-switch.

joeman2116 avatar joeman2116 commented on August 9, 2024

from arduino-esp8266-alexa-multiple-wemo-switch.

cobra85ec avatar cobra85ec commented on August 9, 2024

multiple....

from arduino-esp8266-alexa-multiple-wemo-switch.

joeman2116 avatar joeman2116 commented on August 9, 2024

from arduino-esp8266-alexa-multiple-wemo-switch.

cobra85ec avatar cobra85ec commented on August 9, 2024

i did all that... i just dont know where to change the pins... in the single pin ,.... i was able to change it not problem... this one seems a bit harder...

from arduino-esp8266-alexa-multiple-wemo-switch.

joeman2116 avatar joeman2116 commented on August 9, 2024

from arduino-esp8266-alexa-multiple-wemo-switch.

cobra85ec avatar cobra85ec commented on August 9, 2024

yes it compiles... and thank u so mach... ill sen u a beer for ur help

from arduino-esp8266-alexa-multiple-wemo-switch.

joeman2116 avatar joeman2116 commented on August 9, 2024

from arduino-esp8266-alexa-multiple-wemo-switch.

cobra85ec avatar cobra85ec commented on August 9, 2024

this dont compiles

from arduino-esp8266-alexa-multiple-wemo-switch.

cobra85ec avatar cobra85ec commented on August 9, 2024

i change d1 to the pin i wanted and it say callback not defind in scope

from arduino-esp8266-alexa-multiple-wemo-switch.

joeman2116 avatar joeman2116 commented on August 9, 2024

from arduino-esp8266-alexa-multiple-wemo-switch.

joeman2116 avatar joeman2116 commented on August 9, 2024

from arduino-esp8266-alexa-multiple-wemo-switch.

cobra85ec avatar cobra85ec commented on August 9, 2024

i got it workking,,,, thank u very much......now how do i get u a beer...

from arduino-esp8266-alexa-multiple-wemo-switch.

joeman2116 avatar joeman2116 commented on August 9, 2024

from arduino-esp8266-alexa-multiple-wemo-switch.

cobra85ec avatar cobra85ec commented on August 9, 2024

man... im really happy with ur help.....thanks alot

from arduino-esp8266-alexa-multiple-wemo-switch.

joeman2116 avatar joeman2116 commented on August 9, 2024

from arduino-esp8266-alexa-multiple-wemo-switch.

VivekESP8266 avatar VivekESP8266 commented on August 9, 2024

Hi I too am not able to complie.
Can you please let me know how you resolved the D1 Not declared

from arduino-esp8266-alexa-multiple-wemo-switch.

kakopappa avatar kakopappa commented on August 9, 2024

@VivekESP8266 #14

from arduino-esp8266-alexa-multiple-wemo-switch.

VivekESP8266 avatar VivekESP8266 commented on August 9, 2024

Thank you.
Now compiling OK.
However can you please explain what the numbers 90, 91, 92,& 89 point to.
Also what are the numbers for the other 10 outputs
relay = new Switch("relay 1", 90, relayOn, relayOff);
relay2 = new Switch("relay 2", 91, relay2On, relay2Off);
relay5 = new Switch("relay 5", 92, relay5On, relay5Off);
// flex6 = new Switch("flex 6", 89, flex6On, flex6Off);

from arduino-esp8266-alexa-multiple-wemo-switch.

kakopappa avatar kakopappa commented on August 9, 2024

Numbers are refereed to a web server port started internally to respond to Alexa for each switch you define. You do not have to worry about them.

from arduino-esp8266-alexa-multiple-wemo-switch.

VivekESP8266 avatar VivekESP8266 commented on August 9, 2024

from arduino-esp8266-alexa-multiple-wemo-switch.

labbie48 avatar labbie48 commented on August 9, 2024

whenever I go to compile this I get the error:

invalid conversion from 'void ()()' to 'CallbackFunction {aka bool ()()}' [-fpermissive]

from arduino-esp8266-alexa-multiple-wemo-switch.

kakopappa avatar kakopappa commented on August 9, 2024

from arduino-esp8266-alexa-multiple-wemo-switch.

The-Great-One avatar The-Great-One commented on August 9, 2024

I tried to use your code on a nodemcu by modifying the required lines but the relays remain in high state irrespective of the command given. Here is my code:
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>
#include
#include "switch.h"
#include "UpnpBroadcastResponder.h"
#include "CallbackFunction.h"

// prototypes
boolean connectWifi();

//on/off callbacks
bool s1On();
bool s1Off();
bool s2On();
bool s2Off();
bool s3On();
bool s3Off();
bool s4On();
bool s4Off();

// Change this before you flash
const char* ssid = "2ndFLOOR";
const char* password = "books4ume";
const int relayS1Pin = 12;
const int relayS2Pin = 14;
const int relayS3Pin = 13;
const int relayS4Pin = 15;

boolean wifiConnected = false;

UpnpBroadcastResponder upnpBroadcastResponder;

Switch *s1 = NULL;
Switch *s2 = NULL;
Switch *s3 = NULL;
Switch *s4 = NULL;

bool iss1On = false;
bool iss2On = false;
bool iss3On = false;
bool iss4On = false;

void setup()
{
Serial.begin(9600);

// Initialise wifi connection
wifiConnected = connectWifi();

if(wifiConnected){
upnpBroadcastResponder.beginUdpMulticast();

// Inside void setup()
pinMode(relayS1Pin, OUTPUT);
pinMode(relayS2Pin, OUTPUT);
pinMode(relayS3Pin, OUTPUT);
pinMode(relayS4Pin, OUTPUT);
// Define your switches here. Max 10
// Format: Alexa invocation name, local port no, on callback, off callback
s1 = new Switch("office", 81, s1On, s1Off);
s2 = new Switch("kitchen", 90, s2On, s2Off);
s3 = new Switch("fan", 91, s3On, s3Off);
s4 = new Switch("tv", 92, s4On, s4Off);

Serial.println("Adding switches upnp broadcast responder");

upnpBroadcastResponder.addDevice(*s1);
upnpBroadcastResponder.addDevice(*s2);
upnpBroadcastResponder.addDevice(*s3);
upnpBroadcastResponder.addDevice(*s4);

}
}

void loop()
{
if(wifiConnected){
upnpBroadcastResponder.serverLoop();

  s1->serverLoop();
  s2->serverLoop();
  s3->serverLoop();
  s4->serverLoop();

}
}

bool s1On() {
Serial.println("Switch 1 turn on ...");

iss1On = true;    
return iss1On;

}

bool s1Off() {
Serial.println("Switch 1 turn off ...");

iss1On = false;
return iss1On;

}

bool s2On() {
Serial.println("Switch 2 turn on ...");

iss2On = true;
return iss2On;

}

bool s2Off() {
Serial.println("Switch 2 turn off ...");

iss2On = false;
return iss2On;
}

bool s3On() {
Serial.println("Switch 3 turn on ...");

iss3On = true;
return iss3On;

}

bool s3Off() {
Serial.println("Switch 3 turn off ...");

iss3On = false;
return iss3On;
}

bool s4On() {
Serial.println("Switch 4 turn on ...");

iss4On = true;
return iss4On;

}

bool s4Off() {
Serial.println("Switch 4 turn off ...");

iss4On = false;
return iss4On;
}

// connect to wifi – returns true if successful or false if not
boolean connectWifi(){
boolean state = true;
int i = 0;

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");

// Wait for connection
Serial.print("Connecting ...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (i > 10){
state = false;
break;
}
i++;
}

if (state){
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
else {
Serial.println("");
Serial.println("Connection failed.");
}

return state;
}

from arduino-esp8266-alexa-multiple-wemo-switch.

kakopappa avatar kakopappa commented on August 9, 2024

from arduino-esp8266-alexa-multiple-wemo-switch.

The-Great-One avatar The-Great-One commented on August 9, 2024

Thanks for your reply, I am not a programmer so could you just point out exactly what lines need to be modified. That would be great!

from arduino-esp8266-alexa-multiple-wemo-switch.

kakopappa avatar kakopappa commented on August 9, 2024

@flappypot

try to turn on / off the relay with an example first then move to Alexa.

https://arduinobasics.blogspot.com/2014/09/relay-module.html

bool s1On() {
Serial.println("Switch 1 turn on ...");
iss1On = true;
digitalWrite(relayS1Pin, HIGH);
return iss1On;
}

bool s1Off() {
Serial.println("Switch 1 turn off ...");
digitalWrite(relayS1Pin, LOW);
iss1On = false;
return iss1On;
}

from arduino-esp8266-alexa-multiple-wemo-switch.

The-Great-One avatar The-Great-One commented on August 9, 2024

@kakopappa

Thanks for your help. The code is working beautifully !!

from arduino-esp8266-alexa-multiple-wemo-switch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.