Hi,
Like many, I have been tinkering with iot environmental monitoring using esp8266 with various sensors to monitor environment (temp, humidity, light, etc) for a while. The result has always been a less than professional outcome and the enclosures are not exactly what you call designer look.
The broadlink A1 enviro sensor (wifi) is a very a neat package at a very reasonable price (few cups of coffee) with a modern designer look, however their app for this is very rudimentary, lacking features and flexibility, and you will have to depend on their servers.
This project using nodered, grabs the raw data output from the A1 and transmit it via mqtt, so if you subscribe to the topic you can do what ever you want anywhere (ie display data, store in google sheets or database, or control other devices depending on the data values, eg turning light at dusk, or aircon when temp reached threshold).
Note: Still a noob with NR, so code or flow may not be most efficient.
Prerequisite:
- Have installed node-red-contrib-broadlink-control and familiar with the configaration of the node.
- Have a mqtt broker setup and configured.
The HW:
Broadlink A1
Nodered Server (in my case Pi3)
SW:
Main Nodes used: MQTT node; Broadlink (node-red-contrib-broadlink-control), function node; dashboard node
Broadcasting the raw data:
Flow 1: Broadcasting the raw data from the A1 to MQTT broker:
The A1 outputs two json objects; payload and raw:
e.g payload: {"temperature":20.7,"humidity":68.3,"light":"Normal","air_quality":"Perfect","noise":"Normal"}
e.g raw:
{"temperature":20.7,"humidity":68.3,"light":2,"air_quality":0,"noise":1}
We want to extract the raw object as it contains numerical values so we can graph them.
The "extract raw" function node extracts the raw object and sent it to the mqtt node.
Function node code:
let raw= msg.raw;
msg.payload = raw;
return msg;
This will broadcast the raw data to the mqtt broker.
The receiving end (subscribing):
As stated I am still a noob with NR, I spend some time trying to parse and extract the data so I can split it and display it on the dashboard.
What I found (I think):
The data a json object when it was sent via mqtt, however mqtt seems to turn it into string at the receiving end. I then tried to extract the string using substring, slpit node, etc and got myself all confused and thing starts to get complicated very quickly...
After few frustrating days, I stumbled upon turning the string back into a json object.
Then it just a matter of extracting the parameter you want:
e.g to extract light:
function node code:
let lightstr= msg.payload.light;
msg.payload = lightstr;
return msg;
The output is then displayed on the dashboard:
By using "FRED" or Serveo or Ngrok a NR environmental display instance can be created anywhere.
I have a few of these sensors around the house, looks good and works!