Charting SHT30 Temp/Humidity data
Time to do something interesting with data. Let's chart the SHT30 output...
First, let's get it off the MQTT and turn it into something the Dashboard Chart item can use...
The Sonoff Tele MQTT input listens to "tele/sonoff/#", which contain payloads with JSON-like strings. However, the messages include "tele/sonoff/STATE" as well as "tele/sonoff/SENSOR" which is what we want. Because I'm interested in seeing all the messages at the moment, and Node-RED will only show me messages to which it's subscribed, I'm going to use the Switch node to select by specific Topic i.e.
var msg1 = {};
var msg2 = {};
msg1.topic = "temp";
msg1.payload = msg.payload.SHT3X.Temperature;
msg2.topic = "humidity";
msg2.payload = msg.payload.SHT3X.Humidity;
return [[msg1, msg2]];
Then I pipe that off to the Dashboard tab, where it's fed into
First, let's get it off the MQTT and turn it into something the Dashboard Chart item can use...
MQTT -> Selected Topic -> JSON -> 2 Messages/Different Topics |
- tele/sonoff/STATE
- tele/sonoff/SENSOR
It turns out that the msg.payload isn't proper JSON, so if I poke it through the JSONifier node it turns it into JSON i.e.
{"Time":"2018-01-15T18:05:26","SHT3X":{"Temperature":21.4,"Humidity":49.6},"TempUnit":"C"}
which can be readily turned into two messages, with Topics "temp" and "humidity" and their respective values, respectively, in the SHT3X Splitter node i.e.
var msg2 = {};
msg1.topic = "temp";
msg1.payload = msg.payload.SHT3X.Temperature;
msg2.topic = "humidity";
msg2.payload = msg.payload.SHT3X.Humidity;
return [[msg1, msg2]];
Then I pipe that off to the Dashboard tab, where it's fed into
- A Chart node, charting Temp and Humidity, showing values through time
- Two Gauge nodes, showing the current value
Hurray!!
Node-RED Chart node and Gauge nodes in action |
Which results in...
Simple Node-Red Dashboard for Temperature and Humidity from SHT30 Sensor |
Comments
Post a Comment