NodemCu scheduling

Hi everyone. I have a basic heating control project that formed 2 part. One of (master one) reading room temp and send it to other one (slave one) with nRF24. Master one managed with Ard. NANO, slave one managed with Ard. PRO MİNİ. slave one has also relay to control combi and has DS1302 RTC to scheduling.

I was chaged the slave one (PRO MİNİ) to Nodemcu. My first effort, “reading nRF24 signals with Nodemcu” was successful. But scheduling was not. I think I can use DS1302 module with Nodemcu but there is Blynk here, isnt it? :slight_smile: and its modules like “time input” or “RTC”. I can use them… :confused: can I?

My heating schedule like this;

sheduling part of the code that running on PRO mini is:

     void loop()
    {
      time_function();
      while (myRTC.dayofweek < 6)
      {
        while (myRTC.hours < 6)
        {
          time_function();
          set_temp = 19;                        // set_temp combi to 19
          Serial.println("Weekdays");
          Serial.println("sleeping Mode");
        }
        while (myRTC.hours < 8)
        {
        time_function();
        set_temp = 22;
        Serial.println("Weekdays");
        Serial.println("wake up Mode");
        }
        while (myRTC.hours < 17)
        {
        time_function();
        set_temp = 19;
        Serial.println("Weekdays");
        Serial.println("Home is empty");
        }
        while (myRTC.hours >= 17)
        {
        time_function();
        set_temp = 22;
        Serial.println("Weekdays");
        Serial.println("People in the house");
        }
      }
  while (myRTC.dayofweek < 8)
  {
     while (myRTC.hours <= 7)
     {
      time_function();
      set_temp = 19;
      Serial.println("Weekend");
      Serial.println("sleeping Mode");
      }
      while (myRTC.hours > 7)
      {
      time_function();
      set_temp = 22;
      Serial.println("Weekend");
      Serial.println("People in the house");
      }
  }

You can see all project and codes from here: https://www.hackster.io/tsavascii/programmable-wireless-room-thermostat-bluetooth-accessible-8cd516

Actually my schedule only has two mode: one of set the target temp to 19C, other 22C. After that device listen to RF Channel and decide to run the combi “on” or stay it “off”. So my questions are;

  1. Is it possible to do this with Blynk time input?

  2. If yes then how? Should I add two sperate time input module to my dashboard? or only one can my schedule?

  3. Finally, Should I add a RTC module?

      1. The Blynk library version you are using.  **(0.4.6)**
      2. Android or iOS and the version of the OS. **(Android 5.0)**
      3. Server type, Local or Cloud based. **(Dont know i think Cloud)**
      4. If local server, which version you are using. **(?)**
      5. How you powering the MCU. **(with USB)**
      6. Has the MCU ever connected to a Blynk server (Cloud or local). **(yes)**
      7. The IDE you areusing, including the version number. **(Arduino 1.8.1)**
      8. The settings you have in the IDE for the MCU. **(NodeMCU 1.0 (ESP-12E Module)**
      9.The Arduino core version you are using. **(1.8.1 i think)**
     10. The make and model of your phone. **(Samsung Note 3)**
    

_
11.Your shoe size and anything else you think is important. **(43 EU) * :slight_smile:

Thanks…

@tsavasci yes you can do all what you need with Blynk’s RTC and Time Input widgets. You will need to do a bit of coding to put it all together but there are several examples on this site.

We use 2 Time Input widgets, one for weekdays and one for weekends. We also use the single character hack for Time Input so that no days selected turns off our scheduler. As written the widget takes no days selected to be “ON” for all days. When you find the hack you might want to send a push request via GitHub to Blynk as I’m sure more people would consider no days selected to be “OFF” rather than “ON”.

If you have a reliable internet connection then a physical RTC module should be optional.

1 Like

Thanks for the fast response…this is what i understand from your answer;
I must use 2 Time input widgets one of for weekdays, other one for weekend but how can i set up hourly start-stop time. My schedule goes in and out 2 different modes, 4 times in a day. But time input widgets allow to me only one start and stop time.

For example i will set up a time input widget, which is in weekdays start at 06:50 and stop at 07:50 (my wake up mode) then at 07:51 what will happen?

how can i describe my “empty home mode” start-stop hours that comes after “wake up mode” with this time input widget.

what about this dashboard? is it genius or nonsense of the novice :smile: (Dont hurt :blush: )

You can have as many Time Input widgets as you desire, we just use separate widgets for weekdays and weekends because it suits our needs. As the Time Input widget works without stopping the project then we can change the times of the schedule when we want to.

If we wanted several on an off times during a day we would use more than 2 Time Input widgets.

Take a look at the timeChecker() function in our code at How to use Advanced TimeInput to turn on/off an output?

If you have more than one time to check in a day you would simply duplicate, triplicate everything including the variable names. So timerChecker2(), timeChecker3() and modify all the variables accordingly.

Please describe your “empty home mode” and “wake up mode” in more detail.

Thanks again. I think timerchecker() function will suits to me… mode have no detail by the way :wink:

Weekdays:

  • 06:00 - 08:00 = We wake up at 07:00, so home must be heated before we wake up. Combi try to heat home to 22C in this mode.

  • 08:00 - 17:00 = we are at office so home is empty. It is not necessary to much heat so combi will wait until temp fall below 19C.

  • 17:00 - 00:00 = we came home at 18:00 so combi will try to raise temp to 22C, one hour before we come.

  1. 00:00 - 06:00 = we sleep so heat will slightlyt fall to 19C and combi keep 19C until we wake up

weekend only have 2 modes sleeping (19C) and normal (22C)…

by the way sometimes my wife shouts to me “Tamer…! home is so cold…your damn iot things…its cold raise the temp rapidly…!!” :smile: for this stuations I bought and learn bluetooth module (HC05) to include “forced mode”. When my wife triggered (shouted :slight_smile: ) to me i connect to HC05 and set the combi “forced mode” and combi raise the temp to 60C…until we all burn :joy:. (Turkish bath mode)

Lets be serious. If I colud schedule my project with Blynk time input widget i dont deal with HC05 module.

Note: Ladies more than accurate DHT11, DHT22 and DS18B20… trust me.

This my all code in PRO MİNİ:

//   WIRELESS ROOM THERMOSTAT v1.0 (RECEIVER)
//
//  Writer: Tamer Savaşcı
//  Date: 27.01.2017
//
//  email: tsavasci@yahoo.com


#include <SPI.h>
#include <nRF24L01p.h>
#include <virtuabotixRTC.h>
#include <SoftwareSerial.h>
SoftwareSerial bluetoothModule(A0, A1);
/* Arduino  ->  Bluetooth module
  A0 (Rx)   ->  Tx
  A1 (Tx)   ->  Rx
*/

nRF24L01p receiver(7, 8);            // CSN = 7, CE = 8
virtuabotixRTC myRTC(5, 4, 3);    // SCLK = 5, I/O(DAT) = 4, CE = 3

int relay = 2;
float set_temp;
float room_temp;
char BT_readChar;
int relay_status = 0;
int BT_Force = 0;

void BT ()
{
  BT_readChar = bluetoothModule.read();
  switch (BT_readChar)
  {
case 'a':
  BT_Force = 1;
  digitalWrite(relay, HIGH);
  relay_status = 1;
  Serial.println("Forced mode: on");
  bluetoothModule.println("Forced mode: on");
  break;

case 'b':
  BT_Force = 0;
  Serial.println("Combi is waiting RF command by Bluetooth command");
  bluetoothModule.println("Combi is waiting RF command by Bluetooth command");
  break;
  }
}

void time_function()
{
  myRTC.updateTime();
  Serial.print("Date / Time : ");
  Serial.print(myRTC.dayofmonth);
  Serial.print("/");
  Serial.print(myRTC.month);
  Serial.print("/");
  Serial.print(myRTC.year);
  Serial.print(" ");
  Serial.print("(");
  Serial.print(myRTC.dayofweek);
  Serial.print(")");
  Serial.print(" ");
  Serial.print(myRTC.hours);
  Serial.print(":");
  Serial.print(myRTC.minutes);
  Serial.print(":");
  Serial.println(myRTC.seconds);
  delay(3000);
}

void RF()
{
  while (receiver.available())         // while receiver active
  {
receiver.read();
receiver.rxPL(room_temp);           // read receiver
digitalRead(BT_Force);
if (BT_Force == 0)
{
  if (set_temp > room_temp)             // if "set_temp" value bigger than "room temp"
  {
    digitalWrite(relay, HIGH);      // trigger the relay
    relay_status = 1;
    Serial.println("Combi opened due to RF temp data"); // Combi is ON
    Serial.println();
    bluetoothModule.println("Combi opened due to RF temp data");
    bluetoothModule.println();
    digitalRead(BT_Force);
  }
  else                             // otherwise cut the power of relay
  {
    digitalWrite(relay, LOW);
    relay_status = 0;
    Serial.println("Combi closed due to RF temp data"); // combi is OFF
    Serial.println();
    bluetoothModule.println("Combi closed due to RF temp data");
    bluetoothModule.println();
    digitalRead(BT_Force);
  }
}
else
{
  Serial.println("Combi is working in forced mode by Bluetooth command");
  bluetoothModule.println("Combi is working in forced mode by Bluetooth command");
}
  }
}

void seri()
{
  Serial.print("set_temp: ");
  Serial.println(set_temp);
  Serial.print("Room temp: ");
  Serial.println(room_temp);
  Serial.print("BT Forced status: ");
  Serial.println(BT_Force);
  Serial.println ();
}

void BT_info()
{
  bluetoothModule.print("set_temp: ");
  bluetoothModule.println(set_temp);
  bluetoothModule.print("Room temp: ");
  bluetoothModule.println(room_temp);
  bluetoothModule.println();
  if (relay_status < 1)
  {
bluetoothModule.println("Combi:On");
bluetoothModule.println ();
  }
  else
  {
bluetoothModule.println("Combi:Off");
bluetoothModule.println ();
  }
}

void setup()
{
  bluetoothModule.begin(9600);
  Serial.begin(9600);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  receiver.channel(90);
  receiver.RXaddress("Tamer");
  receiver.init();
  pinMode (2, OUTPUT);
  //myRTC.set_tempDS1302Time(00, 19, 01, 04, 9, 03, 2017);  // This line is for the first upload to arduino than deactive it with (//)
}

void loop()
{
  time_function();
  while (myRTC.dayofweek < 6)
  {
while (myRTC.hours < 6)
{
  time_function();
  set_temp = 19;                        // set_temp combi to 19
  Serial.println("Weekdays");
  Serial.println("Gece Modu");
  seri();
  bluetoothModule.println("Weekdays");
  bluetoothModule.println("Gece Modu");
  BT_info();
  RF();
  BT();
}
while (myRTC.hours < 8)
{
  time_function();
  set_temp = 22;
  Serial.println("Weekdays");
  Serial.println("Uyanis Modu");
  seri();
  bluetoothModule.println("Weekdays");
  bluetoothModule.println("Uyanis Modu");
  BT_info();
  RF();
  BT();
}
while (myRTC.hours < 17)
{
  time_function();
  set_temp = 19;
  Serial.println("Weekdays");
  Serial.println("Home is empty");
  seri();
  bluetoothModule.println("Weekdays");
  bluetoothModule.println("Home is empty");
  BT_info();
  RF();
  BT();
}
while (myRTC.hours >= 17)
{
  time_function();
  set_temp = 22;
  Serial.println("Weekdays");
  Serial.println("People in the house");
  seri();
  bluetoothModule.println("Weekdays");
  bluetoothModule.println("People in the house");
  BT_info();
  RF();
  BT();
}
  }
  while (myRTC.dayofweek < 8)
  {
while (myRTC.hours <= 7)
{
  time_function();
  set_temp = 19;
  Serial.println("Weekend");
  Serial.println("Gece Modu");
  seri();
  bluetoothModule.println("Weekend");
  bluetoothModule.println("Gece Modu");
  BT_info();
  RF();
  BT();
}
while (myRTC.hours > 7)
{
  time_function();
  set_temp = 22;
  Serial.println("Weekend");
  Serial.println("People in the house");
  seri();
  bluetoothModule.println("Weekend");
  bluetoothModule.println("People in the house");
  BT_info();
  RF();
  BT();
}
  }
}

Yessssss…I found it… :smile:
on Blynk web “sketch builder” help me. I look at the RTC example, day hour second ok but where is weekday? Weekday counting very imported for my code. I studied the code;

String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + " " + month() + " " + year(); 

easily include the weekday, i type w,e,e,k (still nothing), d,a,y (and its turn orange) yesss… :smile:

String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + " " + month() + " " + weekday() + " " + year(); 

so i have the weekday, i think its start with 1 Sunday because it shows 2 for monday.

@tsavasci you will have to code up a mod for weekday as Blynk don’t use the common notation of the week starting on a Sunday. Blynk’s week starts on a Monday.

Something like this:

int dayadjustment = -1;

if(weekday() == 1){
    dayadjustment =  6; // needed for Sunday, Time library is day 1 and Blynk is day 7
}

if(t.isWeekdaySelected((weekday() + dayadjustment))){ 
  // code here
}

Hımm :rolling_eyes: yes I will use your suggestion but why blynk dont use common notation? why do not they fix it? They must have a meaningful reason for this…whatever. Thank you @Costas