My Automated Home: Raspberry Pi + Node-Red + MQTT & Amazon Echo

In our latest My Automated home feature, Dave McLaughlin takes us through his journey developing his own smart home system. With some DIY upgrades to existing home automation hardware and some clever software integration he’s built a fascinating system…

בהתחלה

Having used Homeseer and a number of wired and wireless devices whilst in the UK, I switched to wireless when I moved overseas to Indonesia in 2005. As I was living in a rented apartment I need a solution that would not require any cables other than maybe Ethernet in the same room.

I decide on a Z-Wave system, later adding Wemo Lamp modules too. For Z-Wave side of things I chose the HomePro Appliance modules for sockets and Everspring Lamp modules for the lighting. Neither of these 2 modules were cheap.

I ran with this setup until the middle of 2016, but the following issues prompted a change. Firstly Z-Wave was temperamental with 2 units at the far end of ou apartment, even though I had an Appliance Module half way between it just never worked reliably. I would have continually press OFF on the Homeseer Touch based tablet to get my bed light to go off. later I would have 2 units that controlled lamps blow up and fail. one of the IC’s that was part of the power supply had split wide open.

The next headache was the Wemo lamp modules. The only way to get these to work was with IFTTT through their Homeseer and Wemo channels. As long as my internet connection was good this worked ok, albeit a bit slow at times. Not exactly a 10 on the WAF scale.

In early 2016 I came across a website run by Peter Scargill who used to run an electronics design company many years ago from Tyneside. at that time I used his AppCON wired controllers for home automation based on the little 8 bit pic microcontrollers. I had hundreds of meters of 4 core alarm cable run all over my apartment. The system was reliable but trying to hide all that cable didn’t go down well with my partner at the time.

Fast forward to 2016 and Peter was back doing home automation with the little ESP8266 based controllers.

These are based on a Cortex M4 core with built in 802.11 WiFi and come with an SDK that allows development with Eclipse as well as an Arduino IDE option.

As my HomePro units were troublesome I decided to re-engineer the internals and keep the mechanical parts. So I took out the old PCB and did all the measurements so I could make my own 2 stack PCB assembly in much the same as the old one. The lower PCB is the POWER supply and solid state RELAY.

I chose the solid state relays as they switch on the zero crossing and avoid any issues with pulling down the AC and causing the power supply to dip. This works faultlessly and I can switch up to 8 AMPS with this arrangement. more than enough for the intended use of these modules.

These images show the new board stack and the old boards within the module and finally the new boards installed into the HomePro enclosure.

There is an LED on the board to show status and I drilled a small hole to allow this to be seen from the outside. It flashes rapidly until it gets a WiFi and MQTT connection. using the button on the front you can press and hold this for around 3-5 seconds just after power up and this will activate an APN and webpage that you can use to configure the device. easier than trying to do this over the serial connection. Peter and Aiden have considered everything with this.

Now the lighting needed to be sorted. The Everspring units that I had purchased from the UK a couple of years ago used to show an annoying fault. They would on occasion started to switch off and then back on again. It was completely random. I replaced one unit with a new one and the same thing happened. then one day I spotted that the on/off fault was occurring when the voltage in the apartment was dropping below 209Vac – Indonesia is not very good when it comes to stability of the mains supply. I opened one of the units and found that they used a very cheap power supply design based on a capacitor/resistor dropper type. These are good when you have a stable power supply but they really don’t like it when the voltage input is too low.

So armed with the HomePro unit design, I set about creating a new PCB to fit the existing enclosures. The ESP12 was located on one side and the AC-DC power on the other. The solid state relay was also on the same side as the power supply. A prog and on/off button were also fitted so I could install the software initially. The web interface would be used to configure it later. You can see the ESP side of the PCB below. The slot in the PCB is to increase the separation of the AC power from the low voltage DC side. The large pads are the AC in and AC out to the lamp.

So now I had a number of upgraded appliance modules and lighting controllers but how was I going to control all of this? It was time to retire my old Homeseer 2 system. The PC was noסוף הצרות ולהיות Windows 10 זה יחליט שהוא יעדכן את עצמו ללא רשותי. הגיע הזמן לעשות את המעבר ללינוקס.

אז, בהתבסס על הבלוג של פיטר, החלטתי להוציא את ה- Raspberry PI3 שלי עם ה- LCD 7 ″ שלו ולהפיל את צומת האדום. צומת אדום למי שלא ראה זאת זו תוכנת בקרת גרירה ושחרור נחמדה ויציבה מאוד. בהתחלה זה היה מרתיע להתקנה אבל אחרי כשבוע של משחק התחלתי לגלות שקל מאוד להתמודד איתו. אם יש לך כישורי תכנות, תרגיש בבית עם התסריט. כל המודולים מסופקים כמקור סקריפט Java ויש ספריה ענקית והולכת וגוברת עבורו באתר Node-RED.

