Esp8266 as a switch in vera

Hi,

I quite good at programming, but never really done it with luup, plugins etc… But i have a small thing i want my Vera to do…

I want esp8266 with a relay to be controlled as a switch in Vera… Because then i can use homekit/homebridge to control with my I-devices… I know Mysensors and have worked with it a lot, but cant really to get it to work as a switch/light device i Vera… I have googled for 2 month now, and now i have to ask you guys for help… I code the esp’s with arduino, its what i have coded in before :slight_smile:

Im very interested in espeasy, because its so easy to work with, sensors etc, so the perfect match would to let espeasy and vera work together :slight_smile:

Hope someone can help me with my little project

Regards,
Jan

Hi

i also started to use NodeMCU / ESP8266 with Vera. there is standard code in Arduino IDE to let the ESP8266 switch outputs via VERA interface or Vera app.

i also shared my experience on wiring the doorbell into Vera via ESP8266
http://forum.micasaverde.com/index.php/topic,38880.0.html

i can post the code to drive a switch via Vera? or did you already make progres…

@Otje,
Can you please post the code?

Thanks in advance.

Hello,
Here is another way to program ESP8266.
[url=http://www.touteladomotique.com/forum/viewtopic.php?f=6&t=18720]http://www.touteladomotique.com/forum/viewtopic.php?f=6&t=18720[/url]

I can develop how to interact with Vera if needed

Hi

sorry for delay, i was abroad.

i wired the doorbell to the ESPmodule and i used Arduino to program the ESP. i will show the code below.
I made a scene in VERA to send an email in case some one presses the front door bell and i attach a snapshot picture from a IP camera as well. i use a virtual switch in Vera to get it triggered but i guess it could also work without, you can call a scene directly from ESP, thats up to you.
it works fine, it works always, i never have to reboot this ESP. it is great

Arduino / ESP code:

#include <ESP8266WiFi.h>

const char* ssid = “my_network”;
const char* password = “my_password”;
const char* host = “192.168.0.xx”; //this is the IP adress of our VERA
int buttonState = 0;

void setup() {
Serial.begin(115200);
delay(10);
pinMode(2, INPUT); //the doorswitch is connected to GPIO 2
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(”.”);
}
Serial.println(“”);
Serial.println(“WiFi connected”);
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(2);

// check if doorbell is pressed
// if not then status is HIGH:
if (buttonState == HIGH) {
//Serial.println("Doorbell is not activated ");

} else {
// the doorbell is pressed:
Serial.println("Doorbell activated ");
Serial.print("connecting to ");
Serial.println(host);

// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 3480;
if (!client.connect(host, httpPort)) {
Serial.println(“connection failed”);
return;
}
// We now create a URI for the request
String url = “/data_request?id=lu_action&DeviceNum=182&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1”;

Serial.print("Requesting URL: ");
Serial.println(url);

// This will send the request to the server
client.print(String("GET “) + url + " HTTP/1.1\r\n” +
"Host: " + host + “\r\n” +
“Connection: close\r\n\r\n”);
Serial.println();
Serial.println(“closing connection”);
delay(2000);

}
}

1 Like

Thanks for posting the code. I’m going to do some experimenting with it.

You have some “” quotes different that Compiler doesn’t recognize. Had to copy and paste it in notepad and replace your quotes with mines and it worked !. Thanks anyway for posting !!!

1 Like

Hi, thats strange, as it worked in my arduino compiler but thanks anyway and hope it all works out for you

Relative newbie trying to use this for my NodeMCU project. Just want to make the HTTP request when the button is pushed. That’s it!

I replaced the quotes (that were doing the stray /342 error) - and replaced ‘door’ with ‘button press’

  • However, now it just scrolls “Button is not activated” forever in the serial monitor and ignores the button.
    Thinking I put the if/else in wrong, but can’t seem to fix it. Please help, Internet!

#include<ESP8266WiFi.h>

const charssid = “MyWifiNetwork”;
const char
password = “PASSWORD”;
const char*host = “http://maker.ifttt.com”;
int buttonState = 0;

void setup() {
Serial.begin(115200);
delay(10);
pinMode(16, INPUT);//connectedtoGPIO16
//WestartbyconnectingtoaWiFinetwork
Serial.println();
Serial.println();
Serial.print(“Connecting to “);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(”.”);
}
Serial.println(“”);
Serial.println(“WiFi connected”);
Serial.println(“IPaddress:”);
Serial.println(WiFi.localIP());
}

void loop() {
//readthestateofthepushbuttonvalue:
buttonState = digitalRead(16);

//checkifbuttonispressed
//ifnotthenstatusisHIGH

if (buttonState == HIGH) {
Serial.println("Button is not activated ");

} else {
//theButtonispressed:
Serial.println("Button activated ");
Serial.print("connecting to ");
Serial.println(host);

//UseWiFiClientclasstocreateTCPconnections
WiFiClient client;
const int httpPort = 3480;
if (!client.connect(host, httpPort)) {
  Serial.println("connection failed");
  return;
}
//WenowcreateaURIfortherequest
String url = "/trigger/EVENTNAME/with/key/KEYCODE";
Serial.print("RequestingURL:");
Serial.println(url);
//Thiswillsendtherequesttotheserver
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
Serial.println();
Serial.println("closing connection");
delay(2000);

}
}