Smart Home Event Viewer

by lebon1089 in Circuits > Arduino

231 Views, 1 Favorites, 0 Comments

Smart Home Event Viewer

lbox1.jpg
lbox3.jpg
lbox2.jpg

I would like to be aware of different states in my smart home. And not only me, but also my girlfriend. And in such a way that you can see it when you walk past - intentionally NOT via your smartphone

Supplies

  • For the event viewer itself
  • Wemos D1 microcontroller
  • Powersupply
  • circuit board to solder yourself
  • optional various screw terminals
  • 4 resistors 220 Ohm
  • 1 resistor 1 kOhm
  • 4 LEDs
  • 1 Button (I chose a button that matches our light switches)
  • 1 OLED Display (I have a 0.96" OLED SSD1306 I2C display - 128x64 pixels)
  • a nice housing for the electronics


Functionality

I can controll the box by following http-commands:


  • http://10.45.0.23/LED=ON   Blue LED ON
  • http://10.45.0.23/LED=OFF   Blue LED OFF
  • http://10.45.0.23/LED=TRON   Red LED ON
  • http://10.45.0.23/LED=TROFF   Red LED OFF
  • http://10.45.0.23/LED=GAON   Yello LED ON
  • http://10.45.0.23/LED=GAOFF   Yello LED OFF
  • http://10.45.0.23/TX?<SOME TEXT> --> the text SOME TEXT is shown on the display


  • So i use the blue led to indicate that the electric car is fully charged
  • The red LED lets me know when the washer or dryer is done, because washing machine and dryer are 1 floor below
  • The yellow LED is on when the garage is open and off when the garage is closed
  • The green LED always lights up when a text has been sent to the display. I use the text function to indicate when I have to take out which garbage can

If the light switch (button) on the housing is pressed, ALL messages / LEDs go out


Since the Event Viewer is controlled via http calls (I do this via "wget" from the Raspberry), any software or process can control it.

Hardware | Soldering Electronics & Housing

fritzing.jpg
lbox2.jpg
  1. Soldering the Board
  2. i choosed plug headers to easy remove and touch the Wemos D1 board
  3. i choosed screw terminals to connect the LEDs and the button
  4. I subsequently soldered the display directly to the soldering board
  5. Build the case and store everything inside. I used 2 different Lego kits to house the LEDs


Software | the Wemos D1 Sketch

#include <ESP8266WiFi.h>
#include "Wire.h";
#include "SSD1306.h";

const char* ssid = "<My WLAN Name>";
const char* password = "<My WLAN Password>";

//
// the pins used for connected button and LEDs 
//
int ledPin = D8;
int taster = D2;
int ledPinTR = D3;
int ledPinGA = D4;
int ledPinDP = D7;

int data;
int tasterstatus = 0;

String dataset = "";
String arg1;
String arg2;
String arg3;

WiFiServer server(80);

//
// the pins used for conncting the OLED display
//
SSD1306 display(0x3C, D6, D5);

void setup() {
Serial.begin(115200);
delay(10);

pinMode(ledPin, OUTPUT);
pinMode(ledPinTR, OUTPUT);
pinMode(ledPinGA, OUTPUT);
pinMode(ledPinDP, OUTPUT);
pinMode(taster, INPUT);
digitalWrite(ledPin, LOW);

//
// Important: The Wemos needs a STATIC IP 
//
IPAddress ip(10, 45, 0, 23);
IPAddress dns(10, 45, 0, 1);
IPAddress gateway(10, 45, 0, 1);
IPAddress subnet(255, 255, 0, 0);
WiFi.config(ip, dns, gateway, subnet);

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");

server.begin();

Serial.println("Server started");
Serial.print("Use this URL : ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}

void loop() {
tasterstatus = digitalRead(taster);

//
// Rest the EventViewer (switching out the LEDs and clearing the display)
//
if (tasterstatus == HIGH) {
 digitalWrite(ledPin, LOW);
 digitalWrite(ledPinTR, LOW);
 digitalWrite(ledPinGA, LOW);
 digitalWrite(ledPinDP, LOW);
 display.init();
 display.setFont(ArialMT_Plain_24);
 display.drawString(0, 0, "");
 display.display();
}

WiFiClient client = server.available();
if (!client) {
 return;
}

Serial.println("new client");
while(!client.available()){
 delay(1);
}

String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();

//
// The Adress contains "/TX" --> receiving Text-message and write it to the display
// 
if (request.indexOf("/TX") != -1) {
 digitalWrite(ledPinDP, HIGH);
 Serial.println("Freitext");
 Serial.print("request: ");
 Serial.println(request);

 arg1 = split(request, '?', 1);
 arg2 = split(request, '?', 2);
 arg3 = split(request, '?', 3);
 dataset = "";
 Serial.print("arg1: ");
 Serial.println(arg1);
 Serial.print("arg2: ");
 Serial.println(arg2);
 Serial.print("arg3: ");
 Serial.println(arg3);
 display.init();
 display.setFont(ArialMT_Plain_24);
 display.drawString(0, 0, arg1);
 display.display();
} 

//
// Switch the addressed LED on or off
//
if (request.indexOf("/LED=ON") != -1) {
 digitalWrite(ledPin, HIGH);
} 
if (request.indexOf("/LED=OFF") != -1){
 digitalWrite(ledPin, LOW);
}

if (request.indexOf("/LED=TRON") != -1) {
 digitalWrite(ledPinTR, HIGH);
} 
if (request.indexOf("/LED=TROFF") != -1){
 digitalWrite(ledPinTR, LOW);
}
if (request.indexOf("/LED=GAON") != -1) {
 digitalWrite(ledPinGA, HIGH);
} 
if (request.indexOf("/LED=GAOFF") != -1){
 digitalWrite(ledPinGA, LOW);
}

// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("Led pin is now: ");
client.println("<br><br>");
client.println("Click <a href=\"/LED=ON\">here</a> turn the LED on pin 5 ON<br>");
client.println("Click <a href=\"/LED=OFF\">here</a> turn the LED on pin 5 OFF<br>");
client.println("</html>");
delay(1);
Serial.println("Client disconnected");
Serial.println("");
}

String split(String s, char parser, int index) {
 String rs = "";
 int parserIndex = index;
 int parserCnt = 0;
 int rFromIndex = 0, rToIndex = -1;
 while (index >= parserCnt) {
   rFromIndex = rToIndex + 1;
   rToIndex = s.indexOf(parser, rFromIndex);
   if (index == parserCnt) {
   return s.substring(rFromIndex, rToIndex);
 }
   else parserCnt++;
 }
 return rs;
}

Calling the Display Interface

crontab_muell.jpg

I simply use the CRONTAB for appointments as to when which garbage can has to be taken out. With this I control the "dsp_tonne.php".

Here the dsp_tonne.php:

<?php
// Send the passed text to the event viewer
system("wget --no-cache --spider http://10.45.0.23/TX?" . $argv[1] . "???");

// Also send an email
$abs = "lebon1089@gmail.com";
$bet = $argv[1] . " muss raus";
$txt = $argv[1] . " muss raus";
$emp = "lebon1089@gmail.com";
mail($emp, $bet, $txt, "From: gelbesHaus <$abs>");
?>


The other wget calls I use for the other LEDs come from the subprograms of my other smart home components.

See here my Garage-Door-Controller https://www.instructables.com/Garage-Door-Opener-Calling-by-Phone-Via-Arduino-an/


Here