ITCooky Recipes

Lets cooky it yammy things!

IoT in a big way: Own devices in esp8266 managed through Node-Red!

дата November 12, 2019

One article about Node-Red was not enough for me, I felt he could do more things … but how. Its simplicity bothers and helps. The speed of implementation definitely helps especially to test scripts for esp8266. So I set the task of doing a banal climate module: air quality, humidity, temperature and taking it to the street, and a controlled smart plug, also trivial but complicated, for example, to save the configuration, I had to convert the green to round and write it in the memory of esp8266, which does not exist !!!


I will not write in detail about Node-Red, allready described above here: IoT full-on: In ESP8266 with MQTT via Mosquitto through Node-RED!

It is installed, it also has an additional module and an instrument panel.

NR must also have bricks that set a variable date for the time, here it is. It is needed to write the sensor data in a file, it is necessary in all circuits.

[{"id":"d1f915cf.6b6728","type":"inject","z":"e60c0f81.64c18","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":1300,"wires":[["3292d870.1e3dd8"]]},{"id":"3292d870.1e3dd8","type":"moment","z":"e60c0f81.64c18","name":"","topic":"","input":"","inputType":"msg","inTz":"Europe/Moscow","adjAmount":"3","adjType":"hours","adjDir":"add","format":"","locale":"en_US","output":"time","outputType":"flow","outTz":"Europe/Moscow","x":400,"y":1300,"wires":[[]]}]

By the way, Node-Red is easy to kill, you just have to send MQQT data with esp8266 in a loop without brakes, try to avoid that.

Weather module
For this module, I took from a previous article NodeMcu V3 LoLin, temperature sensor DHT22 and MQ-135
Connection diagram

I made a sandwich like that

The DHT22 has thin legs, I had to stick it with a glue gun, the MQ135 is different, but I’ve also stuck it

The mq135 sensor lives its own life, the readings depend of dont know what. If it is connected to 5v on ESP8266, it shows 17, if it is connects a 5v temperature sensor, mq135 starts to show 500, if it is connected the temperature sensor to 3.3v, it shows 61. It is because it is analog.

It is also important to understand that the sensor needs to warm up. When it is turned on for the first time it is heated for 48 hours, then with a short-term loss of energy for about 10 minutes, after that it comes alive. And in my case it never returned to the same data, it fell from 480 to 200!

Actually, it is called an air quality sensor, and you can only tell if the air is good or bad on a large scale without any precision. And this refers to the street air, it does not catch the bad air in the apartment, I already tried producing several bad airs … (I just put it in my mouth) But on the street there is smoke, maybe gasoline, alcohol ( it depends of the people in the neighborhood)!

If you use the sensors with this library and calibrate, you can get a value similar to ppm: the content of carbon dioxide in the air. It is not exactly important for us, since that sensor was not make for that, the main thing is that up to 350 ppm is excellent for the street, up to 800 indoors: here they explainhttps://habr.com/company/tion/blog/389097/
Calibration in the final assembly is necessary, and the addition of other sensors affects the results of the analog output of air sensor (for some reason)
Doing in like here https://hackaday.io/project/3475-sniffing-trinket/log/12363-mq135-arduino-library
In mq135.h that one which appears after installing the library, t was in path /home/myusername/snap/arduino-mhall119/5/Arduino/collections/MQ135-master in Ubuntu I need to change the resistance value, I decided that I have put 1, by default it is 10 here they explain it https://mysku.ru/blog/aliexpress/41409.html

/// The load resistance on the board
#define RLOAD 1.0

start this code

#include <MQ135.h> 
#define analogPin A0
MQ135 gasSensor = MQ135(analogPin);

void setup() {

  Serial.begin(9600); 
  delay(1000); 

}

void loop() {

 float rzero = gasSensor.getRZero(); // чтение калибровочных данных
 Serial.println(rzero); // выдача в последовательный порт

 delay(5000);
}

We took it to the street for half an hour, the temperature of the street should be at 20 degrees, they say that the humidity is not so important.
I see result en serial port monitoring, it must be written in the same file, it is the line

#define RZERO 567.63

After that, the sensor gives me 682 ppm in the room, it seems like a real value. And the values change in large increments immediately by hundreds …

The dht22 sensor, well, everything is clear about it and has been known for a long time: only the accuracy I evaluate in real conditions us plus – minus 1, and not 0.5 as in datasheet.

The scetch for esp8266: simply sends humidity, temperature, air quality, power status and connection to the MQQT server, flashes once at the time of sending data via the LED, and for a long time when there is no connection, and allows changing the interval of sending data through Node-Red.

here it is

#include <PubSubClient.h>
#include <DHT_U.h>
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <MQ135.h>
#include <EEPROM.h>
 

// Uncomment one of the lines bellow for whatever DHT sensor type you're using!
//#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
#define LED_BUILTIN 2


// Change the credentials below, so your ESP8266 connects to your router
const char* ssid = "imyawifitochki";
const char* password = "parolevoyniy";
const char* mqttUser = "name";
const char* mqttPassword = "passworda";
const char* mqttTopicHumidity = "room0/humidity";
const char* mqttTopicTemperature = "room0/temperature";
const char* mqttTopicGas = "room0/gas";
const char* mqttTopicWifi = "room0/wifistatus";
const char* mqttTopicPower = "room0/powerstatus";


const char* mqttTopicResendTime = "room0/resendtime";
const char* mqttTopicResendTimeStatus = "room0/resendtimestatus";
unsigned long resendtime; 
long resendtimetemp; 

// Change the variable to your MQQT IP address, so it connects to your MQTT broker
const char* mqtt_server = "192.168.1.209";

// DHT Sensor - GPIO 5 = D1 on NodeMCU board
const int DHTPin = 5;

MQ135 gasSensor = MQ135(A0);


// Timers auxiliar variables
unsigned long now = millis();
unsigned long lastMeasure = 0;
float ppm;
boolean wifistatus = false;
boolean powerstatus = false;

// Initializes the espClient. You should change the espClient name if you have multiple ESPs running in your home automation system
WiFiClient espClient;
PubSubClient client(espClient);

// Initialize DHT sensor.
DHT dht(DHTPin, DHTTYPE);


void EEPROMWritelong(int address, long value)
      {
      //Decomposition from a long to 4 bytes by using bitshift.
      //One = Most significant -> Four = Least significant byte
      byte four = (value & 0xFF);
      byte three = ((value >> 8) & 0xFF);
      byte two = ((value >> 16) & 0xFF);
      byte one = ((value >> 24) & 0xFF);

      //Write the 4 bytes into the eeprom memory.
      EEPROM.write(address, four);
      EEPROM.commit();
      EEPROM.write(address + 1, three);
      EEPROM.commit();
      EEPROM.write(address + 2, two);
      EEPROM.commit();
      EEPROM.write(address + 3, one);
      EEPROM.commit();
      }

long EEPROMReadlong(long address)
      {
      //Read the 4 bytes from the eeprom memory.
      long four = EEPROM.read(address);
      long three = EEPROM.read(address + 1);
      long two = EEPROM.read(address + 2);
      long one = EEPROM.read(address + 3);

      //Return the recomposed long by using bitshift.
      return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
      }
      

void setup() {
  EEPROM.begin(8); 
  dht.begin();
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  pinMode(LED_BUILTIN, OUTPUT); 
  resendtimetemp = EEPROMReadlong(1);
  resendtime = 1000 * resendtimetemp + 500;
  client.setCallback(callback);
}

void callback(String topic, byte* message, unsigned int length) {
  String messageTemp; 
  for (int i = 0; i < length; i++) {
   messageTemp += (char)message[i];
  };
  

 if(topic==mqttTopicResendTime){
resendtimetemp = messageTemp.toInt();
static char TimeResend[7];
    dtostrf(resendtimetemp, 6, 0, TimeResend);
client.publish(mqttTopicResendTimeStatus, TimeResend);
EEPROMWritelong(1, resendtimetemp);
resendtime = 1000 * resendtimetemp; 
delay(500);
 };
 

      
}
// DThis functions connects your ESP8266 to your router
void setup_wifi() {
  delay(10);  
  WiFi.begin(ssid, password);
}


// This functions reconnects your ESP8266 to your MQTT broker 
void reconnect() {
if (client.connect(WiFi.hostname().c_str(), mqttUser, mqttPassword)) {
 
  client.subscribe(mqttTopicResendTime);
  } else {
      // Wait 5 seconds before retrying
      delay(500);
    }
}


