Garagentoröffner

Um die beiden Garagentore auch über OpenHAB öffnen zu können, nutze ich ein 2er Relayboard mit einem ESP01 drauf.

Hier der benutzte Sketch. Ich arbeite mir der Homie-esp8266 Library, da das MQTT-Binding in OpenHAB die Homiekonvention unterstützt.

#include <Homie.h>
#include <Arduino.h>
#define FW_VERSION "0.0.3"
const byte SET1[] {0xA0,0x01,0x01,0xA2,0x0D,0x0A};
const byte RESET1[] {0xA0,0x01,0x00,0xA1,0x0D,0x0A};
const byte SET2[] {0xA0,0x02,0x01,0xA3,0x0D,0x0A};
const byte RESET2[] {0xA0,0x02,0x00,0xA2,0x0D,0x0A};
const unsigned long ACTIVE_TIME{500};
unsigned long reset1 {0};
unsigned long reset2 {0};
HomieNode garageNode("garagedoors", "Garage", "switch");
void loopHandler() {
}
bool door1Handler(const HomieRange& range, const String& value){
Homie.getLogger() << "Door 1 triggered" <<endl;
Serial.write(SET1,6);
garageNode.setProperty("door1").send("on");
reset1 = millis() + ACTIVE_TIME;
return true;
};
bool door2Handler(const HomieRange& range, const String& value){
Homie.getLogger() << "Door 2 triggered" <<endl;
Serial.write(SET2,6);
garageNode.setProperty("door2").send("on");
reset2 = millis() + ACTIVE_TIME;
return true;
};
void setup() {
Serial.begin(115200);
Homie_setFirmware("csh_garagedoor",FW_VERSION);
Homie_setBrand("Comstock Homecontrol");
//Homie.setLoopFunction(loopHandler);
Homie.disableLedFeedback();
Homie.setup();
garageNode.advertise("door1").setName("Door L").setDatatype("boolean").settable(door1Handler);
garageNode.advertise("door2").setName("Door R").setDatatype("boolean").settable(door2Handler);
}
void loop(){
Homie.loop();
if(reset1!=0 && reset1<millis()){
Serial.write(RESET1,6);
garageNode.setProperty("door1").send("off");
reset1=0;
}
if(reset2!=0 && reset2<millis()){
Serial.write(RESET2,6);
garageNode.setProperty("door2").send("off");
reset2=0;
}
}
view raw main.cpp hosted with ❤ by GitHub
;You have to upload homie/config.json as explained in the homie-esp documentation
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
lib_deps = https://github.com/gorec2005/homie-esp8266.git#develop
;lib_deps = https://github.com/homieiot/homie-esp8266.git#develop
build_flags =
-D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
-D HOMIE_CONFIG=0
-D HOMIE_MDNS=0
monitor_speed = 115200
board_build.filesystem = littlefs
view raw platformio.ini hosted with ❤ by GitHub