בשלב הבא הייתי זקוק למתווך MQTT כתוכנה של פיטר מתקשרת באמצעות פרוטוקול זה. לאחר הגדרת ה- MQTT, אתה מבין במהירות עד כמה הוא יעיל ברשת שלך. אין צורך במכשירי סקר או אפילו לדעת את כתובת ה- IP של המכשירים. המתווך דואג לזה. מי שמכיר את XAP יבין זאת.

בעזרת Node-RED אני מגדיר טיימרים שונים (בזכות פיטר שוב על ה- BigTimer שלו) והפעיל את האורות בלילה. בעזרת תוסף WEMO יש לי כעת שליטה על מנורות ה- WEMO, אם כי רק אם הלאה לסירוגין. המפתח של התוסף הצומת-אדום הבטיח בקרת עמעום בשלב מסוים בזמן.

אוקיי, אז הייתה לי הגדרת צומת אדום ו- MQTT, אבל עכשיו הייתי צריך דרך לשלוט על האורות והמתגים גם על ידי קול וגם על צורה כלשהי של ממשק מכני או מגע. נתקלתי בכמה מתגים אלחוטיים מ- Enocean באתר Element14 ולכן הזמנתי כמה מהם יחד עם מודול ה- Raspberry Pi Enocean המחבר את סיכות ה- GPIO ב- PI ומשתמש ב- UART כדי לתקשר עם צומת אדום ותוסף.

למתגים יש תגמול בכך שאין סוללה להתקנה או לטפל בה. הם משתמשים בקציר אנרגיה דרך סליל ומגנט המופעל בזמן שאתה לוחץ על הכפתור. למרבה הצער הם לא מגיעים עם גופי קיר כך שתצטרך לעצב משלך. הם אכן מספקים קובץ STL של כפתור Toggle שתוכלו להדפיס תלת מימד כך שהשתמשתי בזה ויצרתי עבורם הרכבה משלי. זה משרת 2 מטרות, אחת לכיסוי המתג הישן על הקיר ומבטיחה שהוא נשאר במצב ON כך שמודולי המנורה תמיד פועלים ושנית לאיתור הפקדים במקום מוכר.

בעזרת תקע Enocean צומת-אדום אני מקבל עומס על הודעה עם מצבי הכפתור. על ידי ניתוח זה במתג צומת אדום אני יכול לשלוח את הפקודה המתאימה לאור או למתג וכו ‘. זו דוגמה לעומס הנשלח על ידי מתג Enocean. זה מקודד בפורמט JSON כל כך קל לנתח. ה- ID ו- V הם מה שאנחנו מעוניינים בו.

{“מטען מטען”: {“id”: “002d0932”, “v”: “a0 למטה”, “יחידה”: “”, “rssi”: -76, “סוג”: “מצב”, “eep”: ” F6-02-03 “,” MAN “:” ENOCEAN_GMBH “,” DESC “:” מתג נדנדה “,” RV “:” 30 “,” RAWBYTE “:” 55000707017AF630002D09323001FFFFFFFFFF4C000D “},” _MSGID “:” 3D4C. “”04C19” “” }

התמונה הבאה מציגה את המתג שיש לו 4 יציאות המבוססות על ערך msg.payload.v במברק מהמתג האנוקיאני. לאחר מכן מופנים אלה למכשיר המתאים. אני משתמש בתכונת TOGGLE בתוך הקושחה MQTT כדי להפעיל ולכבות את המכשיר מאותו מתג. המשמעות היא שיש לי עד 4 מצבי מתג מכל מודול אנוקיאני.

עכשיו החלק המהנה מתחיל מכיוון שיש לי הד של אמזון ותמיד רציתי לשלוט על הבית שלי עם פקודות קוליות. אתה יכול להאשים את Scifi בזה

אין תמיכה בהד ישיר, לפחות לא בלי שיהיה לך חיבור HTTPS לצומת האדום שלך וזה לצערנו בלתי אפשרי עם ספק שירותי האינטרנט שלי ולכן הייתי זקוק לחלופה. בעזרת Amazon Echo Habridge זה מריצה על אותו פטל PI3, לא יכולתי להגדיר קול להפעלת אורות וכו ‘. ההברידג’ מחקה API של Philips Hue כך שהד רואה את המכשירים שהגדרת. להלן דוגמא למכשיר שנקרא מאוורר החדר הקדמי.

