In a previous post we learned how to make the smart light sensor, not we will learn how to integrate it in Node-RED so we can read the value and perform an action when it has changed.

After the sensor is connected to the NodeMCU board and configured we will have to first configure the MQTT server on it, please access the web GUI again and go to Configuration -> Configure MQTT.

Here you can use our free MQTT server if you wish and the settings should look like this:

Once its set and saved, please go back to Main Menu, Console – check what the full topic looks like here and copy it down. You might need to wait up to 5 minutes until the sensor will update the data and displays the topic it has sent it to. Will looks something like this: “qpmzlightsensor01/tele/SENSOR”.

Now we can go in Node-RED and create a flow that will message us on Telegram when the luminosity has changed.

First drag a “mqtt” node into your flow, double click on it to configure, click the Edit button next to the Server field and ensure the MQTT server info is added:

Next, we have to tell the node which topic to read from, hit update and on the node Properties page, add the full topic you have copied down earlier:

Now Node-RED can read the values of the light sensor from the MQTT topic where the sensor is sending them.

To ensure that this is working, we can add a “debug” node to our flow, connect it to read the values of the MQTT node, deploy, and then watch the debug window for values received:

Next, we will add a simple function that will send a message to a smart lamp (Learn from this post how to make your own smart lamp) on a different MQTT topic making it turn on or off depending on the light levels read by the sensor:

You can copy and paste the body of the function into your workflow function:

if (msg.payload > 10) {
msg.payload = 0
} else {
msg.payload = 1;

return msg;

Deploy and its all done! Now your light will turn on whenever the light level is below 10 (you can adjust this to your own preference).