Node-Red and Grafana

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.

My sensor node tracking the lighting conditions of our windows.

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.

Grafana was really easy to set up and use.

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:

  1. If there is direct sunlight, close the shades.
  2. If the sun has set, close the shades.
  3. 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:

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.