Author Topic: Esp8266 as a switch in vera  (Read 1064 times)

Offline stofakiller

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Esp8266 as a switch in vera
« on: September 19, 2016, 12:46:22 pm »
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 :-)

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 :-)

Hope someone can help me with my little project

Regards,
Jan

Offline Otje

  • Full Member
  • ***
  • Posts: 204
  • Karma: +5/-1
Re: Esp8266 as a switch in vera
« Reply #1 on: January 05, 2017, 06:49:07 pm »
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....
VERA Plus, VERA 3 Lite , couple of PIR's, several switch units, wall mounted tablet, Sonos integration with TTS, Temperature sensors, Imperihome, Zwave LED bulbs

Offline JR

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: Esp8266 as a switch in vera
« Reply #2 on: April 13, 2017, 08:08:21 am »
@Otje,
Can you please post the code?

Thanks in advance.

Offline jojoflyhigh

  • Sr. Newbie
  • *
  • Posts: 33
  • Karma: +0/-1
Re: Esp8266 as a switch in vera
« Reply #3 on: April 13, 2017, 07:36:02 pm »
Hello,
Here is another way to program ESP8266.
http://www.touteladomotique.com/forum/viewtopic.php?f=6&t=18720

I can develop how to interact with Vera if needed


Offline Otje

  • Full Member
  • ***
  • Posts: 204
  • Karma: +5/-1
Re: Esp8266 as a switch in vera
« Reply #4 on: April 14, 2017, 11:00:25 am »
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);
   
  }
}
 



VERA Plus, VERA 3 Lite , couple of PIR's, several switch units, wall mounted tablet, Sonos integration with TTS, Temperature sensors, Imperihome, Zwave LED bulbs

Offline MarcusB

  • Sr. Newbie
  • *
  • Posts: 36
  • Karma: +1/-0
Re: Esp8266 as a switch in vera
« Reply #5 on: April 29, 2017, 08:49:07 pm »
Thanks for posting the code. I'm going to do some experimenting with it.