legotheboss / YouTube-files

Files for QuickPi tutorials
https://www.youtube.com/QuickPie
109 stars 40 forks source link

ESP2866 and MQTT sensor reading #20

Open s95 opened 6 years ago

s95 commented 6 years ago

Hi QuickPi, Thank you for all the great tutorials. I want to start off that this is not an "issue" but I need your help to set up a new accessory for my ESP8266. I set up my ESP8266 based on your motion sensor tutorial (I modified your code to work for an ultrasonic sensor since I didn't have a PIR) and everything works fine. However, I really want to add a sensor to my ESP8266 and read its value from the home app. I have a DHT22 sensor and I tried what Korcsog did (links at the bottom of this post) but his code just doesn't work. Some things that also confuse me in his code is that he has the IP of the ESP8266 in the accessory js file where as you just use the host as localhost. I guess my main questions are: -Could you modify your .ino and accessory js file for the motion sensor tutorial so that it can post a generic sensor reading (like temperature) to the home app? (I use Core.js instead of Bridged core) -If possible, could you add the sensor code to the same .ino and .js file so that I can read the temperature/humidity and detect motion changes from a single ESP8266? -Is it possible to have multiple readings (using like 8 of the ESP8266's digital pins) and posting their readings to the home app? Or can it only post 1 reading?

Thanks so much for the help, I put the links to the DHT22 MQTT files below:

https://github.com/Korcsog/Arduino/blob/master/DHT22Wemos.ino https://github.com/Korcsog/Homekit/blob/master/Accessories/HumiditySensor_accessory.js https://github.com/Korcsog/Homekit/blob/master/Accessories/TemperatureSensor_accessory.js

Korcsog commented 6 years ago

Hi @s95 ! The IP both in the .js and .ino file is not the ESP's IP. Its the MQTT server's IP (e.g. my raspberry pi). It is possible to modify the ESP's code to read a DHT sensor and a motion sensor at the same time. Also possible to publish multiple data from one ESP. At the moment I've 3 ESPs with multiple sensors/relays/buttons attached to it. One of my ESPs reads the humidity/temp data from a Bosch sensor, reads data from an AirQuality sensor and has a relay with a (stateless) button so it controls lights. You just need on properly coded .ino file. Also you need .js files for each services (e.g.: three files; one for the motion sensor accessory, one for the humidity and one for the temp data). So multiple readings still possible. At the moment I'm using my DHT .js file with a Bosch sensor and it still works. The most important thing is to have the proper code for the ESP.

legotheboss commented 6 years ago

I am planning a multi-sensor for HomeKit, similar to what BruhAutomation did with the ESP8266. I will be porting this soon over to HomeKit. This should combine many of what you're looking for and much more.