# Homeyduino-Projekte

**URL:** <https://community.homey.app/t/homeyduino-projekte/23779>\
**Category:** Fragen & Hilfe\
**Created:** [January 4, 2020, 3:12pm UTC](https://community.homey.app/t/homeyduino-projekte/23779 "2020-01-04T15:12:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![S.Krey](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/s.krey/32/17470_2.png) [@S.Krey](https://community.homey.app/u/S.Krey)\
**Post date:** [January 4, 2020, 3:12pm UTC](https://community.homey.app/t/homeyduino-projekte/23779/1 "2020-01-04T15:12:40Z")

</div>

Mahlzeit, ich wollte mal fragen, ob schon jemand hier Projekte mit dem ESP und Homeyduino verwirklicht hat. Falls das Thema eher in den Bereich Entwickler gehört, bitte verschieben.

Ich sitze momentan daran, eine kleine Steuerung für meinen Garagentorantrieb von Chamberlain zu verwirklichen. Ein ESP32 soll über ein Relais den kurzen Impuls des normalerweise montierten Schalters von Chamberlain weitergeben und zusätzlich über einen Reedkontakt mir anzeigen, ob das Tor zu oder auf ist. Ergänzend hierzu werde ich noch einen Temperatur- und Feuchtigkeitssensor montieren, da es mich schon immer mal interessiert hat, wie sich die Temperatur im Winter in der Garage verhält.

Und da ist er, der erste Prototyp. Bitte beachtet, dass der Code noch nicht optimiert ist.  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/9/19181d8d5292aafd428442a9edff9106ffdebebd.jpeg)

[//20.01.20](https://20.01.20) Version 4.1 eingefügt.  
[//02.02.20](https://02.02.20) Version 4.2 eingefügt

> **Code Garagensteuerung**
>
> //v1 Code von [https://huisvanvandaag.nl](https://huisvanvandaag.nl).  
> //v2 Code von siehe oben, an ESP32 angepasst, relay.h raus, Wifi Code geändert  
> //v3 SHT31 eingefügt  
> //v4 Reed-Kontakt Garagentor, Rückgabewert des Reed Kontaktes an Homey  
> [//v4.1](https://v4.1) Millis angepasst, Reedontakt Code geändert  
> [//v4.2](https://v4.2) Wifi reconnect eingefügt [https://medium.com/diy-my-smart-home/esp-tipp-wifi-reconnect-einbauen-dc4a7397b741](https://medium.com/diy-my-smart-home/esp-tipp-wifi-reconnect-einbauen-dc4a7397b741)
> 
> //Relay  
> #include \<WiFi.h\>  
> #include \<WiFiClient.h\>  
> #include \<Homey.h\>  
> #define PIN\_RELAY 17 // Signal Pin Relay  
> bool state = false;  
> unsigned long previousMillis = 0;  
> const unsigned long interval = 100; //Interval in milliseconds
> 
> //sht31  
> #include \<Wire.h\>  
> #include “SHTSensor.h”  
> SHTSensor sht;  
> unsigned long previousMillis2 = 0;  
> const unsigned long interval2 = 30000; //Interval in milliseconds
> 
> //Reed  
> int pinStatusGarageDoor = 16;  
> byte GarageDoorBinaryState;  
> unsigned long previousMillis3 = 0;  
> const unsigned long interval3 = 100; //Interval in milliseconds
> 
> // Wifi  
> //============================================================================================  
> const char\* ssid = “XXX”;  
> const char\* password = “XXX”;
> 
> void setup() {  
> Wire.begin();  
> Serial.begin(115200);  
> while (!Serial);  
> Serial.println(F(“Relay, SHT31 und Reed Test”));  
> StartWiFi();
> 
> if (sht.init()) {  
> Serial.print(“SHT31 init(): success\n”);  
> } else {  
> Serial.print(“SHT31 init(): failed\n”);  
> }
> 
> pinMode(PIN\_RELAY, OUTPUT); //Set relay pin to output  
> digitalWrite(PIN\_RELAY, LOW); //Turn output off  
> pinMode(pinStatusGarageDoor, INPUT\_PULLUP);  
> Homey.begin(“Garage”); // Name  
> Homey.setClass(“socket”);  
> Homey.addCapability(“onoff”, setState);  
> Homey.addAction(“output”, setState);  
> Homey.addCondition(“state”, getState);  
> Homey.addCapability(“measure\_humidity”);  
> Homey.addCapability(“measure\_temperature”);  
> Homey.addCapability(“alarm\_contact”);
> 
> }
> 
> void loop() {  
> Homey.loop();  
> unsigned long currentMillis = millis();  
> WifiRetry();
> 
> if (currentMillis - previousMillis \> interval) {  
> previousMillis = currentMillis;
> 
> }
> 
> if (currentMillis - previousMillis2 \> interval2) {  
> previousMillis2 = currentMillis;  
> sht31();
> 
> }  
> if (currentMillis - previousMillis3 \> interval3) {  
> previousMillis3 = currentMillis;  
> reed();  
> }
> 
> zeroState();  
> }
> 
> void StartWiFi() {  
> WiFi.begin(ssid, password);  
> while (WiFi.waitForConnectResult() != WL\_CONNECTED) {  
> Serial.println(“Connection Failed! Rebooting…”);  
> delay(5000);  
> ESP.restart();  
> }  
> Serial.println(“Connected to the WiFi network”);  
> Serial.println("");  
> Serial.println(“WiFi connected”);  
> Serial.println("IP address: ");  
> Serial.println(WiFi.localIP());  
> }
> 
> void WifiRetry() {  
> int wifi\_retry = 0;  
> while(WiFi.status() != WL\_CONNECTED && wifi\_retry \< 5 ) {  
> wifi\_retry++;  
> Serial.println(“WiFi not connected. Try to reconnect”);  
> WiFi.disconnect();  
> WiFi.mode(WIFI\_OFF);  
> WiFi.mode(WIFI\_STA);  
> WiFi.begin(ssid, password);  
> delay(100);  
> }  
> if(wifi\_retry \>= 5) {  
> Serial.println("\nReboot");  
> ESP.restart();  
> }  
> }
> 
> void setState() {  
> state = Homey.value.toInt();  
> applyState();  
> }
> 
> void applyState() {  
> //digitalWrite(PIN\_RELAY, state);  
> if (state \> 0) {  
> digitalWrite(PIN\_RELAY, HIGH); //turn relay on  
> delay(100);  
> digitalWrite(PIN\_RELAY, LOW);  
> }
> 
> Serial.println("applyState(): new state is " + String(state));  
> Homey.setCapabilityValue(“onoff”, state);  
> Homey.trigger(“state”, state);  
> }
> 
> void getState() {
> 
> Serial.println("getState(): state is " + String(state));  
> return Homey.returnResult(state);  
> }
> 
> void zeroState() {  
> if (state \> 0) {  
> state = 0; //Status auf Null  
> Homey.setCapabilityValue(“onoff”, state); //und Rückgabewert an Homey senden  
> }  
> }
> 
> void sht31() {  
> float temperature = (sht.getTemperature());  
> byte humidity = (sht.getHumidity());  
> Serial.print(“SHT:\n”);  
> Serial.print(" Temperatur: “);  
> Serial.print(temperature);  
> Serial.println(” \*C");  
> Serial.print(" Luftfeuchtigkeit: “);  
> Serial.print(humidity);  
> Serial.println(” %");
> 
> if (isnan(humidity) || isnan(temperature)) {  
> Serial.print("\t");  
> Serial.println(“Failed to read from sht31 sensor (isnan)!”);  
> //return;  
> delay(5000);  
> ESP.restart();  
> }  
> if ((humidity \>= 100) || (temperature \<= -146)) {  
> Serial.print("\t");  
> Serial.println(“Failed to read from sht31 sensor (-146 100) !”);  
> //return;  
> delay(5000);  
> ESP.restart();  
> }  
> if ((humidity == 0) || (temperature == 0)) {  
> Serial.print("\t");  
> Serial.println(“Failed to read from sht31 sensor (0) !”);  
> //return;  
> delay(5000);  
> ESP.restart();  
> }
> 
> Homey.setCapabilityValue(“measure\_temperature”, (float) temperature);  
> Homey.setCapabilityValue(“measure\_humidity”, (int) humidity);  
> }
> 
> void reed() {  
> byte \_GarageDoorBinaryState = digitalRead(pinStatusGarageDoor);  
> if (GarageDoorBinaryState != \_GarageDoorBinaryState) {  
> GarageDoorBinaryState = \_GarageDoorBinaryState;  
> }  
> if (\_GarageDoorBinaryState == HIGH) {  
> Serial.println(“Die Garage ist geschlossen”);  
> Serial.println(\_GarageDoorBinaryState);  
> Homey.setCapabilityValue(“alarm\_contact”, (false));  
> }  
> else  
> {  
> Serial.println(“Die Garage ist offen”);  
> Serial.println(\_GarageDoorBinaryState);  
> Homey.setCapabilityValue(“alarm\_contact”, (true));  
> }  
> }

Das hierauf folgende Projekt wird deutlich größer, da Homey ja keine Z-Unos unterstützt und ich somit meine Wetterstation (Regenmenge, Wind und -richtung, UV, LUX, Temperatur, Feuchtigkeit und Luftdruck) auf einen ESP32 verändern muss.

---

<div class="post-metadata">

**Author:** ![Lars\_Machiels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lars_machiels/32/10295_2.png) [@Lars\_Machiels](https://community.homey.app/u/Lars_Machiels)\
**Post date:** [January 6, 2020, 2:37pm UTC](https://community.homey.app/t/homeyduino-projekte/23779/2 "2020-01-06T14:37:01Z")

</div>

Ein Project mit Homey(Duino) und ein ESP32 ist sehr gut möglich. Ich habe vor kurzem eine CO2 /Temp/Druck/IAQ sensor gemacht mit einem ESP32.

> [@HomeyDuino CO2 sensor](https://community.homey.app/t/homeyduino-co2-sensor/20410/8):
>
> Just finished my second version. This time in a 3D printed enclosure and a Bosch BME680 (with official Bosch library). So now I can read CO2/Temp/Humidity/Pressure/VOC/IAQ. The BME680 can also act as a smoke detector. I tried it with setting a piece of paper on fire. The IAQ readings immediately went up to over 400 (range 0-500), One can do the (WiFi) setup via a WiFi access point to fill in the parameters for WiFi/Homey and a MQTT client. Still need to calibrate the C…

---

<div class="post-metadata">

**Author:** ![S.Krey](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/s.krey/32/17470_2.png) [@S.Krey](https://community.homey.app/u/S.Krey)\
**Post date:** [January 19, 2020, 12:14pm UTC](https://community.homey.app/t/homeyduino-projekte/23779/3 "2020-01-19T12:14:55Z")

</div>

Sehr schön, habe es auf meiner Arduino-To-Do-List @Lars_Machiels notiert.

Nachdem mein Code für die Garage nun einige Tage gut funktioniert hat, habe ich mich mal an den Anfang der Wetterstation gesetzt. Dabei ist ein ESP32 mit BME280 (Temperatur, Luftfeuchtigkeit und -druck), einem VEML6070 (UV-INDEX), MAX44009 (Luxmeter) und einem Regentropfensensor herausgekommen. Windrichtung und- geschwindigkeit sowie Regenmenge fehlt noch. Der Code sendet aktuell alle 30 Sekunden die Werte und ist noch nicht optimiert worden. Untergebracht ist alles in einem 3D-Druck Testgehäuse. Die 12V-Heizung für den Regentropfensensor habe ich in China bestellt. Bin gespannt, wie sich diese schlagen wird.

 ![20200119_115938000_iOS](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/3/c/3c7bb4dd1d7a701b48c55b08926c9b057f789db4.jpeg) ![20200119_120031357_iOS](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/c/0c97d28d6b72484db963ccdbc76581a009dcf28b.jpeg) ![20200119_120047274_iOS](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/6/4/6480cafa0193c5c0d85b7d48276b830170e1bd73.jpeg)

[//02.02.20](https://02.02.20) Version 6.2 eingefügt.

> **Code**
>
> ön//BME Testsketch und MAX44009 Testsketch zusammenkopiert  
> //v2: Wifi hinzugefügt  
> //v3: Homey und millis hinzugefügt  
> //v4: Raindrop  
> //v5: allgemeine Codeanpassungen  
> //v6: UV-Sensor und Index
> 
> #include \<Wire.h\>  
> #include \<Adafruit\_Sensor.h\>  
> #include \<Adafruit\_BME280.h\>  
> #include \<MAX44009.h\>  
> MAX44009 light;  
> #include \<WiFi.h\>  
> #include \<Homey.h\>
> 
> Adafruit\_BME280 bme; // I2C
> 
> unsigned long previousMillis = 0;  
> const unsigned long interval = 30000; //Interval in milliseconds
> 
> // Wifi  
> //============================================================================================  
> const char\* ssid = “XXX”;  
> const char\* password = “XXX”;
> 
> // Raindrop  
> //============================================================================================
> 
> int pinStatusRainDrop = 4;  
> byte pinRainSensorBinaryState;  
> unsigned long previousMillis2 = 0;  
> const unsigned long interval2 = 1000; //Interval in milliseconds
> 
> // VEML  
> //============================================================================================  
> #include “Adafruit\_VEML6070.h”  
> Adafruit\_VEML6070 uv = Adafruit\_VEML6070();  
> int UV = 0;  
> byte UVIndex;
> 
> void setup() {  
> Serial.begin(115200);  
> while (!Serial); // time to get serial running  
> Serial.println(F(“BME280, MAX44009, Regentropfen und VEML Test”));  
> Wire.begin();  
> pinMode(pinStatusRainDrop, INPUT\_PULLUP);  
> uv.begin(VEML6070\_1\_T); // pass in the integration time constant  
> StartWiFi();  
> Homey.begin(“Sensoren”);  
> Homey.setClass(“sensor”);  
> Homey.addCapability(“measure\_humidity”);  
> Homey.addCapability(“measure\_temperature”);  
> Homey.addCapability(“measure\_luminance”);  
> Homey.addCapability(“measure\_pressure”);  
> Homey.addCapability(“alarm\_contact”);  
> delay(500); // noch prüfen, ob notwendig  
> unsigned status;
> 
> // default settings  
> // (you can also pass in a Wire library object like &Wire2)  
> if (!bme.begin(0x76)) {  
> Serial.println(“Could not find a valid BME280 sensor, check wiring!”);  
> while (1);  
> }
> 
> if (light.begin())  
> {  
> Serial.println(“Could not find a valid MAX44009 sensor, check wiring!”);  
> while (1);  
> }  
> Serial.println();  
> }
> 
> void loop() {  
> Homey.loop();  
> unsigned long currentMillis = millis();  
> WifiRetry();  
> if (currentMillis - previousMillis \> interval) {  
> previousMillis = currentMillis;  
> updateSensor();  
> UVIndex = ReadUVIndex();  
> Homey.setCapabilityValue(“measure\_ultraviolet”, (int) UVIndex);  
> Serial.printf(“UV-INDEX = “);  
> Serial.printf(”\t”);  
> Serial.println(UVIndex);  
> rain();  
> }  
> if (currentMillis - previousMillis2 \> interval2) {  
> previousMillis2 = currentMillis;  
> //rain();  
> }  
> }
> 
> void StartWiFi() {  
> WiFi.begin(ssid, password);  
> while (WiFi.waitForConnectResult() != WL\_CONNECTED) {  
> Serial.println(“Connection Failed! Rebooting…”);  
> delay(5000);  
> ESP.restart();  
> }  
> Serial.println(“Connected to the WiFi network”);  
> Serial.println("");  
> Serial.println(“WiFi connected”);  
> Serial.println("IP address: ");  
> Serial.println(WiFi.localIP());  
> }
> 
> void WifiRetry() {  
> int wifi\_retry = 0;  
> while(WiFi.status() != WL\_CONNECTED && wifi\_retry \< 5 ) {  
> wifi\_retry++;  
> Serial.println(“WiFi not connected. Try to reconnect”);  
> WiFi.disconnect();  
> WiFi.mode(WIFI\_OFF);  
> WiFi.mode(WIFI\_STA);  
> WiFi.begin(ssid, password);  
> delay(100);  
> }  
> if(wifi\_retry \>= 5) {  
> Serial.println("\nReboot");  
> ESP.restart();  
> }  
> }
> 
> void updateSensor() {  
> float temperature = bme.readTemperature();  
> byte humidity = bme.readHumidity();  
> float baromin = (bme.readPressure() / 100.0F);  
> uint16\_t lux = light.get\_lux();
> 
> if (isnan(humidity) || isnan(temperature) || isnan(baromin)) {  
> Serial.print("\t");  
> Serial.println(“Failed to read from BME280 sensor (isnan)!”);  
> //return;  
> delay(5000);  
> ESP.restart();  
> }  
> if ((humidity \>= 100) || (temperature \<= -146)) {  
> Serial.print("\t");  
> Serial.println(“Failed to read from BME280 sensor (-146 100) !”);  
> //return;  
> delay(5000);  
> ESP.restart();  
> }  
> if ((humidity == 0) || (temperature == 0)) {  
> Serial.print("\t");  
> Serial.println(“Failed to read from BME280 sensor (0) !”);  
> //return;  
> delay(5000);  
> ESP.restart();  
> }
> 
> Serial.print(“Temperatur = “);  
> Serial.printf(”\t”);  
> Serial.print(temperature);  
> Serial.println(" \*C");
> 
> Serial.print(“Luftdruck = “);  
> Serial.printf(”\t”);  
> Serial.print(baromin);  
> Serial.println(" hPa");
> 
> Serial.print(“Feuchtigkeit “);  
> Serial.printf(”\t”);  
> Serial.print(humidity);  
> Serial.println(" %");
> 
> Serial.print(“Licht (lux)= “);  
> Serial.printf(”\t”);  
> Serial.println(lux);
> 
> Homey.setCapabilityValue(“measure\_temperature”, (int) temperature);  
> Homey.setCapabilityValue(“measure\_humidity”, (int) humidity);  
> Homey.setCapabilityValue(“measure\_luminance”, (int) lux);  
> Homey.setCapabilityValue(“measure\_pressure”, (int) baromin);
> 
> }
> 
> void rain() {
> 
> byte \_pinRainSensorBinaryState = digitalRead(pinStatusRainDrop);  
> if (pinRainSensorBinaryState != \_pinRainSensorBinaryState) {  
> pinRainSensorBinaryState = \_pinRainSensorBinaryState;
> 
> if (\_pinRainSensorBinaryState == HIGH) {  
> Serial.println(“Kein Regen”);  
> Serial.println(\_pinRainSensorBinaryState);  
> Homey.setCapabilityValue(“alarm\_contact”, (false));  
> }  
> else  
> {  
> Serial.println(“Es regnet”);  
> Serial.println(\_pinRainSensorBinaryState);  
> Homey.setCapabilityValue(“alarm\_contact”, (true));  
> }
> 
> }  
> }  
> byte ReadUVIndex() {  
> UV = uv.readUV();  
> if (UV \< 50) return 0;  
> if (UV \<= 227) return 1;  
> if (UV \<= 318) return 2;  
> if (UV \<= 408) return 3;  
> if (UV \<= 503) return 4;  
> if (UV \<= 606) return 5;  
> if (UV \<= 696) return 6;  
> if (UV \<= 795) return 7;  
> if (UV \<= 881) return 8;  
> if (UV \<= 976) return 9;  
> if (UV \<= 1079) return 10;  
> return 11;
> 
> }

---

<div class="post-metadata">

**Author:** ![Fred\_Miller](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/fred_miller/32/13545_2.png) [@Fred\_Miller](https://community.homey.app/u/Fred_Miller)\
**Post date:** [January 19, 2020, 5:00pm UTC](https://community.homey.app/t/homeyduino-projekte/23779/4 "2020-01-19T17:00:26Z")

</div>

An der kompletten Wetterstation habe ich dann interesse 😀

---

<div class="post-metadata">

**Author:** ![Lars\_Machiels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lars_machiels/32/10295_2.png) [@Lars\_Machiels](https://community.homey.app/u/Lars_Machiels)\
**Post date:** [January 20, 2020, 7:21am UTC](https://community.homey.app/t/homeyduino-projekte/23779/5 "2020-01-20T07:21:28Z")

</div>

Toll!

---

<div class="post-metadata">

**Author:** ![Tequila329](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tequila329/32/10729_2.png) [@Tequila329](https://community.homey.app/u/Tequila329)\
**Post date:** [January 20, 2020, 7:38am UTC](https://community.homey.app/t/homeyduino-projekte/23779/6 "2020-01-20T07:38:35Z")

</div>

Hab aktuell zwei Sensoren mit ESP am laufen, jeweils mit:

- DHT 22 für Temp und Luftfeuchte
- Kapazitiver Bodenfeuchtesensor
- Solarzelle und Laderegler Regler für autarken Betrieb ohne Festspannung.

Dient zur Steuerung der Bewässerung von Rasen und Hochbeet.

Nächstes Projekt wird eine Lüftersteuerung, die einen 3D Druck, Bladeless Lüfter in Kombination mit Zwift + Rennrad steuert.  
Je schneller ich virtuell fahre, desto schneller soll der Lüfter drehen 😃

---

<div class="post-metadata">

**Author:** ![S.Krey](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/s.krey/32/17470_2.png) [@S.Krey](https://community.homey.app/u/S.Krey)\
**Post date:** [February 2, 2020, 11:48am UTC](https://community.homey.app/t/homeyduino-projekte/23779/7 "2020-02-02T11:48:10Z")

</div>

> [@Tequila329](#):
>
> Hab aktuell zwei Sensoren mit ESP am laufen, jeweils mit:
> 
> - DHT 22 für Temp und Luftfeuchte
> - Kapazitiver Bodenfeuchtesensor
> - Solarzelle und Laderegler Regler für autarken Betrieb ohne Festspannung.
> 
> Dient zur Steuerung der Bewässerung von Rasen und Hochbeet.

Ein sehr schönes Projekt übrigens. Steht auch auf meiner gefühlt niemals endenden Arduino-To-Do-Liste.

BME680 für das Projekt von @Lars_Machiels habe ich schonmal bestellt. Ansonsten habe ich meine beiden Codes oben angepasst und aktualisiert, falls doch mal jemand nachbauen will. Ansonsten wird es an der Wetterstation erstmal nicht weitergehen, da der Davis Windsensor zuirück zum Hersteller ist, das Aenometer lief nicht mehr rund.

---

<div class="post-metadata">

**Author:** ![Tequila329](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tequila329/32/10729_2.png) [@Tequila329](https://community.homey.app/u/Tequila329)\
**Post date:** [February 11, 2020, 11:27am UTC](https://community.homey.app/t/homeyduino-projekte/23779/8 "2020-02-11T11:27:12Z")

</div>

Ja die Liste wird irgendwie eher länger als kürzer 🙂

Meine Outdoor Ikea Kerzen haben auch ihre Akkus büßen müssen und werden jetzt mit Feststrom versorgt und via ESP 01 + MQTT geschaltet.  
Mich hat der Akkutausch bei Kälte genervt 😅
