NodeMCU

MAKE A LIGHT SENSOR WITH NodeMCU

Flash Tasmota (latest version) as follows:

Download tasmota.bin from the following site: https://github.com/arendst/Tasmota/releases

On MacBook, run the app esphome-flasher. Connect the NodeMCU to the MacBook with the USB cable. Refresh the serial port by clicking the double-arrow button.

Select the tasmota.bin file downloaded previously.

Click on Flash ESP button.

The app will first erase any content flashed in the NodeMCU and will start flashing the tasmota.bin file into the NodeMCU device.

Once flashing is completed, NodeMCU will start an Access Point named tasmota_XXXX. Hook on it and use a browser to go to 192.168.4.1.

The following page will appear:

Enter the SSID and the relevant password. Then Save.

NodeMCU will restart and hook on the Wifi defined previously. Its IP Address can be found with Network scanner software. Once found, use a browser and type the IP Address found previoulsy. The following page will appear:

Click on Configuration. The following page will appear:

Click on Configure Module. The following page will appear:

Select Module type as Generic, and select GPIO4 as Switch1.

Click on Save.

Return to Configuration Menu and Select Configure MQTT. The following page will appear:

Fill up the URL of the MQTT Broker, the port on which the broker is listening (default is 1883).

Fill up the User and the User password (these parameters must correspond to the User(s) and password defined in the MQTT configuration).

Last, define the MQTT topic which will correspond to this Light sensor.

Click on Save.

Light Sensor used:

Connect the light Sensor respecting the following:

SensorNodeMCU
VCC3.3Volts
GNDGND
DOGPIO4

Create a Rule (the rule is ON switch1#state=0 DO publish cmnd/node_mcu off ENDON in tasmota language), which will allow to send an MQTT message each time the Light Sensor will change status, by doing what follows:

Return to Main Menu and Select Console. The following page will appear:

Type the Rule (as Rule1) in the command line and press Enter. The Rule1 will be displayed in the console.

Type Rule1 1 to activate the Rule1, and Press Enter.

The job is completed. Check that the MQTT message is sent each time the light sensor changes status by running the following command on any computer where mosquitto_clients has been installed:

mosquitto_sub -h brokerURL -t "stat/node_mcu/POWER" -v

where brokerURL is the IP Address of the device on which the MQTT broker is running.

Note: It is possible to make a Motion Sensor following the same procedure and the following component: