Category

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 noend of trouble and being Windows 10 it would decide it would update itself without my permission. Time to make the move to Linux.

So, based on the blog from Peter I decided to get out my Raspberry Pi3 with its 7″ LCD and fire up Node-Red. Node-Red for those who have no seen this is a very nice and stable drag and drop control software. At first it was daunting to setup but after about a week of playing I started to find that it was very easy to get to grips with. If you have any programming skills, then you will feel at home with the scripting. All the modules are provided as Java script source and there is a huge and ever increasing library for it on the Node-Red website.

Next I needed an MQTT broker as the software from Peter communicates using this protocol. once you have setup and used MQTT, you quickly realise how efficient it is on your network. There is no need to poll devices or even to know the devices IP address. The broker takes care of this. Those familiar with xAP will understand this.

Using Node-Red I setup various timers (thanks to Peter again for his BigTimer) and switch on the lights at night. using a Wemo plugin I now also had control of the Wemo Lamps albeit only on and off. The developer of the Node-Red plugin has promised dimming control at some point in time.

Ok, so I had Node-Red and MQTT setup but now I needed a way to control the lights and switches by both voice and some form of mechanical or touch interface. I ran across some wireless switches from Enocean on the Element14 website so I ordered a couple of them along with the Raspberry Pi Enocean module which plug into the GPIO pins on the Pi and uses the UART to communicate with Node-Red and a plugin.

The switches have a perk in that there is no battery to install or take care of. They use energy harvesting through a coil and magnet that is activated as you press the button. They sadly don’t come with any wall fixtures so you have to design your own. They do provide a toggle button STL file that you can get 3D printed so I used this and created my own mounting for them. This serves 2 purposes, one to cover the old switch on the wall ensuring it remains in the ON position so that the lamp modules are always on and secondly to locate the controls in a familiar location.

Using the Node-Red Enocean plug in I get a message payload with the button states. By parsing this in a Node-Red switch I can send the appropriate command to the light or switch etc. This is an example of the payload sent by the Enocean switch. It’s encoded in JSON format so easy to parse. The ID and V are what we are interested in.

{ “payload”: { “id”: “002d0932”, “v”: “A0 down”, “unit”: “”, “rssi”: -76, “type”: “state”, “EEP”: “f6-02-03”, “man”: “ENOCEAN_GMBH”, “Desc”: “Rocker switch”, “rV”: “30”, “rawByte”: “55000707017af630002d09323001ffffffff4c000d” }, “_msgid”: “3e6d4c8f.c192b4” }

The following image shows the switch which has 4 outputs based on the msg.payload.v value in the telegram from the Enocean switch. These are then directed to the appropriate device. I use the toggle feature within the MQTT firmware to switch the device on and off from the same switch. This means I have up to 4 switch states from each Enocean module.

Now the fun part begins because I have an Amazon Echo and I have always wanted to control my home with voice commands. You can blame SciFi for this

There is no direct Echo support, at least not without having an HTTPS connection to your Node-Red and that sadly is impossible with my ISP so I needed an alternative. using this Amazon Echo HABridge from running on the same Raspberry Pi3 I could not setup voice activate lights etc. The HABridge emulates a Philips hue API so the Echo sees the devices you setup. here is an example of a device which is called Front room Fan.

By uttering the following at the Echo, the fan can be turned on. “Alexa, turn on front room fan” or off by saying “Alexa, turn off front room fan”

The HABridge sends the commands to Node-Red via an HTTP request and I then parse the URL for the values. This is a simple script as shown below.

How to do this with low cost Modules

Having designed my own PCB’s to replace the modules I needed a way to add additional switch modules and light controllers.

My own home made units cost around US$15 to make with all the PCB’s and the parts together. So still low cost.

#
Preview
Product
Rating
តមលៃ

ចេក

Jane Choi Raspberry Pi 4 B model B 8GB Starter kit (8GB RAM)-Motherboard 64GB SD Card, Coolingកង្ហារ …

121 ការពិនិត្យឡើងវិញ

£ 222.99

ទិញនៅលើក្រុមហ៊ុន Amazon

2

Raspberry PI 400 4GB ការចាប់ផ្តើមផ្លូវការប្លង់ចក្រភពអង់គ្លេស

215 ការពិនិត្យឡើងវិញ

£ 110.56

ទិញនៅលើក្រុមហ៊ុន Amazon

បី

ឧបករណ៍ចាប់ផ្តើមដំបូងសម្រាប់ Raspberry Pi 4 B 3 B 3 B + 400, 561 ទំព័រការបង្រៀនលម្អិត Python C …

2,835 ការពិនិត្យឡើងវិញ

£ 42.95

ទិញនៅលើក្រុមហ៊ុន Amazon

