Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Node-RED Temperature Automation

By: Chonz R. (June/8/2018)

Synopsis:

After this project (~40min) you should be able to turn on a digital output pin on the raspi from
nodered generated analog data coming form DHT11/22 sensor as well as outside temperature.
So if either one is higher than setpoint, pin will go high. A timestamp inject node will send input
data every 10 min. and email warnings if temperature passes certain point. Using a relay, we
can control high voltage loads from raspi pin (i.e. AC motor fan).

We will need internet on the raspi for outdoor weather information. Creating the user
interface(ui) will allow us to access the raspi generated data locally on any computer with
internet. This project was tested on a fresh install of Rasbian Stretch.

SSH (secure shell) with programs like PuTTY will make this easier as you can copy cmnds from
this document and paste them in Lxterm on any other LAN connected computer you have. To
do this turn on SSH (go to preferences – Raspi Configuration - interfaces). Open Putty on your other
computer and put IP of raspi for host. (default user is – pi && default pass is – raspberry)
You might also want to checkout WinSCP for easy files transfer to/from computer and raspi.
*Not necessary for this project.

-------------------------------------------------------------------------------------------------------------------------------

Used Hardware:

 Raspberry Pi
 DHT-22 or DHT-11 sensor (dht11 is less accurate/precise)
 2N3904 Transistor (NPN BJT)
 S108T02 solid-state relay (coil relays should work as well)
 120 VAC Fan (or w.e. device for the relay to turn on; will need to open one side of the power
cable for switch control with the relay, be sure its unplugged 1st especially if its 120V.
 Resistors-
o 10KΩ
o 330Ω
o 4.7KΩ
 Breadboard & various jumper cables (mainly F/M)

-------------------------------------------------------------------------------------------------------------------------------

Instructions:

Make sure internet is connected to raspi. Put in Lxterm

 sudo apt-get update && sudo apt-get upgrade


st
1 install ui nodes from the Lxterm
Get the npm directory 1st
 uname –m (shows processor version. Mine showed armv71
however the following cmnds worked with the
armv61 text only)
 wget https://nodejs.org/dist/v8.9.0/node-v8.9.0-linux-
armv6l.tar.gz
 tar -xzf node-v8.9.0-linux-armv6l.tar.gz
 cd node-v6.11.1-linux-armv6l/
 sudo cp -R * /usr/local/

node –v and npm –v should show the versions of either.

 npm install node-red-contrib-ui (buncha WARN signs pop up but don’t worry)
 cd node_modules
 mv node-red-contrib-ui ~/.node-red/node_modules
 cd
 rmdir node_modules

1st need to install bcm2835 library before DHT sensor node. Find current version at
http://www.airspayce.com/mikem/bcm2835/
Replace 1.57 wherever its stated below with w.e. is newer
 wget http://www.open.com.au/mikem/bcm2835/bcm2835-1.57.tar.gz
 tar zxvf bcm2835-1.57.tar.gz
 cd bcm2835-1.57
 ./configure
 make
 sudo make check (Total should = 1 Pass)
 sudo make install
 cd

Start NodeRED to get into the graphical user interface (GUI)


 node-red-start
open a web browser and type in the url your ip address with :1880 (i.e. 192.168.0.10:1880)
You should now be in the NodeRED GUI.
Install the rest below from the Manage palette option within the icon.

-DHT-22/11 node (node-red-contrib-dht-sensor)

-Openweathermap node (node-red-node-openweathermap)


-Boolean logic node (node-red-contrib-boolean-logic)

-Button, gage, text and tab nodes from (Node-red-dashboard)

Finally refresh nodered from Lxterm:

 node-red-stop
 node-red-start

JSON code for this project is posted on website (chansey.weebly.com) named node-

red_weathermap_dht_json.txt. To use, copy paste it into clipboard (go to , import,


clipboard)

-------------------------------------------------------------------------------------------------------------------------------
Schematic:
-------------------------------------------------------------------------------------------------------------------------------
Node Expanation: Change the inject node(timestamp) to send as often as you like.

Step 2: Double click the “Open Weather Map” node and configure your City and Country:

The weather map app will ask you for an API key. You will need to make a free account on their
website to generate a random API key. Go to -
https://home.openweathermap.org/users/sign_in

site posted in the comment node.


For the ui dashboard you need to set a group name for it to show on the website
(ip address:1880/ui)

Step 5: Connect the email node to the weathermap node and set your email and password.
With this you can monitor the weather conditions on your phone if you are not at
home.(optional)
-------------------------------------------------------------------------------------------------------------------------------

FAQ:

 Used Raspbian Stretch, NodeRed Version-0.18.7, Node Version-4.8.2, NPM Version-1.4.21


 Nodered-dashboard nodes may conflict with ui nodes and ui website will become undefined.
 Manage palette option may not be available if node-red-contrib-ui isn’t installed
 GPIO nodes were already included in the Nodered GUI.
 This cannot be done with FRED(https://fred.sensetecnic.com/) since there is no GPIO nodes.
 Cmnd sudo apt-get -f install npm used to get the npm directory w/o issues.

-------------------------------------------------------------------------------------------------------------------------------

Tips:

Easily add more data analysis from weathermap into the function node. The names used in the
function node are from expanding the complete weather msg payload in the debug tab
-------------------------------------------------------------------------------------------------------------------------------

References:
Project sites:

Chansey.weebly.com
 https://www.hackster.io/ada-energy-17/home-automation-using-raspberry-pi-2-and-node-red-ede8ae

 http://developers.sensetecnic.com/article/how-to-control-almost-anything-with-a-raspberry-pi-2-node-
red-and-wotkit/

Other used sites:

 https://raspberrypi.stackexchange.com/questions/67281/bash-npm-command-not-
found?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
 https://www.instructables.com/id/Install-Nodejs-and-Npm-on-Raspberry-Pi/

AUX sites:

 http://developers.sensetecnic.com/article/using-sqlite-with-fred/
 https://randomnerdtutorials.com/getting-started-with-node-red-on-raspberry-pi/

You might also like