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
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
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 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”;
// 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);
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 !!!
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!