void loop() {

now = millis();

  //dont know what this string does, but without it all does not work
 if(!client.loop()) 
     client.connect("blabla");

   if (!client.connected()) {
   digitalWrite(LED_BUILTIN, LOW); 
    reconnect(); 
   digitalWrite(LED_BUILTIN, HIGH);   
     };
       
if (now - lastMeasure > resendtime) {
lastMeasure = now;
if (client.connected()) { 
    
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h = dht.readHumidity();
    // Read temperature as Celsius (the default)
    float t = dht.readTemperature();
    // Computes temperature values in Celsius
    float hic = dht.computeHeatIndex(t, h, false);
    static char temperatureTemp[7];
    dtostrf(hic, 6, 1, temperatureTemp);   
    static char humidityTemp[7];
    dtostrf(h, 6, 1, humidityTemp);
    //mq135
    //SensorGas = analogRead(0);
    float ppm = gasSensor.getPPM();
    static char GasTemp[7];
    dtostrf(ppm, 6, 0, GasTemp);
    
    // Publishes values
   digitalWrite(LED_BUILTIN, LOW);
    if (!wifistatus)
        {
            client.publish(mqttTopicWifi, "0");
            wifistatus = true;
        } else {
            client.publish(mqttTopicWifi, "1"); 
     };
     if (!powerstatus)
        {
            client.publish(mqttTopicPower, "0");
            powerstatus = true;
        } else {
            client.publish(mqttTopicPower, "1"); 
     };
   client.publish(mqttTopicTemperature, temperatureTemp);
   client.publish(mqttTopicHumidity, humidityTemp);
   client.publish(mqttTopicGas, GasTemp);

static char TimeResend[7];
    dtostrf(resendtimetemp, 6, 0, TimeResend);
client.publish(mqttTopicResendTimeStatus, TimeResend);

   digitalWrite(LED_BUILTIN, HIGH);
    } else {
  wifistatus = false;
      };
  };
}

The libraries at the beginning of the script are standard and from the previous article but for the record:

Download the library for the temperature and humidity sensor dht22 https://github.com/adafruit/DHT-sensor-library/archive/master.zip and that one too https://github.com/adafruit/Adafruit_Sensor/archive/master.zipAdd it to the program through the menu Scretch > Include Library > Add .ZIP Library

Now, on Node-Red, the following bricks are responsible for this module.

foto

And the text with all the settings, you can immediately add to your Node-Red through the import

[{"id":"66632934.7d2108","type":"ui_chart","z":"e60c0f81.64c18","name":"Temperature","group":"bc9278be.b3a778","order":2,"width":"0","height":"0","label":"Temperature","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#8e0911","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":610,"y":1440,"wires":[[],[]]},{"id":"dd1d964c.587a48","type":"mqtt in","z":"e60c0f81.64c18","name":"Temperature","topic":"room0/temperature","qos":"2","broker":"572eed08.5bb714","x":410,"y":1400,"wires":[["66632934.7d2108","e4fe9e7e.ad3bd","2642c360.3f098c"]]},{"id":"59b169c0.45d7c8","type":"file","z":"e60c0f81.64c18","name":"Write temp_room0.log","filename":"/root/iot_data/temp_room0.log","appendNewline":true,"createDir":false,"overwriteFile":"false","x":840,"y":1400,"wires":[[]]},{"id":"e4fe9e7e.ad3bd","type":"function","z":"e60c0f81.64c18","name":"Add time to data","func":"var timenow=flow.get('time');\nmsg.payload = timenow + ' '+ msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":1400,"wires":[["59b169c0.45d7c8"]]},{"id":"55dd3d19.1cb534","type":"mqtt in","z":"e60c0f81.64c18","name":"Humidity","topic":"room0/humidity","qos":"2","broker":"572eed08.5bb714","x":400,"y":1540,"wires":[["2204294a.0fe706","6601b62f.9280f8","5c8f1bbc.113754"]]},{"id":"5b4fb0e2.0fe7c","type":"file","z":"e60c0f81.64c18","name":"Write humi_room0.log","filename":"/root/iot_data/humi_room0.log","appendNewline":true,"createDir":false,"overwriteFile":"false","x":840,"y":1540,"wires":[[]]},{"id":"2204294a.0fe706","type":"function","z":"e60c0f81.64c18","name":"Add time to data","func":"var timenow=flow.get('time');\nmsg.payload = timenow + ' '+ msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":1540,"wires":[["5b4fb0e2.0fe7c"]]},{"id":"7f21c47e.cd05ec","type":"mqtt in","z":"e60c0f81.64c18","name":"MQQT 0 status","topic":"room0/wifistatus","qos":"2","broker":"572eed08.5bb714","x":420,"y":1780,"wires":[["64b4189d.f8b998"]]},{"id":"64b4189d.f8b998","type":"ui_chart","z":"e60c0f81.64c18","name":"MQQT status","group":"ee36947a.ec2f48","order":1,"width":0,"height":0,"label":"MQQT was lost at","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"1","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"colors":["#000000","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#77090a","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":590,"y":1780,"wires":[[],[]]},{"id":"4e04c12d.74d74","type":"mqtt in","z":"e60c0f81.64c18","name":"Power","topic":"room0/powerstatus","qos":"2","broker":"572eed08.5bb714","x":390,"y":1840,"wires":[["da433eb8.d0b53"]]},{"id":"da433eb8.d0b53","type":"ui_chart","z":"e60c0f81.64c18","name":"Power","group":"ee36947a.ec2f48","order":2,"width":0,"height":0,"label":"Power was lost at","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"1","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"colors":["#000000","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#680808","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":570,"y":1840,"wires":[[],[]]},{"id":"de1fc131.312c1","type":"mqtt in","z":"e60c0f81.64c18","name":"Air Quality","topic":"room0/gas","qos":"2","broker":"572eed08.5bb714","x":400,"y":1660,"wires":[["74651f53.e4a4","466ebb3f.6f3764","3cb75aee.0a3c16"]]},{"id":"74651f53.e4a4","type":"ui_chart","z":"e60c0f81.64c18","name":"Gas","group":"bc9278be.b3a778","order":6,"width":0,"height":0,"label":"Air Quality","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#24a516","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":570,"y":1700,"wires":[[],[]]},{"id":"6601b62f.9280f8","type":"ui_chart","z":"e60c0f81.64c18","name":"Humidity","group":"bc9278be.b3a778","order":4,"width":"0","height":"0","label":"Humidity","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#0971c1","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":600,"y":1580,"wires":[[],[]]},{"id":"f15544ba.4e3c58","type":"ui_slider","z":"e60c0f81.64c18","name":"","label":"slider","group":"1022d713.859ec9","order":2,"width":0,"height":0,"passthru":true,"outs":"end","topic":"room0/resendtime","min":"15","max":"600","step":"5","x":390,"y":1900,"wires":[["eb3a4359.710b3"]]},{"id":"eb3a4359.710b3","type":"mqtt out","z":"e60c0f81.64c18","name":"","topic":"room0/resendtime","qos":"","retain":"","broker":"572eed08.5bb714","x":590,"y":1900,"wires":[]},{"id":"aa44d360.ad6e4","type":"mqtt in","z":"e60c0f81.64c18","name":"resend time","topic":"room0/resendtimestatus","qos":"2","broker":"572eed08.5bb714","x":410,"y":1960,"wires":[["20197ac3.af7b56"]]},{"id":"20197ac3.af7b56","type":"ui_text","z":"e60c0f81.64c18","group":"1022d713.859ec9","order":1,"width":0,"height":0,"name":"","label":"Weather sensors - send and check  data  every (seconds):","format":"{{msg.payload}}","layout":"col-center","x":750,"y":1960,"wires":[]},{"id":"2642c360.3f098c","type":"ui_text","z":"e60c0f81.64c18","group":"bc9278be.b3a778","order":1,"width":0,"height":0,"name":"","label":"Temperature now is","format":"{{msg.payload}}","layout":"row-center","x":630,"y":1480,"wires":[]},{"id":"5c8f1bbc.113754","type":"ui_text","z":"e60c0f81.64c18","group":"bc9278be.b3a778","order":3,"width":0,"height":0,"name":"","label":"Humidity now is ","format":"{{msg.payload}}","layout":"row-center","x":620,"y":1620,"wires":[]},{"id":"466ebb3f.6f3764","type":"ui_text","z":"e60c0f81.64c18","group":"bc9278be.b3a778","order":5,"width":0,"height":0,"name":"","label":"Air quality now is","format":"{{msg.payload}}","layout":"row-center","x":610,"y":1740,"wires":[]},{"id":"4571b392.d9b66c","type":"file","z":"e60c0f81.64c18","name":"Write air_room0.log","filename":"/root/iot_data/air_room0.log","appendNewline":true,"createDir":false,"overwriteFile":"false","x":830,"y":1660,"wires":[[]]},{"id":"3cb75aee.0a3c16","type":"function","z":"e60c0f81.64c18","name":"Add time to data","func":"var timenow=flow.get('time');\nmsg.payload = timenow + ' '+ msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":1660,"wires":[["4571b392.d9b66c"]]},{"id":"bc9278be.b3a778","type":"ui_group","z":"","name":"Weather Data","tab":"c5ac561a.7e8ef8","order":1,"disp":true,"width":"10","collapse":false},{"id":"572eed08.5bb714","type":"mqtt-broker","z":"","name":"Mosquitto Orange","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"ee36947a.ec2f48","type":"ui_group","z":"","name":"Weather Status","tab":"c5ac561a.7e8ef8","order":3,"disp":true,"width":"10","collapse":false},{"id":"1022d713.859ec9","type":"ui_group","z":"","name":"Weather Send/Check interval Settings","tab":"5d7f916a.3be03","order":4,"disp":true,"width":"6","collapse":false},{"id":"c5ac561a.7e8ef8","type":"ui_tab","z":"","name":"Weather","icon":"dashboard","order":2},{"id":"5d7f916a.3be03","type":"ui_tab","z":"","name":"Settings","icon":"dashboard","order":4}]

After importing something, don’t forget to click on Deploy in NR

These bricks give us 24-hour statistics on the Weather tab in the Node-Red user interface

The power chart shows when the module was turned off or restarted; After turning it on, the graph will show line drop. MQQT monitors the status of WiFi connections.
In addition, on the Settings tab in the Node-Red UI, the tab Weather Send/Check interval Settings allows you to configure the update interval, which is stored in esp8266’s memory

IMPORTANT: on the first start after uploading scetch to esp8266, it is necessary to set the update interval in the Weather Send/Check interval Settings box on the Configuration tab in the Node-Red user interface, otherwise there can be any number, it is taken from an empty place in memory, but it may not be empty

Now about power. I wanted to power wirelessly through glass, unfortunately this technology is not so strong, in fact only 8 mm is transmitted from the base.
I bought this 18650 Battery shield V3 for Raspberry Pi WEMOS for Arduino Micro Type usb-USB; I will not give a link because it is not worth buying. This should work as a UPS; the power turns off; the battery turns on; the power turns on; the battery charges from power. In real life, it does not always turn on even from the battery: the Chinese did not copy it completely, or the original was the same … The power is welded at 3v, i also try 5v: no matter how it is connected, it does not act as a UPS ! I have a hamburger like that


I throw it out, it works for 22-24 hours, the real charge of the Samsung 18650 chines battery is 1000 mAh I have measured it with USB power tester. The main consumer is the air sensor.


Smart outlet module with temperature and humidity sensor

This is how it looks, done with what was in Leroy Merlin

As a base, two parquet sticks were selected, glued with carpentry glue. 2.5 mm cables, terminals Wago Terminal 5 connectors for 26.6 × 14 × 5 × 20.5 mm cables, polyamide, 5 pieces: the cables has to be inserted with force. Everything just entered to the distribution box of 120x80x50 mm, IP5: the cables take up a lot of space. Drill a hole, seal it with scotch on one side and fill it with a glue gun, it turned out to be an excellent window for the LED. Plug Schneider Electric grounded outlets, gray IP44 is an excellent plug and its made in Russia(not in German), several can be assembled in a row, there is space to put the wires, it is a pity that you can not turn the cover, only in one position, for which interferes when the two are close.

Here is a diagram. The relays are no longer sold, but I think they are all the same (I have vcc-gnd): I only need to connect 5v to a good source, it didn’t work for me from Lolin (although there is a 5v), I connected it directly to the charger – This is a disaggregated USB Auchan charge (120 RUR).

The price og all components its 1500 rubles – it is the value of a Chinese Wi-Fi plug, but you cannot program it for what you need! The assembly takes a lot of tme time and, for some reason, the fingers start to bleed …

Here is the LoLin scketch

#include "PubSubClient.h";
#include "DHT_U.h";
#include "DHT.h";
#include "ESP8266WiFi.h";
#include "EEPROM.h";

// Uncomment one of the lines bellow for whatever DHT sensor type you&#039;re using!
//#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
#define LED_BUILTIN 2

// Change the credentials below, so your ESP8266 connects to your router
const char* ssid = "mYwIfI";
const char* password = "PASSword";
const char* mqttUser = "IOTman";
const char* mqttPassword = "PASSiot";

const char* mqttTopicHumidity = "room1/humidity";
const char* mqttTopicTemperature = "room1/temperature";
const char* mqttTopicWifi = "room1/wifistatus";
const char* mqttTopicPower = "room1/powerstatus";
// power 1 settings start
const char* mqttTopicButtonPower1 = "power/buttonunit1";
const char* mqttTopicButtonStatusPower1 = "power/buttonstatusunit1";
const char* mqttTopicPower1status = "power/unit1status";
int buttonpower1;
const char* mqttTopicButtonPower1auto = "power/buttonunit1auto";
const char* mqttTopicButtonStatusPower1auto = "power/buttonstatusunit1auto";
int buttonpower1auto;
const char* mqttTopicButtonPower1case = "power/buttonunit1case";
const char* mqttTopicButtonStatusPower1case = "power/buttonstatusunit1case";
int buttonpower1case;
const char* mqttTopicButtonPower1temp = "power/buttonunit1temp";
const char* mqttTopicButtonStatusPower1temp = "power/buttonstatusunit1temp";
int8_t buttonpower1temp;
const char* mqttTopicButtonPower1time = "power/buttonunit1time";
const char* mqttTopicButtonStatusPower1time = "power/buttonstatusunit1time";
unsigned long buttonpower1time;
unsigned long lastMeasure21 = 0;
unsigned long reruntime; 
// power 1 settings end

// power 2 settings start
const char* mqttTopicButtonPower2 = "power/buttonunit2";
const char* mqttTopicButtonStatusPower2 = "power/buttonstatusunit2";
const char* mqttTopicPower2status = "power/unit2status";
int buttonpower2;
const char* mqttTopicButtonPower2auto = "power/buttonunit2auto";
const char* mqttTopicButtonStatusPower2auto = "power/buttonstatusunit2auto";
int buttonpower2auto;
const char* mqttTopicButtonPower2case = "power/buttonunit2case";
const char* mqttTopicButtonStatusPower2case = "power/buttonstatusunit2case";
int buttonpower2case;
const char* mqttTopicButtonPower2temp = "power/buttonunit2temp";
const char* mqttTopicButtonStatusPower2temp = "power/buttonstatusunit2temp";
int8_t buttonpower2temp;
const char* mqttTopicButtonPower2time = "power/buttonunit2time";
const char* mqttTopicButtonStatusPower2time = "power/buttonstatusunit2time";
unsigned long buttonpower2time;
unsigned long lastMeasure22 = 0;
unsigned long reruntime2; 
// power 2 settings end


// Change the variable to your Raspberry Pi IP address, so it connects to your MQTT broker
const char* mqtt_server = "192.168.1.209";


const int DHTPin = 1;
const int power1 = 4;
const int power2 = 5;
int tempwarning = 3;
int Nt = 0;
int Nh = 0;
boolean wifistatus = false;
boolean powerstatus = false;


// Timers auxiliar variables
unsigned long now = millis();
unsigned long lastMeasure = 0;

const char* mqttTopicResendTime = "room1/resendtime";
const char* mqttTopicResendTimeStatus = "room1/resendtimestatus";
unsigned long resendtime = 30000; 
long resendtimetemp; 

//eeprom memory use
//power1 settings
// 1,2,3,4,5-8,
//power2 settings
// 9,10,11,12,13-16,
//data resend time
// 17-20

// Initializes the espClient.
WiFiClient espClient;
PubSubClient client(espClient);

// Initialize DHT sensor.
DHT dht(DHTPin, DHTTYPE);


void setup() {
  EEPROM.begin(32);
  dht.begin();
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  pinMode(power2, OUTPUT); 
  pinMode(power1, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  // power 1 settings start
 buttonpower1 = EEPROM.read(1);
 buttonpower1auto = EEPROM.read(2);
 buttonpower1case = EEPROM.read(3);
 buttonpower1temp = (int8_t)EEPROM.read(4);
 buttonpower1time = EEPROMReadlong(5);
 reruntime = 60000 * buttonpower1time;
 // power 1 settings end

   // power 2 settings start
 buttonpower2 = EEPROM.read(9);
 buttonpower2auto = EEPROM.read(10);
 buttonpower2case = EEPROM.read(11);
 buttonpower2temp = (int8_t)EEPROM.read(12);
 buttonpower2time = EEPROMReadlong(13);
 reruntime2 = 60000 * buttonpower2time;
 // power 2 settings end

 resendtimetemp = EEPROMReadlong(17);
 resendtime = 1000 * resendtimetemp + 500;
 
digitalWrite(power2, HIGH);
digitalWrite(power1, HIGH);
  client.setCallback(callback);
  //Serial.begin(9600);
}


//This function will write a 4 byte (32bit) long to the eeprom at
//the specified address to address + 3.
void EEPROMWritelong(int address, long value)
      {
      //Decomposition from a long to 4 bytes by using bitshift.
      //One = Most significant -> Four = Least significant byte
      byte four = (value & 0xFF);
      byte three = ((value >> 8) & 0xFF);
      byte two = ((value >> 16) & 0xFF);
      byte one = ((value >> 24) & 0xFF);

      //Write the 4 bytes into the eeprom memory.
      EEPROM.write(address, four);
      EEPROM.commit();
      EEPROM.write(address + 1, three);
      EEPROM.commit();
      EEPROM.write(address + 2, two);
      EEPROM.commit();
      EEPROM.write(address + 3, one);
      EEPROM.commit();
      }

long EEPROMReadlong(long address)
      {
      //Read the 4 bytes from the eeprom memory.
      long four = EEPROM.read(address);
      long three = EEPROM.read(address + 1);
      long two = EEPROM.read(address + 2);
      long one = EEPROM.read(address + 3);

      //Return the recomposed long by using bitshift.
      return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
      }
      
// Don't change the function below. This functions connects your ESP8266 to your router
void setup_wifi() {
  delay(10);
  // We start by connecting to a WiFi network
  WiFi.begin(ssid, password);

}

// This functions is executed when some device publishes a message to a topic that your ESP8266 is subscribed to
// Change the function below to add logic to your program, so when a device publishes a message to a topic that 
// your ESP8266 is subscribed you can actually do something
void callback(String topic, byte* message, unsigned int length) {
  String messageTemp; 
  for (int i = 0; i < length; i++) {
   messageTemp += (char)message[i];
  };
  
// power 1 settings start 
  if(topic==mqttTopicButtonPower1){
     if(messageTemp == "do"){       
if (buttonpower1 == 1)
{
client.publish(mqttTopicButtonStatusPower1, "off");
client.publish(mqttTopicPower1status, "0");
buttonpower1 = 0;
EEPROM.write(1, buttonpower1);
EEPROM.commit();
digitalWrite(power1, HIGH);
}else {
client.publish(mqttTopicButtonStatusPower1, "on");
client.publish(mqttTopicPower1status, "1");
buttonpower1 = 1;
EEPROM.write(1, buttonpower1);
EEPROM.commit();
digitalWrite(power1, LOW);
};
delay(500);
 };
 };  
 if(topic==mqttTopicButtonPower1auto){
     if(messageTemp == "do"){       
if (buttonpower1auto == 1)
{
client.publish(mqttTopicButtonStatusPower1auto, "off");

buttonpower1auto = 0;
EEPROM.write(2, buttonpower1auto);
EEPROM.commit();

}else {
client.publish(mqttTopicButtonStatusPower1auto, "on");

buttonpower1auto = 1;
EEPROM.write(2, buttonpower1auto);
EEPROM.commit();
};
delay(500);
 };
 };

 if(topic==mqttTopicButtonPower1case){
     if(messageTemp == "do"){       
if (buttonpower1case == 1)
{
client.publish(mqttTopicButtonStatusPower1case, "less");
buttonpower1case = 0;
EEPROM.write(3, buttonpower1case);
EEPROM.commit();

}else {
client.publish(mqttTopicButtonStatusPower1case, "more");
buttonpower1case = 1;
EEPROM.write(3, buttonpower1case);
EEPROM.commit();
};
delay(500);
 };
 };
 if(topic==mqttTopicButtonPower1temp){
buttonpower1temp = messageTemp.toInt();
static char TempTemp[7];
    dtostrf(buttonpower1temp, 6, 0, TempTemp);
client.publish(mqttTopicButtonStatusPower1temp, TempTemp);
EEPROM.write(4, buttonpower1temp);
EEPROM.commit();
delay(500);
 };
 if(topic==mqttTopicButtonPower1time){
buttonpower1time = messageTemp.toInt();
static char TimeTemp[7];
    dtostrf(buttonpower1time, 6, 0, TimeTemp);
client.publish(mqttTopicButtonStatusPower1time, TimeTemp);
//EEPROM.write(5, buttonpower1time);
EEPROMWritelong(5, buttonpower1time);
reruntime = 60000 * buttonpower1time;
delay(500);
 };


// power 1 settings end

  if(topic==mqttTopicResendTime){
resendtimetemp = messageTemp.toInt();
static char TimeResend[7];
    dtostrf(resendtimetemp, 6, 0, TimeResend);
client.publish(mqttTopicResendTimeStatus, TimeResend);
EEPROMWritelong(17, resendtimetemp);
resendtime = 1000 * resendtimetemp; 
delay(500);
 };
 
// power 2 settings start 
  if(topic==mqttTopicButtonPower2){
     if(messageTemp == "do"){       
if (buttonpower2 == 1)
{
client.publish(mqttTopicButtonStatusPower2, "off");
client.publish(mqttTopicPower2status, "0");
buttonpower2 = 0;
EEPROM.write(9, buttonpower2);
EEPROM.commit();
digitalWrite(power2, HIGH);
}else {
client.publish(mqttTopicButtonStatusPower2, "on");
client.publish(mqttTopicPower2status, "1");
buttonpower2 = 1;
EEPROM.write(9, buttonpower2);
EEPROM.commit();
digitalWrite(power2, LOW);
};
delay(500);
 };
 };  
 if(topic==mqttTopicButtonPower2auto){
     if(messageTemp == "do"){       
if (buttonpower2auto == 1)
{
client.publish(mqttTopicButtonStatusPower2auto, "off");

buttonpower2auto = 0;
EEPROM.write(10, buttonpower2auto);
EEPROM.commit();

}else {
client.publish(mqttTopicButtonStatusPower2auto, "on");

buttonpower2auto = 1;
EEPROM.write(10, buttonpower2auto);
EEPROM.commit();
};
delay(500);
 };
 };

 if(topic==mqttTopicButtonPower2case){
     if(messageTemp == "do"){       
if (buttonpower2case == 1)
{
client.publish(mqttTopicButtonStatusPower2case, "less");
buttonpower2case = 0;
EEPROM.write(11, buttonpower2case);
EEPROM.commit();

}else {
client.publish(mqttTopicButtonStatusPower2case, "more");
buttonpower2case = 1;
EEPROM.write(11, buttonpower2case);
EEPROM.commit();
};
delay(500);
 };
 };
 if(topic==mqttTopicButtonPower2temp){
buttonpower2temp = messageTemp.toInt();
static char TempTemp[7];
    dtostrf(buttonpower2temp, 6, 0, TempTemp);
client.publish(mqttTopicButtonStatusPower2temp, TempTemp);
EEPROM.write(12, buttonpower2temp);
EEPROM.commit();
delay(500);
 };
 if(topic==mqttTopicButtonPower2time){
buttonpower2time = messageTemp.toInt();
static char TimeTemp[7];
    dtostrf(buttonpower2time, 6, 0, TimeTemp);
client.publish(mqttTopicButtonStatusPower2time, TimeTemp);
//EEPROM.write(5, buttonpower1time);
EEPROMWritelong(13, buttonpower2time);
reruntime2 = 60000 * buttonpower2time;
delay(500);
 };
// power 1 settings end
      
}

// This functions reconnects your ESP8266 to your MQTT broker
// Change the function below if you want to subscribe to more topics with your ESP8266 
void reconnect() {

    if (client.connect(WiFi.hostname().c_str(), mqttUser, mqttPassword)) {
      // Subscribe or resubscribe to a topic
      // You can subscribe to more topics (to control more LEDs in this example)
   
   // power 1 settings start
   client.subscribe(mqttTopicButtonPower1);
   client.subscribe(mqttTopicButtonPower1auto);
   client.subscribe(mqttTopicButtonPower1case);
   client.subscribe(mqttTopicButtonPower1temp);
   client.subscribe(mqttTopicButtonPower1time);
   // power 1 settings end

   // power 2 settings start
   client.subscribe(mqttTopicButtonPower2);
   client.subscribe(mqttTopicButtonPower2auto);
   client.subscribe(mqttTopicButtonPower2case);
   client.subscribe(mqttTopicButtonPower2temp);
   client.subscribe(mqttTopicButtonPower2time);
   // power 2 settings end
   client.subscribe(mqttTopicResendTime);
    } else {
      // Wait 5 seconds before retrying
      delay(500);
    }

}


void loop() {

  now = millis();

  //dont know what this string does, but without it all does not work
 if(!client.loop()) 
     client.connect("blabla");

  if (!client.connected()) {
   digitalWrite(LED_BUILTIN, LOW); 
    reconnect(); 
   digitalWrite(LED_BUILTIN, HIGH);   
     };


if (now - lastMeasure21 > reruntime) {
    lastMeasure21 = now;  
if (buttonpower1auto == 1) 
{ client.publish(mqttTopicPower1status, "0");
  client.publish(mqttTopicButtonStatusPower1, "off");
  digitalWrite(power1, HIGH);
  buttonpower1 = 0;
};

}; 

 if (now - lastMeasure22 > reruntime2) {
    lastMeasure22 = now;  
if (buttonpower2auto == 1) 
{ client.publish(mqttTopicPower2status, "0");
  client.publish(mqttTopicButtonStatusPower2, "off");
  digitalWrite(power2, HIGH);
  buttonpower2 = 0;
};

};        
    
if (now - lastMeasure > resendtime) {
    lastMeasure = now;  

    float hf = dht.readHumidity();
    static char humidityTemp[7];
    dtostrf(hf, 6, 1, humidityTemp);
    int8_t h = (int) hf;
    float tf = dht.readTemperature();
    static char temperatureTemp[7];
    dtostrf(tf, 6, 1, temperatureTemp);
    int8_t t = (int) tf;
    
    
// power 1 settings start
if (buttonpower1auto == 1) 
{ 

  
if (buttonpower1case == 1 )
{
if ( t >= buttonpower1temp)
{ 

 Nt = Nt + 1;
 lastMeasure21 = now; 
 if (Nt == 2 )
{ 
  client.publish(mqttTopicPower1status, "1");
  client.publish(mqttTopicButtonStatusPower1, "on");
  digitalWrite(power1, LOW);
  buttonpower1 = 1;
 
  Nt = 0;
};

  
} else {
Nt = 0;  
};




};
if (buttonpower1case == 0 ) {
  if ( t <= buttonpower1temp)
{ 

  Nt = Nt + 1;
 lastMeasure21 = now;
 if (Nt == 2 )
{ 
  client.publish(mqttTopicPower1status, "1");
  client.publish(mqttTopicButtonStatusPower1, "on");
 digitalWrite(power1, LOW);
 buttonpower1 = 1;
  
  Nt = 0;
};

  
} else {
Nt = 0;  
};

};
};
// power 1  settings end


// power 2 settings start
if (buttonpower2auto == 1) 
{
if (buttonpower2case == 1 )
{
if ( h >= buttonpower2temp)
{ 
  
   Nh = Nh + 1;
 lastMeasure22 = now; 
 if (Nh == 2 )
{ 
  client.publish(mqttTopicPower2status, "1");
  client.publish(mqttTopicButtonStatusPower2, "on");
  digitalWrite(power2, LOW);
  buttonpower2 = 1;
 
  Nh = 0; 
 }; 
} else {
Nh = 0;  
};

};
if (buttonpower2case == 0 ) {
  if ( h <= buttonpower2temp)
{ 

  Nh = Nh + 1;
  lastMeasure22 = now;
 if (Nh == 2 )
{ 
  client.publish(mqttTopicPower2status, "1");
  client.publish(mqttTopicButtonStatusPower2, "on");
 digitalWrite(power2, LOW);
 buttonpower2 = 1;
 
 Nh = 0; 
 }; 
} else {
Nh = 0;  
};
};
};
// power 2 settings end

if (client.connected()) {


    // Publishes 
digitalWrite(LED_BUILTIN, LOW);   digitalWrite(LED_BUILTIN, LOW);

    
    client.publish(mqttTopicTemperature, temperatureTemp);
    client.publish(mqttTopicHumidity, humidityTemp);

    static char TimeResend[7];
    dtostrf(resendtimetemp, 6, 0, TimeResend);
client.publish(mqttTopicResendTimeStatus, TimeResend);

    // power 1 settings start
    static char TempTemp[7];
    dtostrf(buttonpower1temp, 6, 0, TempTemp);
client.publish(mqttTopicButtonStatusPower1temp, TempTemp);
static char TimeTemp[7];
    dtostrf(buttonpower1time, 6, 0, TimeTemp);
client.publish(mqttTopicButtonStatusPower1time, TimeTemp);
  if (digitalRead(power1) == LOW)
 {
  if (buttonpower1 == 1)
{
  client.publish(mqttTopicPower1status, "1");
  client.publish(mqttTopicButtonStatusPower1, "on");
} else {
  client.publish(mqttTopicPower1status, "0");
  client.publish(mqttTopicButtonStatusPower1, "off");
  digitalWrite(power1, HIGH);
  buttonpower1 = 0;
};
 } else {
  if (buttonpower1 == 0)
{
  client.publish(mqttTopicPower1status, "0");
  client.publish(mqttTopicButtonStatusPower1, "off");
} else {
  client.publish(mqttTopicPower1status, "1");
  client.publish(mqttTopicButtonStatusPower1, "on");
  digitalWrite(power1, LOW);
  buttonpower1 = 1;
};

 };
 if (buttonpower1auto == 1)
{
  client.publish(mqttTopicButtonStatusPower1auto, "on");
} else {
  client.publish(mqttTopicButtonStatusPower1auto, "off");

}; 
 if (buttonpower1case == 1)
{
  client.publish(mqttTopicButtonStatusPower1case, "more");
} else {
  client.publish(mqttTopicButtonStatusPower1case, "less");

}; 
// power 1 settings end


 // power 2 settings start
    static char TempTemp2[7];
    dtostrf(buttonpower2temp, 6, 0, TempTemp2);
    client.publish(mqttTopicButtonStatusPower2temp, TempTemp2);
    static char TimeTemp2[7];
    dtostrf(buttonpower2time, 6, 0, TimeTemp2);
    client.publish(mqttTopicButtonStatusPower2time, TimeTemp2);
    
  if (digitalRead(power2) == LOW)
 {
  if (buttonpower2 == 1)
{
  client.publish(mqttTopicPower2status, "1");
  client.publish(mqttTopicButtonStatusPower2, "on");
} else {
  client.publish(mqttTopicPower2status, "0");
  client.publish(mqttTopicButtonStatusPower2, "off");
  digitalWrite(power2, HIGH);
  buttonpower2 = 0;
};
 } else {
  if (buttonpower2 == 0)
{
  client.publish(mqttTopicPower2status, "0");
  client.publish(mqttTopicButtonStatusPower2, "off");
} else {
  client.publish(mqttTopicPower2status, "1");
  client.publish(mqttTopicButtonStatusPower2, "on");
  digitalWrite(power2, LOW);
  buttonpower2 = 1;
};

 };
 if (buttonpower2auto == 1)
{
  client.publish(mqttTopicButtonStatusPower2auto, "on");
} else {
  client.publish(mqttTopicButtonStatusPower2auto, "off");

}; 
 if (buttonpower2case == 1)
{
  client.publish(mqttTopicButtonStatusPower2case, "more");
} else {
  client.publish(mqttTopicButtonStatusPower2case, "less");

}; 
// power 2 settings end

 if (!wifistatus)
 {
client.publish(mqttTopicWifi, "0");
wifistatus = true;
  
 } else {
 client.publish(mqttTopicWifi, "1"); 
 };
if (!powerstatus)
        {
            client.publish(mqttTopicPower, "0");
            powerstatus = true;
        } else {
            client.publish(mqttTopicPower, "1"); 
     };

  digitalWrite(LED_BUILTIN, HIGH);
  };
 
};

}



IMPORTANT: on the first start after submit scketch to esp8266, it is necessary to set the update interval in the Storage Room Send/Check interval Settings box in the Node-Red user interface, otherwise there may be garbage, it read from an empty place in memory, but it may not be empty. The same is true for other configurations, but not as critical

When sending data, it does the same as the weather module, only there is no airsensor. There is also an interval setting in the Settings tab in the Node-Network UI, but settings to turn on the plugs in the given condition also appear, they work even if there is no connection to Node-Red.

Here are the bricks responsible for the smart plug in Node-Red

And text that you can import yourself

[{"id":"5fb16ee4.f988e","type":"ui_chart","z":"e60c0f81.64c18","name":"Temperature","group":"91158576.4f6178","order":2,"width":0,"height":0,"label":"Temperature graph","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#8e0911","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#910304","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":610,"y":1040,"wires":[[],[]]},{"id":"f8830669.9e10c8","type":"mqtt in","z":"e60c0f81.64c18","name":"Temperature","topic":"room1/temperature","qos":"2","broker":"572eed08.5bb714","x":410,"y":920,"wires":[["5fb16ee4.f988e","b77ce775.ac0f98","8a1fb374.d6b14","692ab0d4.84698"]]},{"id":"7c990247.71a3cc","type":"file","z":"e60c0f81.64c18","name":"Write temp_room1.log","filename":"/root/iot_data/temp_room1.log","appendNewline":true,"createDir":false,"overwriteFile":"false","x":840,"y":920,"wires":[[]]},{"id":"b77ce775.ac0f98","type":"function","z":"e60c0f81.64c18","name":"Add time to data","func":"var timenow=flow.get('time');\nmsg.payload = timenow + ' '+ msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":920,"wires":[["7c990247.71a3cc"]]},{"id":"4293b7d1.57e368","type":"ui_chart","z":"e60c0f81.64c18","name":"Humidity","group":"91158576.4f6178","order":4,"width":0,"height":0,"label":"Humidity graph","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#0971c1","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":600,"y":1220,"wires":[[],[]]},{"id":"c5e2d074.7634","type":"mqtt in","z":"e60c0f81.64c18","name":"Humidity","topic":"room1/humidity","qos":"2","broker":"572eed08.5bb714","x":400,"y":1100,"wires":[["4293b7d1.57e368","6d8e3a37.c02eb4","7d33c3bc.f07a7c","c49d559f.8ef4c8"]]},{"id":"6d7903e5.1fdeac","type":"file","z":"e60c0f81.64c18","name":"Write humi_room1.log","filename":"/root/iot_data/humi_room1.log","appendNewline":true,"createDir":false,"overwriteFile":"false","x":840,"y":1100,"wires":[[]]},{"id":"6d8e3a37.c02eb4","type":"function","z":"e60c0f81.64c18","name":"Add time to data","func":"var timenow=flow.get('time');\nmsg.payload = timenow + ' '+ msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":1100,"wires":[["6d7903e5.1fdeac"]]},{"id":"75b1ee83.fb8dc","type":"ui_chart","z":"e60c0f81.64c18","name":"Power 1","group":"fba9a7a9.8c5418","order":3,"width":0,"height":0,"label":"Power 1 use","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"1","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#680808","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":680,"y":140,"wires":[[],[]]},{"id":"6bb7ff0c.048ea","type":"mqtt in","z":"e60c0f81.64c18","name":"","topic":"power/unit1status","qos":"2","broker":"572eed08.5bb714","x":420,"y":140,"wires":[["75b1ee83.fb8dc"]]},{"id":"f7a70f9f.25cec","type":"mqtt in","z":"e60c0f81.64c18","name":"MQQT status","topic":"room1/wifistatus","qos":"2","broker":"572eed08.5bb714","x":410,"y":800,"wires":[["e586b3bf.742ce"]]},{"id":"e586b3bf.742ce","type":"ui_chart","z":"e60c0f81.64c18","name":"MQQT status","group":"c8aa5b51.ed6ff8","order":1,"width":0,"height":0,"label":"MQQT was lost at","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"1","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"colors":["#000000","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#77090a","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":570,"y":800,"wires":[[],[]]},{"id":"83fc107.a5b6ef","type":"ui_button","z":"e60c0f81.64c18","name":"","group":"fba9a7a9.8c5418","order":2,"width":0,"height":0,"passthru":false,"label":"press to change","color":"","bgcolor":"","icon":"","payload":"do","payloadType":"str","topic":"power/buttonunit1","x":420,"y":20,"wires":[["1d72bb8f.7aa464"]]},{"id":"1d72bb8f.7aa464","type":"mqtt out","z":"e60c0f81.64c18","name":"","topic":"power/buttonunit1","qos":"","retain":"","broker":"572eed08.5bb714","x":650,"y":20,"wires":[]},{"id":"c1ce83be.d59b6","type":"mqtt in","z":"e60c0f81.64c18","name":"Power1 Button status","topic":"power/buttonstatusunit1","qos":"2","broker":"572eed08.5bb714","x":440,"y":80,"wires":[["44e98139.d58"]]},{"id":"44e98139.d58","type":"ui_text","z":"e60c0f81.64c18","group":"fba9a7a9.8c5418","order":1,"width":0,"height":0,"name":"","label":"Power 1 (override by auto control):","format":"{{msg.payload}}","layout":"row-spread","x":720,"y":80,"wires":[]},{"id":"e8a32ad3.656188","type":"ui_button","z":"e60c0f81.64c18","name":"","group":"fba9a7a9.8c5418","order":5,"width":0,"height":0,"passthru":false,"label":"press to change","color":"","bgcolor":"","icon":"","payload":"do","payloadType":"str","topic":"power/buttonunit1auto","x":420,"y":200,"wires":[["a947e584.e98788"]]},{"id":"a947e584.e98788","type":"mqtt out","z":"e60c0f81.64c18","name":"","topic":"power/buttonunit1auto","qos":"","retain":"","broker":"572eed08.5bb714","x":660,"y":200,"wires":[]},{"id":"d30d9525.ffe7b8","type":"mqtt in","z":"e60c0f81.64c18","name":"power1 Auto  Button status","topic":"power/buttonstatusunit1auto","qos":"2","broker":"572eed08.5bb714","x":450,"y":260,"wires":[["6c440e2c.b0432"]]},{"id":"6c440e2c.b0432","type":"ui_text","z":"e60c0f81.64c18","group":"fba9a7a9.8c5418","order":4,"width":0,"height":0,"name":"","label":"Power 1 Temprutare Auto Control:","format":"{{msg.payload}}","layout":"row-spread","x":720,"y":260,"wires":[]},{"id":"7dad518e.e0f73","type":"ui_button","z":"e60c0f81.64c18","name":"","group":"fba9a7a9.8c5418","order":7,"width":0,"height":0,"passthru":false,"label":"press to change","color":"","bgcolor":"","icon":"","payload":"do","payloadType":"str","topic":"power/buttonunit1case","x":420,"y":320,"wires":[["f83f2f6b.a2178"]]},{"id":"f83f2f6b.a2178","type":"mqtt out","z":"e60c0f81.64c18","name":"","topic":"power/buttonunit1case","qos":"","retain":"","broker":"572eed08.5bb714","x":660,"y":320,"wires":[]},{"id":"aefd6457.2fb318","type":"mqtt in","z":"e60c0f81.64c18","name":"power1 Auto  Button Case","topic":"power/buttonstatusunit1case","qos":"2","broker":"572eed08.5bb714","x":450,"y":380,"wires":[["5f62a213.e2221c"]]},{"id":"5f62a213.e2221c","type":"ui_text","z":"e60c0f81.64c18","group":"fba9a7a9.8c5418","order":6,"width":0,"height":0,"name":"","label":"When the temperature is...:","format":"{{msg.payload}}","layout":"col-center","x":740,"y":380,"wires":[]},{"id":"2023e629.f7fcda","type":"ui_slider","z":"e60c0f81.64c18","name":"","label":"slider","group":"fba9a7a9.8c5418","order":9,"width":0,"height":0,"passthru":true,"outs":"end","topic":"power/buttonunit1temp","min":"-35","max":"65","step":1,"x":390,"y":440,"wires":[["81263bde.91ff88"]]},{"id":"81263bde.91ff88","type":"mqtt out","z":"e60c0f81.64c18","name":"","topic":"power/buttonunit1temp","qos":"","retain":"","broker":"572eed08.5bb714","x":600,"y":440,"wires":[]},{"id":"ea28795a.ea98c8","type":"mqtt in","z":"e60c0f81.64c18","name":"power1 Auto  Button Temp","topic":"power/buttonstatusunit1temp","qos":"2","broker":"572eed08.5bb714","x":450,"y":500,"wires":[["cda707f3.409308"]]},{"id":"cda707f3.409308","type":"ui_text","z":"e60c0f81.64c18","group":"fba9a7a9.8c5418","order":8,"width":0,"height":0,"name":"","label":"than...:","format":"{{msg.payload}}","layout":"col-center","x":670,"y":500,"wires":[]},{"id":"518c1721.0ef2f8","type":"ui_slider","z":"e60c0f81.64c18","name":"","label":"slider","group":"fba9a7a9.8c5418","order":12,"width":0,"height":0,"passthru":true,"outs":"end","topic":"power/buttonunit1time","min":"1","max":"1000","step":"5","x":390,"y":560,"wires":[["769e0778.e2f7a8"]]},{"id":"769e0778.e2f7a8","type":"mqtt out","z":"e60c0f81.64c18","name":"","topic":"power/buttonunit1time","qos":"","retain":"","broker":"572eed08.5bb714","x":600,"y":560,"wires":[]},{"id":"8e77c553.3d1568","type":"mqtt in","z":"e60c0f81.64c18","name":"power1 Auto  Button Time","topic":"power/buttonstatusunit1time","qos":"2","broker":"572eed08.5bb714","x":450,"y":620,"wires":[["b368c669.6da6d8"]]},{"id":"b368c669.6da6d8","type":"ui_text","z":"e60c0f81.64c18","group":"fba9a7a9.8c5418","order":11,"width":0,"height":0,"name":"","label":"turn on power for (min)...:","format":"{{msg.payload}}","layout":"col-center","x":730,"y":620,"wires":[]},{"id":"81acd203.1a222","type":"mqtt in","z":"e60c0f81.64c18","name":"Power status","topic":"room1/powerstatus","qos":"2","broker":"572eed08.5bb714","x":410,"y":860,"wires":[["ab1a1085.b7e91"]]},{"id":"ab1a1085.b7e91","type":"ui_chart","z":"e60c0f81.64c18","name":"Power status","group":"c8aa5b51.ed6ff8","order":2,"width":0,"height":0,"label":"Power was lost at","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"1","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"colors":["#000000","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#77090a","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":570,"y":860,"wires":[[],[]]},{"id":"311965fc.bcde5a","type":"ui_chart","z":"e60c0f81.64c18","name":"Power 2","group":"5d3c2f30.e95b4","order":3,"width":0,"height":0,"label":"Power 2 use","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"1","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#680808","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":1260,"y":140,"wires":[[],[]]},{"id":"b9e207d5.faf328","type":"mqtt in","z":"e60c0f81.64c18","name":"","topic":"power/unit2status","qos":"2","broker":"572eed08.5bb714","x":1000,"y":140,"wires":[["311965fc.bcde5a"]]},{"id":"c0f3e890.50a9e8","type":"ui_button","z":"e60c0f81.64c18","name":"","group":"5d3c2f30.e95b4","order":2,"width":0,"height":0,"passthru":false,"label":"press to change","color":"","bgcolor":"","icon":"","payload":"do","payloadType":"str","topic":"power/buttonunit2","x":1000,"y":20,"wires":[["9947f5c1.130478"]]},{"id":"9947f5c1.130478","type":"mqtt out","z":"e60c0f81.64c18","name":"","topic":"power/buttonunit2","qos":"","retain":"","broker":"572eed08.5bb714","x":1230,"y":20,"wires":[]},{"id":"25644cfa.7b9654","type":"mqtt in","z":"e60c0f81.64c18","name":"Power2 Button status","topic":"power/buttonstatusunit2","qos":"2","broker":"572eed08.5bb714","x":1020,"y":80,"wires":[["63e87dc0.334cb4"]]},{"id":"63e87dc0.334cb4","type":"ui_text","z":"e60c0f81.64c18","group":"5d3c2f30.e95b4","order":1,"width":0,"height":0,"name":"","label":"Power 2 (override by auto control):","format":"{{msg.payload}}","layout":"row-spread","x":1300,"y":80,"wires":[]},{"id":"6c3e3c55.f81e54","type":"ui_button","z":"e60c0f81.64c18","name":"","group":"5d3c2f30.e95b4","order":5,"width":0,"height":0,"passthru":false,"label":"press to change","color":"","bgcolor":"","icon":"","payload":"do","payloadType":"str","topic":"power/buttonunit2auto","x":1000,"y":200,"wires":[["f5da73f4.22916"]]},{"id":"f5da73f4.22916","type":"mqtt out","z":"e60c0f81.64c18","name":"","topic":"power/buttonunit2auto","qos":"","retain":"","broker":"572eed08.5bb714","x":1240,"y":200,"wires":[]},{"id":"1700d32.26aca2d","type":"mqtt in","z":"e60c0f81.64c18","name":"power2 Auto  Button status","topic":"power/buttonstatusunit2auto","qos":"2","broker":"572eed08.5bb714","x":1030,"y":260,"wires":[["baba5a9c.6601b8"]]},{"id":"baba5a9c.6601b8","type":"ui_text","z":"e60c0f81.64c18","group":"5d3c2f30.e95b4","order":4,"width":0,"height":0,"name":"","label":"Power 2 Humidity Auto Control:","format":"{{msg.payload}}","layout":"row-spread","x":1290,"y":260,"wires":[]},{"id":"dc8fc8ce.aef588","type":"ui_button","z":"e60c0f81.64c18","name":"","group":"5d3c2f30.e95b4","order":7,"width":0,"height":0,"passthru":false,"label":"press to change","color":"","bgcolor":"","icon":"","payload":"do","payloadType":"str","topic":"power/buttonunit2case","x":1000,"y":320,"wires":[["ec4c9b15.062838"]]},{"id":"ec4c9b15.062838","type":"mqtt out","z":"e60c0f81.64c18","name":"","topic":"power/buttonunit2case","qos":"","retain":"","broker":"572eed08.5bb714","x":1240,"y":320,"wires":[]},{"id":"39c84012.dc4ee","type":"mqtt in","z":"e60c0f81.64c18","name":"power2 Auto  Button Case","topic":"power/buttonstatusunit2case","qos":"2","broker":"572eed08.5bb714","x":1030,"y":380,"wires":[["94a9fa82.c5ec98"]]},{"id":"94a9fa82.c5ec98","type":"ui_text","z":"e60c0f81.64c18","group":"5d3c2f30.e95b4","order":6,"width":0,"height":0,"name":"","label":"When the humidity is...:","format":"{{msg.payload}}","layout":"col-center","x":1310,"y":380,"wires":[]},{"id":"d8b512eb.d148c","type":"ui_slider","z":"e60c0f81.64c18","name":"","label":"slider","group":"5d3c2f30.e95b4","order":9,"width":0,"height":0,"passthru":true,"outs":"end","topic":"power/buttonunit2temp","min":"0","max":"100","step":1,"x":970,"y":440,"wires":[["ae0c8dc4.727a9"]]},{"id":"ae0c8dc4.727a9","type":"mqtt out","z":"e60c0f81.64c18","name":"","topic":"power/buttonunit2temp","qos":"","retain":"","broker":"572eed08.5bb714","x":1180,"y":440,"wires":[]},{"id":"20495eae.c1ac82","type":"mqtt in","z":"e60c0f81.64c18","name":"power2 Auto  Button Hum","topic":"power/buttonstatusunit2temp","qos":"2","broker":"572eed08.5bb714","x":1030,"y":500,"wires":[["96679630.ad9d48"]]},{"id":"96679630.ad9d48","type":"ui_text","z":"e60c0f81.64c18","group":"5d3c2f30.e95b4","order":8,"width":0,"height":0,"name":"","label":"than...:","format":"{{msg.payload}}","layout":"col-center","x":1250,"y":500,"wires":[]},{"id":"af1a3232.ba29","type":"ui_slider","z":"e60c0f81.64c18","name":"","label":"slider","group":"5d3c2f30.e95b4","order":12,"width":0,"height":0,"passthru":true,"outs":"end","topic":"power/buttonunit2time","min":"1","max":"1000","step":"5","x":970,"y":560,"wires":[["401038f3.9af088"]]},{"id":"401038f3.9af088","type":"mqtt out","z":"e60c0f81.64c18","name":"","topic":"power/buttonunit2time","qos":"","retain":"","broker":"572eed08.5bb714","x":1180,"y":560,"wires":[]},{"id":"87874ed1.92dfb","type":"mqtt in","z":"e60c0f81.64c18","name":"power1 Auto  Button Time","topic":"power/buttonstatusunit2time","qos":"2","broker":"572eed08.5bb714","x":1030,"y":620,"wires":[["ba6bd99.57a9e28"]]},{"id":"ba6bd99.57a9e28","type":"ui_text","z":"e60c0f81.64c18","group":"5d3c2f30.e95b4","order":11,"width":0,"height":0,"name":"","label":"turn on power for (min)...:","format":"{{msg.payload}}","layout":"col-center","x":1310,"y":620,"wires":[]},{"id":"4bea9f97.478f6","type":"ui_slider","z":"e60c0f81.64c18","name":"","label":"slider","group":"5b5e436d.06525c","order":2,"width":0,"height":0,"passthru":true,"outs":"end","topic":"room1/resendtime","min":"15","max":"600","step":"5","x":390,"y":680,"wires":[["c9cf61b2.27fc8"]]},{"id":"c9cf61b2.27fc8","type":"mqtt out","z":"e60c0f81.64c18","name":"","topic":"room1/resendtime","qos":"","retain":"","broker":"572eed08.5bb714","x":590,"y":680,"wires":[]},{"id":"98b50a35.88b558","type":"mqtt in","z":"e60c0f81.64c18","name":"resend time","topic":"room1/resendtimestatus","qos":"2","broker":"572eed08.5bb714","x":410,"y":740,"wires":[["e763f56c.4c08e8"]]},{"id":"e763f56c.4c08e8","type":"ui_text","z":"e60c0f81.64c18","group":"5b5e436d.06525c","order":1,"width":0,"height":0,"name":"","label":"Storage Room sensors - send and check  data  every (seconds):","format":"{{msg.payload}}","layout":"col-center","x":770,"y":740,"wires":[]},{"id":"8a1fb374.d6b14","type":"ui_text","z":"e60c0f81.64c18","group":"91158576.4f6178","order":1,"width":0,"height":0,"name":"","label":"Temperature now is","format":"{{msg.payload}}","layout":"row-center","x":630,"y":1000,"wires":[]},{"id":"7d33c3bc.f07a7c","type":"ui_text","z":"e60c0f81.64c18","group":"91158576.4f6178","order":3,"width":0,"height":0,"name":"","label":"Humidity now is","format":"{{msg.payload}}","layout":"row-center","x":620,"y":1140,"wires":[]},{"id":"692ab0d4.84698","type":"ui_text","z":"e60c0f81.64c18","group":"fba9a7a9.8c5418","order":10,"width":0,"height":0,"name":"","label":"(Temperature now is","format":"{{msg.payload}})","layout":"row-left","x":640,"y":960,"wires":[]},{"id":"c49d559f.8ef4c8","type":"ui_text","z":"e60c0f81.64c18","group":"5d3c2f30.e95b4","order":10,"width":0,"height":0,"name":"","label":"(Humidity now is","format":"{{msg.payload}})","layout":"row-left","x":620,"y":1180,"wires":[]},{"id":"91158576.4f6178","type":"ui_group","z":"","name":"Storage Room Data","tab":"274c10df.50bbd","order":1,"disp":true,"width":"10","collapse":false},{"id":"572eed08.5bb714","type":"mqtt-broker","z":"","name":"Mosquitto Orange","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"fba9a7a9.8c5418","type":"ui_group","z":"","name":"Storage Room Power 1 Settings","tab":"5d7f916a.3be03","order":3,"disp":true,"width":"6","collapse":false},{"id":"c8aa5b51.ed6ff8","type":"ui_group","z":"","name":"Storage Room Status","tab":"274c10df.50bbd","order":2,"disp":true,"width":"10","collapse":false},{"id":"5d3c2f30.e95b4","type":"ui_group","z":"","name":"Storage Room Power 2 Settings","tab":"5d7f916a.3be03","order":3,"disp":true,"width":"6","collapse":false},{"id":"5b5e436d.06525c","type":"ui_group","z":"","name":"Storage Room Send/Check interval Settings","tab":"5d7f916a.3be03","order":4,"disp":true,"width":"6","collapse":false},{"id":"274c10df.50bbd","type":"ui_tab","z":"","name":"Storage Room","icon":"dashboard","order":1},{"id":"5d7f916a.3be03","type":"ui_tab","z":"","name":"Settings","icon":"dashboard","order":4}]

138/5000
I won’t even show a screenshot with the data, it’s nothing interesting. Here is a screenshot with the settings.

Settings for each outlet goes in columns. The first reacts to temperature, the second to humidity. You can turn the plug on or off immediately in the configuration; This will change if automation is activated. You can see the graph of the operation of the plug for 24 hours, 1 means it is on, the values are displayed instantly. There are settings to enable automation, select if it is more or less than the set value (immediately show what value it is now) and then turn on the outlet (otherwise, turn it off), during a given interval.I verified that it works, but, of course, mistakes can remain. It turned out many features, for example, you can not write Boolean values in memory, changed them to 0 and 1, but it is the same. To estimate the temperature, I translated the decimal digits of the sensors to integers, since (as many people notice) the comparison of the decimal digits can give an unexpected result. Many, many hours of entertainment all this brought me ehhh.

CAUTION: There was an incomprehensible error, the automation worked alone, or something else. Therefore, now, for automation to activate, expect two events to happen.

Simply collect the temperature of all computer processors
Well, not all… from Windows, probably, you can also, somehow, probably … Windows is not suitable for IoT, even through Bash for Windows.

I have some computers that really work 24 hours, there are others that turn on for a couple of hours. We put the MQQT client in them and send the CPU temperature data.

But starting with Node-Red, here are the bricks that are responsible for this.

The same but in text to import

[{"id":"b05b819f.c4ea5","type":"mqtt in","z":"e60c0f81.64c18","name":"Cpu Temp","topic":"pccpu/retropi","qos":"2","broker":"572eed08.5bb714","x":380,"y":2160,"wires":[["34365a5f.ca6216","d07f2055.bc239"]]},{"id":"34365a5f.ca6216","type":"ui_chart","z":"e60c0f81.64c18","name":"RetroPi Cpu Temp","group":"51bdd67d.76b488","order":2,"width":"0","height":"0","label":"","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"0","dot":false,"ymin":"","ymax":"","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#7c0202","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":550,"y":2160,"wires":[[],[]]},{"id":"d07f2055.bc239","type":"ui_text","z":"e60c0f81.64c18","group":"51bdd67d.76b488","order":1,"width":0,"height":0,"name":"","label":"CPU (Broadcom BCM2836) Temperature","format":"{{msg.payload}}","layout":"col-center","x":650,"y":2120,"wires":[]},{"id":"fdbdadbe.75049","type":"mqtt in","z":"e60c0f81.64c18","name":"Cpu Temp","topic":"pccpu/orangepiplus","qos":"2","broker":"572eed08.5bb714","x":380,"y":2240,"wires":[["f8715fd8.f4c4e","7ac58efe.9836f"]]},{"id":"f8715fd8.f4c4e","type":"ui_chart","z":"e60c0f81.64c18","name":"Orange Pi Pc plus Cpu Temp","group":"c2baeca.d963e1","order":2,"width":0,"height":0,"label":"","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"0","dot":false,"ymin":"","ymax":"","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#7c0202","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":580,"y":2240,"wires":[[],[]]},{"id":"7ac58efe.9836f","type":"ui_text","z":"e60c0f81.64c18","group":"c2baeca.d963e1","order":1,"width":0,"height":0,"name":"","label":"CPU (H3 Quad-core) Temperature","format":"{{msg.payload}}","layout":"col-center","x":630,"y":2200,"wires":[]},{"id":"6eee9129.5375a","type":"mqtt in","z":"e60c0f81.64c18","name":"Cpu Temp1","topic":"pccpu/inteli5c1","qos":"2","broker":"572eed08.5bb714","x":390,"y":2320,"wires":[["2facad3f.7a4302","ee017615.d82cb8"]]},{"id":"2facad3f.7a4302","type":"ui_chart","z":"e60c0f81.64c18","name":"Intel Core Cpu Temp","group":"8007d5e0.fc68a8","order":5,"width":0,"height":0,"label":"Intel Core i5-3470 CPU Temperature","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"0","dot":false,"ymin":"","ymax":"","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#7c0202","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":660,"y":2480,"wires":[[],[]]},{"id":"984b8237.787a6","type":"mqtt in","z":"e60c0f81.64c18","name":"Cpu Temp2","topic":"pccpu/inteli5c2","qos":"2","broker":"572eed08.5bb714","x":390,"y":2380,"wires":[["2facad3f.7a4302","b1d1dca0.453be"]]},{"id":"466f0788.50fb68","type":"mqtt in","z":"e60c0f81.64c18","name":"Cpu Temp3","topic":"pccpu/inteli5c3","qos":"2","broker":"572eed08.5bb714","x":390,"y":2440,"wires":[["2facad3f.7a4302","dd72b678.7599e8"]]},{"id":"75af7157.a1885","type":"mqtt in","z":"e60c0f81.64c18","name":"Cpu Temp4","topic":"pccpu/inteli5c4","qos":"2","broker":"572eed08.5bb714","x":390,"y":2500,"wires":[["2facad3f.7a4302","39fcaaab.85efa6"]]},{"id":"ee017615.d82cb8","type":"ui_text","z":"e60c0f81.64c18","group":"8007d5e0.fc68a8","order":1,"width":0,"height":0,"name":"","label":"Core 1 Temperature","format":"{{msg.payload}}","layout":"row-center","x":660,"y":2320,"wires":[]},{"id":"b1d1dca0.453be","type":"ui_text","z":"e60c0f81.64c18","group":"8007d5e0.fc68a8","order":2,"width":0,"height":0,"name":"","label":"Core 2 Temperature","format":"{{msg.payload}}","layout":"row-center","x":660,"y":2360,"wires":[]},{"id":"dd72b678.7599e8","type":"ui_text","z":"e60c0f81.64c18","group":"8007d5e0.fc68a8","order":3,"width":0,"height":0,"name":"","label":"Core 3 Temperature","format":"{{msg.payload}}","layout":"row-center","x":660,"y":2400,"wires":[]},{"id":"39fcaaab.85efa6","type":"ui_text","z":"e60c0f81.64c18","group":"8007d5e0.fc68a8","order":4,"width":0,"height":0,"name":"","label":"Core 4 Temperature","format":"{{msg.payload}}","layout":"row-center","x":660,"y":2440,"wires":[]},{"id":"572eed08.5bb714","type":"mqtt-broker","z":"","name":"Mosquitto Orange","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"51bdd67d.76b488","type":"ui_group","z":"","name":"RetroPi","tab":"69d311f6.b104c","order":1,"disp":true,"width":"12","collapse":false},{"id":"c2baeca.d963e1","type":"ui_group","z":"","name":"Orange Pi PC PLUS","tab":"69d311f6.b104c","order":2,"disp":true,"width":"12","collapse":false},{"id":"8007d5e0.fc68a8","type":"ui_group","z":"","name":"Intel PC","tab":"69d311f6.b104c","order":3,"disp":true,"width":"12","collapse":false},{"id":"69d311f6.b104c","type":"ui_tab","z":"","name":"CPU Temperature","icon":"dashboard","order":3}]

These graphics are displayed in 24 hours.

The steps for RaspberryPi 3 in RetroPi and Orange Pi PC PLUS in Armbian differ only in the name of the topic in which we will send the temperature value

install on minipc
sudo apt-get install mosquitto-clients
lets go to
cd /home/pi
make file
vi sendtemp.sh
add code

#!/bin/bash
a=`cat /sys/class/thermal/thermal_zone0/temp`
d=$(( ${a}/1000 ))
/usr/bin/mosquitto_pub -h "192.168.1.209" -u Login -P MyPassword -t "pccpu/retropi" -m "${d}"

make it executible
chmod +x sendtemp.sh
add to cron
crontab -e
line

* * * * * sh /home/pi/sendtemp.sh

The commands for Orangepi are the same, but instead of pccpu/retropi, you must put pccpu/orangepiplus and the path to the script

Now, for the Intel PC in Ubuntu, it is not so easy to get the temperature, it is different for each core
must be installed
sudo apt-get install mosquitto-clients
and for sensors
sudo apt-get install lm-sensors
sudo sensors-detect

list of sensors
sudo sensors -u
lets go to home folder
cd /home/user
make file
sudo vi sendtemp.sh
add

#!/bin/bash
c1=`sensors -u *-isa-* | grep "temp2_input:" | awk '{printf "%.0f", $2}'`
/usr/bin/mosquitto_pub -h "192.168.1.209" -u Login -P MyPassword -t "pccpu/inteli5c1" -m "${c1}"
c1=`sensors -u *-isa-* | grep "temp3_input:" | awk '{printf "%.0f", $2}'`
/usr/bin/mosquitto_pub -h "192.168.1.209" -u Login -P MyPassword -t "pccpu/inteli5c2" -m "${c1}"
c1=`sensors -u *-isa-* | grep "temp4_input:" | awk '{printf "%.0f", $2}'`
/usr/bin/mosquitto_pub -h "192.168.1.209" -u Login -P MyPassword -t "pccpu/inteli5c3" -m "${c1}"
c1=`sensors -u *-isa-* | grep "temp5_input:" | awk '{printf "%.0f", $2}'`
/usr/bin/mosquitto_pub -h "192.168.1.209" -u Login -P MyPassword -t "pccpu/inteli5c4" -m "${c1}"

make it executible
sudo chmod +x sendtemp.sh
add to cron
sudo crontab -e
line

* * * * * sh /home/user/sendtemp.sh

And it works!


Leave a Reply

Your email address will not be published. Required fields are marked *