ដើម្បីទទួលបាននេះសូម្បីតែទាបជាងនេះខ្ញុំបានមកឆ្លងកាត់ស្ទូឌីយោអ៊ីស្ទូស្ទូសស្ទូឌីយោនិងប្តូរ S20 Smart Smary ។ ទាំងនេះមានប្រហែល 12 ដុល្លារសម្រាប់ម៉ូឌុល S20 និង 8.50 ដុល្លារសម្រាប់ឧបករណ៍បញ្ជាពន្លឺដែលអាចពិចារណាបានតិចជាងម៉ូឌុលរលក Z នៅលើទីផ្សារ។ ពួកគេភ្ជាប់មកជាមួយកម្មវិធីបង្កប់ផ្ទាល់ខ្លួនរបស់អ៊ីអ៊ីធីដែលត្រូវបានគ្រប់គ្រងពីកម្មវិធី iOS ឬ Android ប៉ុន្តែខ្ញុំចង់មានលទ្ធភាពប្រើក្រមរបស់ពេត្រុស។ ពេត្រុសបានធ្វើការស្រាវជ្រាវខ្លះទៅលើរឿងនេះហើយបានរកឃើញថាជាមួយនឹងការផ្លាស់ប្តូរបន្តិចបន្តួចចំពោះក្រមរបស់គាត់វានឹងត្រូវដាក់កម្មវិធីអ៊ីនធឺណេតនិងការងារ។ អ្នកត្រូវការយូអេសប៊ីទៅអ៊ូរជាមួយនឹងទិន្នផល 3.3v ដើម្បីធ្វើដូចនេះប៉ុន្តែនេះគឺសាមញ្ញគ្រប់គ្រាន់ប្រសិនបើអ្នកអាចប្រើដែកដែលកំពុងសូត្រ។ ការធ្លាក់ចុះតែមួយគត់គឺថាម៉ូឌុលអ៊ីតេគរមានពន្លឺ 512KB និងដើម្បីអនុញ្ញាតឱ្យកូដរបស់ពេត្រុសធ្វើបច្ចុប្បន្នភាព OTA យើងត្រូវប្តូរវាទៅ 8 មេកាបៃ។ ការចងចាំ IC មានប្រហែល 3 ដុល្លារសម្រាប់ 5 នៅលើអ៊ីបេយ។ ប្រដាប់ដោយស្ថេរភាពដំណើរការផ្លូវអាកាសក្តៅ (ខ្ចីមិត្តភក្តិប្រសិនបើអ្នកមិនមាន) ការងារមានល្បឿនលឿនហើយមិនប្រថុយនឹងគ្រោះថ្នាក់ដល់ក្តារ។ រូបភាពខាងក្រោមបង្ហាញពីចំណុចសំខាន់របស់រូបរាងខាងលើបន្ទាប់ពីយកចេញនូវអ្វីដែលចាស់ចេញហើយថ្មីមួយដែលសម។

អ្នកក៏ត្រូវ Solder នៅលើបឋមកថាមួយជួរដេកតែមួយនៃរន្ធចំនួន 4 នៅលើ PCB ។ នេះអនុវត្តថាមពលដល់ក្តារហើយអនុញ្ញាតឱ្យអ្នកសរសេរកម្មវិធីវាដោយកម្មវិធីបង្កប់ MQTT ផ្ទាល់ខ្លួន។ ខ្ញុំមានប្លក់លម្អិតអំពីរបៀបធ្វើនេះ។

ម៉ូឌុល S20 មើលទៅឆ្លាតវៃនិងទំនើប។ កុងតាក់ថាមពលអនុញ្ញាតឱ្យអ្នកបើកនិងបិទវានៅក្នុងស្រុក។ អ្នកដែលបានបង្ហាញនៅទីនេះគឺរន្ធអ៊ឺរ៉ូប៉ុន្តែអ៊ីណុកនឹងផ្តល់ជូនទាំងជម្រើសអាមេរិកនិងអង់គ្លេសឆាប់ៗនេះ។

ម៉ូឌុលរអិលគឺជាឧបករណ៍បញ្ជាចង្កៀងដែលមានមូលដ្ឋាននៅ ES27 ដូច្នេះមិនសមស្របសម្រាប់ចក្រភពអង់គ្លេសនាពេលបច្ចុប្បន្ននេះទេប៉ុន្តែពួកគេធ្វើការបានយ៉ាងល្អ។

ដោយពិចារណាថាពួកគេកំពុងផ្តល់ម៉ូឌុលប្តូរនៅចក្រភពអង់គ្លេសខ្ញុំរំពឹងថាកំណែបាយ័នអាចនឹងមកក្នុងពេលឆាប់ៗនេះ។ ខ្ញុំពិតជាចូលចិត្តប្រភេទវីសឥឡូវសម្រាប់ការតំឡើងកាន់តែងាយស្រួល។

ទាំងនេះងាយស្រួលបើកនិងកែប្រែដូចគ្នានឹងជំហានបន្ថែមមួយផ្សេងទៀតក្រៅពីការជំនួស IC ដែលមានពន្លឺចេញហើយនោះគឺត្រូវផ្លាស់ទីសូន្យ OHM OHM Lev Fr

Leave a Reply

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