I placed 2 DHT sensors in my house, one in the bath room, the otherone in the living room. Whenever the one in the bath room gets more then 10% higher in humidity then the one in the living room, I want to start the fan.
DHT sensors are connected to ESP8266-12 that feed an MQTT topic on my Pi. Node-Red puts the value into a MySQL data base. I now have a table with sensor’s humidity values updated and an other table where I could put a value according to the condition of 10% higher.
How can I make a request that would put a “on” or “off” value in the second table according to the condition ?
THX
Does that DHT readings values are time stamped?
You can create a function with Node-RED that is triggered every X number of seconds that opens your database and compares the values, if the value is higher it triggers the MQTT topic that sends the on or off command.
When they get into the MQTT file, they are time stemped and into the data base they are also.
What would look like that function ?
There is the flow to put the valu into the database
[{“id”:”ca77ca65.961bf8″,”type”:”mqtt in”,”z”:”1faf2c1f.1ed2d4″,”name”:””,”topic”:”Maison/SS/Humidite”,”qos”:”1″,”broker”:”a42b5e0c.745e8″,”x”:110,”y”:60,”wires”:[[“8899b529.010888”]]},{“id”:”8899b529.010888″,”type”:”function”,”z”:”1faf2c1f.1ed2d4″,”name”:”Maison/SS/Humidite”,”func”:”msg.topic = \”REPLACE INTO Capteurs VALUES (‘1’, ‘Maison/SS/Humidite’,’\” + msg.payload + \”‘,now());\”;\nreturn msg;”,”outputs”:1,”noerr”:0,”x”:400,”y”:60,”wires”:[[“856ef26c.95f8f”]]},{“id”:”6055c210.ce4f7c”,”type”:”mqtt in”,”z”:”1faf2c1f.1ed2d4″,”name”:””,”topic”:”Maison/RC/Salle_Bain/Hum”,”qos”:”1″,”broker”:”a42b5e0c.745e8″,”x”:140,”y”:240,”wires”:[[“7d997ae2.95cfe4”]]},{“id”:”7d997ae2.95cfe4″,”type”:”function”,”z”:”1faf2c1f.1ed2d4″,”name”:”Maison/RC/Salle_Bain/Hum”,”func”:”msg.topic = \”REPLACE INTO Capteurs VALUES (‘4’, ‘Maison/RC/Salle_Bain/Hum’,’\” + msg.payload + \”‘,now());\”;\nreturn msg;”,”outputs”:1,”noerr”:0,”x”:420,”y”:240,”wires”:[[“856ef26c.95f8f”]]},{“id”:”856ef26c.95f8f”,”type”:”mysql”,”z”:”1faf2c1f.1ed2d4″,”mydb”:”948bddb2.bfe6b”,”name”:”DomotiquePi”,”x”:710,”y”:140,”wires”:[[“7579428.e533abc”]]},{“id”:”a42b5e0c.745e8″,”type”:”mqtt-broker”,”z”:”1faf2c1f.1ed2d4″,”broker”:”DomotiquePi”,”port”:”1883″,”clientid”:””,”usetls”:false,”compatmode”:true,”keepalive”:”60″,”cleansession”:true,”willTopic”:””,”willQos”:”0″,”willPayload”:””,”birthTopic”:””,”birthQos”:”0″,”birthPayload”:””},{“id”:”948bddb2.bfe6b”,”type”:”MySQLdatabase”,”z”:”1faf2c1f.1ed2d4″,”host”:”127.0.0.1″,”port”:”3306″,”db”:”MQTT”,”tz”:”cdt”}]
THX