על ידי ביטוי הדברים הבאים בהד, ניתן להפעיל את המאוורר. “אלכסה, הפעל את מאוורר החדר הקדמי” או כבוי באומרו “אלכסה, כבה את מאוורר החדר הקדמי”

ההברידג ‘שולח את הפקודות לצומת אדום באמצעות בקשת HTTP ואני מנתח את כתובת האתר לערכים. זהו סקריפט פשוט כמוצג להלן.

כיצד לעשות זאת עם מודולים בעלות נמוכה

לאחר שתכננתי PCB משלי כדי להחליף את המודולים הייתי זקוק לדרך להוסיף מודולי מתגים נוספים ובקרי אור.

יחידות הבית שלי גרמו לעלות סביב 15 דולר ארה”ב להכין עם כל ה- PCB והחלקים יחד. אז עדיין עלות נמוכה.

וִיְדוּס
תצוגה מקדימה
מוצר
דֵרוּג
מחיר

1
ג’יין צ’וי Raspberry Pi 4 B דגם B 8GB ערכת Starter (8GB RAM)-לוח SD 64GB, Cooli, Cooliמעריץ ng, …
121 ביקורות
222.99 ליש”ט
קנה באמזון

2
Raspberry Pi 400 4GB ערכת סטארט-אפ רשמית, פריסת בריטניה
215 ביקורות
110.56 ליש”ט
קנה באמזון

3
ערכת המתנע האולטימטיבית של FreeNove עבור Raspberry Pi 4 B 3 B+ 400, 561 עמודים הדרכות מפורטות, Python C …
2,835 ביקורות
42.95 ליש”ט
קנה באמזון

כדי להוריד את זה עוד יותר נמוך יותר נתקלתי בסטודיו Slampher של Itead והמתגים החכמים של S20. אלה בסביבות 12 דולר ארה”ב כל אחד עבור מודולי S20 ו- 8.50 $ עבור בקרי האור כה משמעותיים פחות מכל אחד ממודולי Z-Wave בשוק. הם מגיעים עם הקושחה של ITEAD שנשלטת מאפליקציית iOS או אנדרואיד, אך רציתי להיות מסוגלת להשתמש בקוד של פיטר. פיטר עשה מחקר בנושא ומצא כי עם שינויים קלים בקוד שלו, הוא יתכנת ליחידות ה- ITEAD ולעבוד. אתה זקוק ל- USB ל- UART עם פלט 3.3 וולט כדי לעשות זאת אבל זה פשוט מספיק אם אתה יכול להפעיל ברזל הלחמה. החיסרון היחיד הוא שמודולי ה- ITEAD מגיעים עם פלאש 512KB ולאפשר לקוד של פיטר לבצע עדכוני OTA, עלינו לשנות את זה ל 8MB. ה- IC של הזיכרון הוא בסביבות 3 $ עבור 5 ב- eBay. חמושים בתחנת עבודת אוויר חם (לווה חברים אם אין לך כזה) העבודה מהירה ואינה מסתכנת בפגיעה בלוחות. התמונה הבאה מציגה את ה- SOIC IC למעלה משמאל לאחר הסרת הישן והחדשה המותאמת.

עליכם גם להלחם על כותרת לשורה היחידה של 4 חורים ב- PCB. זה מיישם כוח על הלוח ומאפשר לך לתכנת אותו עם הקושחה MQTT המותאמת אישית. יש לי בלוג מפורט כיצד לעשות זאת.

מודולי ה- S20 נראים חכמים ומודרניים מאוד. מתג ההפעלה מאפשר לך להפעיל ולכבות אותו באופן מקומי. אלה המוצגים כאן הם שקעי יורו אך ITEAD יציעו אפשרויות ארה”ב וגם בבריטניה בקרוב מאוד.

מודולי Slampher הם בקרי מנורה מבוססי ES27, כך שאינם אידיאליים לבריטניה כרגע אך הם עובדים טוב מאוד.

בהתחשב בכך שהם מציעים את מודולי המתג כבריטניה, הייתי מצפה שגרסת כידון עשויה להגיע בקרוב. אני למעשה מעדיף את סוג הבורג עכשיו להתקנה קלה יותר.

אלה קלים לפתוח ולשנות כמו קודם עם צעד נוסף נוסף מלבד החלפת ה- Flash IC וזה להעביר קישור יחיד של אוהם אוהם FR FR

Leave a Reply

Your email address will not be published. Required fields are marked *