I guess this code is what you’re trying to implement:
//#define USE_BLYNK_WM true
#define USE_BLYNK_WM false
#if USE_BLYNK_WM
#include <BlynkSimpleEsp8266_WM.h> //https://github.com/khoih-prog/Blynk_WM
#else
#include <BlynkSimpleEsp8266.h>
#endif
#include "DHT.h"
// Use what pin you're using OK
#define DHT_PIN D4
#define DHTTYPE DHT11 // DHT 22 (AM2302)
DHT dht(DHT_PIN, DHTTYPE);
BlynkTimer timer;
bool notified = false;
bool allowNotify = false;
#if !USE_BLYNK_WM
char auth[] = "**************";
char ssid[] = "****";
char pass[] = "****";
char server[] = "x.x.x.x";
#endif
// You have to add RTC widget to the APP
#include <WidgetRTC.h>
WidgetRTC rtc;
// To create display widgets @ V9 and V10 for displaying dailyMinTemp and dailyMaxTemp
#define MIN_AVG_TEMP -273
float dailyMaxTemp;
float dailyMinTemp;
float dailyAvgTemp = MIN_AVG_TEMP;
bool restartDailyLog = true;
bool newDay = false;
BLYNK_CONNECTED()
{
rtc.begin();
//synchronize the state of widgets with hardware states
Blynk.syncAll();
}
BLYNK_WRITE(V3) //Notifications on or off, make it a ON/OFF switch, not pushbutton
{
allowNotify = param.asInt(); // assigning incoming value from pin V3 to a variable
if (allowNotify) { // If value is 1 run this command
digitalWrite(D10, HIGH); //D4 output from Wemos D1 mini
}
else { // If value is 0 run this command
digitalWrite(D10, LOW);
}
Serial.print("V3 Button value is: ");
Serial.println(allowNotify);
}
int MIN_TEMP_ALARM;
int MAX_TEMP_ALARM;
// Slider for MIN TEMP ALARM
BLYNK_WRITE(V7)
{
MIN_TEMP_ALARM = param.asInt();
Serial.println("MIN_TEMP_ALARM(V4) = " + String(MIN_TEMP_ALARM));
}
//// Slider for MAX TEMP ALARM
BLYNK_WRITE(V8)
{
MAX_TEMP_ALARM = param.asInt();
Serial.println("MAX_TEMP_ALARM(V4) = " + String(MAX_TEMP_ALARM));
}
#define MAX_TEMP_IN_CELCIUS 100
#define MIN_TEMP_IN_CELCIUS 0
void sendSensor()
{
String notifyString;
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Reset startDailyLog every day once, between 12:00:00-12:00:59AM
if (!newDay && (hour() == 0) && (minute() == 0))
{
Serial.println("newDay: " + String(hour()) + ":" + String(minute()));
restartDailyLog = true;
newDay = true;
}
else if (newDay && (hour() != 0))
{
Serial.println("Reset newDay: " + String(hour()) + ":" + String(minute()));
newDay = false;
}
// Reset MIN/MAX values if new day
if (restartDailyLog)
{
restartDailyLog = false;
dailyMaxTemp = MIN_TEMP_IN_CELCIUS;
dailyMinTemp = MAX_TEMP_IN_CELCIUS;
dailyAvgTemp = MIN_AVG_TEMP;
}
// Record MIN and MAX
if (t > dailyMaxTemp)
{
dailyMaxTemp = t;
// Send daily MAX only when necessary
// To create display widgets @ V9 and V10 for displaying dailyMinTemp and dailyMaxTemp
Serial.println("DMax: " + String(dailyMaxTemp, 1));
Blynk.virtualWrite(V10, String(dailyMaxTemp, 1));
}
if (t < dailyMinTemp)
{
dailyMinTemp = t;
// Send daily MAX only when necessary.
// To create display widgets @ V9 and V10 for displaying dailyMinTemp and dailyMaxTemp
Serial.println("DMin: " + String(dailyMinTemp, 1));
Blynk.virtualWrite(V9, String(dailyMinTemp,1));
}
// calculate dailyAvgTemp
if (dailyAvgTemp == MIN_AVG_TEMP)
{
dailyAvgTemp = t;
}
else
{
dailyAvgTemp = (dailyAvgTemp + t) / 2;
}
// You can send any value at any time.
// Please don't send more that 10 values per second. Use 1 decimal
Serial.println("T: " + String(t, 1) );
Serial.println("H: " + String(h, 1));
Serial.println("A: " + String(dailyAvgTemp, 1));
Blynk.virtualWrite(V5, String(h, 1));
Blynk.virtualWrite(V6, String(t, 1));
// To create display widget @ V11 for displaying dailyAvgTemp
Blynk.virtualWrite(V11, String(dailyAvgTemp, 1));
if (allowNotify)
{
//Notifications 1st try
if (t >= MAX_TEMP_ALARM && !notified)
{
notified = true;
notifyString = "Alert - T > " + String(MAX_TEMP_ALARM);
Serial.println(notifyString);
Blynk.notify(notifyString);
timer.setTimeout(600000L, resetNotified); // 10 min between messages
}
else if ((t < MIN_TEMP_ALARM - 1) && (t > MIN_TEMP_ALARM + 1))
{
notified = false;
}
else if (t <= MIN_TEMP_ALARM && !notified)
{
notified = true;
notifyString = "Alert - T < " + String(MIN_TEMP_ALARM);
Serial.println(notifyString);
Blynk.notify(notifyString);
timer.setTimeout(600000L, resetNotified); // 10 min between messages
}
}
}
void resetNotified()
{
notified = 0;
}
void setup()
{
Serial.begin(115200);
Serial.println("\nStarting");
#if USE_BLYNK_WM
Blynk.begin();
#else
WiFi.begin(ssid, pass);
Blynk.config(auth, server, 8080);
//Blynk.config(auth);
Blynk.connect();
if ( Blynk.connected())
Serial.println("Connected to Blynk");
#endif
dht.begin();
timer.setInterval(30000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
With this code, the daily MIN/MAX and AVG log starts around 12:00:xx AM.
You can use 2 sliders to set the MIN / MAX alarm values.
You have to create some more Widgets such as RTC, display to show the new values.
Good luck