As an exercise, we were asked to play around with Node Red and Grafana, two very powerful tools that have a lot to offer specifically within the IoT realm.
The first thing I did was make sure my sensors were connected to my WiFi network and sending data. This data was is being sent using an MQTT broker. Nothing crazy here, just temperature, humidity, and a photoresistor value. I placed it by my window so that the photoresistor could record nighttime conditions, direct sunlight conditions and ambient daylight conditions. Our window faces due east, so at sunrise, the sensor is bathed in direct sunlight, but after 12:00 PM, it will be in shadow.
Using this data, I set up a simple dashboard on Grafana that graphs temperature, humidity and light, with the current values displayed on the right. At some point, it would be nice to set this up on an iPad in my house displaying multiple zones.
I then began using Node-Red to think of ways that this could be used to add some intelligence. Our blinds are electric, so I figured that a light sensor would be a great way know when to open and close them. Based on the three different light conditions I described earlier, I set up the following rules:
If there is direct sunlight, close the shades.
If the sun has set, close the shades.
Else, open the shades.
I also wanted to use the LED that can be turned on and off using MQTT, so I also added a node that had the LED flash when the blinds were ‘opening’ or ‘closing.’
This proved to actually be the hardest part of the exercise. I had to figure out how to store data using the context and flow methods in Node-Red. Not too challenging but still not necessarily intuitive.
The JSON for this Node-Red flow can be found below: