Need help with my DIY Thermostat project

I searched a lot and tried even more but I am giving up on it almost.
What I am trying to make is a easy controllable Thermostat with an esp8266 , a DHT11 and a Relay.
I got the Project running as far as setting a max and min temp in the code but I am just not able ( dont know) how I can implement and set a temperature thats is executed correctly in Blynk.

So far it I got both Temp and Humidity showing as a gauge, and the diy Thermostat is acting correct with the programmed min and max Temp, but like I said I have no idea what to do/programm to set a point in blynk to reach the wanted target temperature simply switching the signal relay ( for the pump and burner) on and off.

I only got this weekend as I am visiting my mother and she got this super old not at all usable antique Thermostat on the wall. I tried as much as possible at home but it would be a great help if someone could complete my " kinda like working code" so I can finish the work and make the heating working precise.
Right now its impossible so set a normal room temperature as there is only one analog knob and that does not even show any markings of temperature at all. its either deadly hot, burning huge amounts of oil or terrible cold.

Thanks so much in advance!


#define BLYNK_PRINT Serial    
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#define DHTPIN 14 //pin gpio 12 in sensor
#define DHTTYPE DHT11   
DHT dht(DHTPIN, DHTTYPE);

//Constants 
const int Relay = 13;   
const int Temperature = 14;  


int value;
int mintemp = 21;
int maxtemp = 24;


char auth[] = "xxxxxxxxxxxxxxxxxx";  

SimpleTimer timer;

void setup()
{
  Serial.begin(11500); // See the connection status in Serial Monitor
  Blynk.begin(auth, "xxxxxxxx", "xxxxxxxxx"); 


  timer.setInterval(1500L, sendUptime);

    pinMode(Relay,OUTPUT);
}

void sendUptime()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  Blynk.virtualWrite(0, t); 
  Blynk.virtualWrite(1, h); 
}

void loop()
{
    
   float t = dht.readTemperature();
  if(t < mintemp){
    digitalWrite(Relay,HIGH);
  }
 

  {
    
   float t = dht.readTemperature();
  if(t > maxtemp){
    digitalWrite(Relay,LOW);
  }
  
  delay(150); 
  Blynk.run();
  timer.run();
}
}

not sure what is not working.

Watch out also for hysteresis loops - at least at present you have a range of temperatures in which you wont switch the relay.

As it is now I have no way of changing the wanted temperature. I want to be able to manipulate the temperature. Right now I cannot do that. it is set to 21min and 24 max.
What I am trying to do is to have a working slider in blynk where I can set a temperature.
so Blynk should compare the actual temperature with the selected and control it to the set temp.

For start, your void loop should consist of blynk.run and timer.run. Nothing else. There’s a lot of discussion about that on this forum, so use search option.

You need a BLYNK_WRITE(Vx) function, where x is the virtual pin that your slider is attached to.

Each time the slider value changes, the BLYNK_WRITE function is called automatically. You then get the value from the slider using the param.asInt or param.asFloat (depending on whether you want whole numbers of decimals as your value for the target temperature).

You would then probably want to set your minimum temperature and maximum temperature based on this result from the slider. Say, half a degree lower than target for your minimum and half a degree higher for your maximum (but you’d need to use float variables for your min/max to do this).

The code that takes the temperature readings and does the if comparisons needs to be moved into your sendUptime function (and get rid off the delay - it’s not needed because the function is only called every 1.5 seconds, and you don’t need to take a temperature reading before each if statement, you’ve already taken one at the start of the sendUptime function).

For completeness, you should do a Blynk.syncVietual(Vx) in your void setup (at the end of the existing void setup code) to force the slider value to be retrieved from the Blynk server on startup. Without this, the slider would have to be moved manually to trigger a BLYNK_WRITE from the slider.

Be aware that the DHT sensors are super inaccurate, so if you want a room temperature that’s actually 22° you may have to set your slider to 18° or 25°, depending on your particular sensor.

These sensors sometimes return a reading that isn’t valid, so the code to read them often has a NAN (not a number) test incorporated into it. You’d do well to look st DHT code examples and copy them to incorporate this test.

I’d also say that leaving your mother with a half-tested thermostat at the end of the weekend probably isn’t the best idea!

This post was written on a mobile phone and these syntax of the commands is from memory rather than properly checked, so you’ll need to look at code examples to get it exactly right, but it should be near enough to help you with your search criteria.

Pete.

ok thanks a lot for your time, will try my best.