Timezone conversion for the Time Input widget

Do you use latest library now? Advanced example? TimeInputParam? This is what I get :

Start: 15:30:0
Stop: 16:30:0
Time zone: Europe/Kiev
Time zone offset: 10800
Day 7 is selected

Start: 15:30:0
Stop: 16:30:0
Time zone: Etc/UTC
Time zone offset: 0
Day 7 is selected

Don’t forget - you need to select at least 1 day.

Why are you getting 0, surely Kiev is not 0.
I have downloaded 0.3.9 but not set it up yet.

My bad. This output before app update. Updated comment.

@Dmitriy TZ wasn’t in the old library but it is in 0.3.9. All fine and thanks for the fix.

Time zone: Europe/Athens
Time zone offset: 10800
Start: 1:23
Weekdays Schedule Started
5992
4980
Stop: 2:34
Weekdays Schedule NOT Stopped
5992
9240
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected

[98177] Time sync: OK
1 Like

Serial Monitor output for the following sketch:

TimeInput set as ON time 11:20 and OFF time as 11:25. Initially without Wednesday enabled and then enabled just prior to 11:20. Confirmed with LED on between 11:20 and 11:25.

The important lines in the code are:

65 compare Time library days of the week (Day 1 is Sunday) with Blynk days of the week (Day 1 is Monday). So -1 deducted from Time library day.

90 and 104 has a 90s window to check the current time with the 60s SimpleTimer interval to ensure the relay is turned ON and OFF just once at the start and stop times.

Starting
[17892] Connecting to MTN WIFI 19996
[18893] Connected to WiFi
[18893] IP: 192.168.10.171
[18893] Blynk v0.3.9 on ESP8266
[18893] Connecting to 192.168.10.229:8442
[19081] Ready (ping: 10ms).
[19103] Time sync: OK
Checked schedule at: 11:16:13
Schedule INACTIVE today

Checked schedule at: 11:17:13
Schedule INACTIVE today

Checked schedule at: 11:18:13
Schedule INACTIVE today

Checked schedule at: 11:19:13
Schedule INACTIVE today

Checked schedule at: 11:19:32
Schedule ACTIVE today
Start: 11:20
Stop : 11:25
Time zone: Europe/Nicosia
Time zone offset: 10800
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
Motor NOT STARTED today

Checked schedule at: 11:20:13
Schedule ACTIVE today
Start: 11:20
Stop : 11:25
Time zone: Europe/Nicosia
Time zone offset: 10800
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
Motor STARTED at 11:20
Motor is still RUNNING

[319218] Time sync: OK
Checked schedule at: 11:21:13
Schedule ACTIVE today
Start: 11:20
Stop : 11:25
Time zone: Europe/Nicosia
Time zone offset: 10800
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
Motor STARTED at 11:20
Motor is still RUNNING

Checked schedule at: 11:22:12
Schedule ACTIVE today
Start: 11:20
Stop : 11:25
Time zone: Europe/Nicosia
Time zone offset: 10800
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
Motor STARTED at 11:20
Motor is still RUNNING

Checked schedule at: 11:23:13
Schedule ACTIVE today
Start: 11:20
Stop : 11:25
Time zone: Europe/Nicosia
Time zone offset: 10800
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
Motor STARTED at 11:20
Motor is still RUNNING

Checked schedule at: 11:24:13
Schedule ACTIVE today
Start: 11:20
Stop : 11:25
Time zone: Europe/Nicosia
Time zone offset: 10800
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
Motor STARTED at 11:20
Motor is still RUNNING

Checked schedule at: 11:25:13
Schedule ACTIVE today
Start: 11:20
Stop : 11:25
Time zone: Europe/Nicosia
Time zone offset: 10800
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
Motor STARTED at 11:20
Motor STOPPED at 11:25

[619262] Time sync: OK
Checked schedule at: 11:26:13
Schedule ACTIVE today
Start: 11:20
Stop : 11:25
Time zone: Europe/Nicosia
Time zone offset: 10800
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
Motor STARTED at 11:20
Motor STOPPED at 11:25

Checked schedule at: 11:27:12
Schedule ACTIVE today
Start: 11:20
Stop : 11:25
Time zone: Europe/Nicosia
Time zone offset: 10800
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
Motor STARTED at 11:20
Motor STOPPED at 11:25

Sketch:

 /**************************************************************
 * timeinput.ino Demonstrate interaction of Time library with
 * Blynk's TimeInput widget, Costas 14/9/16
 * App project setup:
 * RTC on V0 and Time Input widget on V1.
 *
 **************************************************************/

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

SimpleTimer timer;

WidgetRTC rtc;

BLYNK_ATTACH_WIDGET(rtc, V0);
#define server "192.168.10.229"   // or "blynk.cloud-com" for Blynk's cloud server
#define TestLED 2                 // on board LED pin assignment
char Date[16];
char Time[16];
char auth[] = "*******************";
char ssid[] = "MTN WIFI 19996";
char pass[] = "******************I";
long startsecondswd;            // weekday start time in seconds
long stopsecondswd;             // weekday stop  time in seconds
long nowseconds;                // time now in seconds

void setup()
{
  pinMode(TestLED, OUTPUT);
  digitalWrite(TestLED, HIGH); // set LED OFF
  Serial.begin(115200);
  Serial.println("\Starting");
  Blynk.begin(auth, ssid, pass, server);
  int mytimeout = millis() / 1000;
  while (Blynk.connect() == false) { // try to connect to server for 10 seconds
    if((millis() / 1000) > mytimeout + 8){ // try local server if not connected within 9 seconds
       break;
    }
  }
  rtc.begin();
  timer.setInterval(60000L, activetoday);  // check every minute if schedule should run today 
  timer.setInterval(30000L, reconnectBlynk);  // check every 30s if still connected to server 
}

void activetoday(){        // check if schedule should run today
  if(year() != 1970){
    Blynk.syncVirtual(V1); // sync timeinput widget    
  }
}

BLYNK_WRITE(V1) {
  sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
  sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
  
  TimeInputParam t(param);
  
  Serial.print("Checked schedule at: ");
  Serial.println(Time);
  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))){ //Time library starts week on Sunday, Blynk on Monday
    Serial.println("Schedule ACTIVE today");
    if (t.hasStartTime()) // Process start time
    {
      Serial.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
    }
    if (t.hasStopTime()) // Process stop time
    {
      Serial.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
    }
    // Display timezone details, for information purposes only 
    Serial.println(String("Time zone: ") + t.getTZ()); // Timezone is already added to start/stop time 
    Serial.println(String("Time zone offset: ") + t.getTZ_Offset()); // Get timezone offset (in seconds)
  
    for (int i = 1; i <= 7; i++) {  // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
      if (t.isWeekdaySelected(i)) {
        Serial.println(String("Day ") + i + " is selected");
      }
    } 
    nowseconds = ((hour() * 3600) + (minute() * 60) + second());
    startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
    //Serial.println(startsecondswd);  // used for debugging
    if(nowseconds >= startsecondswd){    
      Serial.print("Motor STARTED at");
      Serial.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
      if(nowseconds <= startsecondswd + 90){    // 90s on 60s timer ensures 1 trigger command is sent
        digitalWrite(TestLED, LOW); // set LED ON
        // code here to switch the relay ON
      }      
    }
    else{
      Serial.println("Motor NOT STARTED today");
      // nothing more to do here, waiting for motor to be turned on later today      
    }
    stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
    //Serial.println(stopsecondswd);  // used for debugging
    if(nowseconds >= stopsecondswd){
      Serial.print("Motor STOPPED at");
      Serial.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
      if(nowseconds <= stopsecondswd + 90){   // 90s on 60s timer ensures 1 trigger command is sent
        digitalWrite(TestLED, HIGH); // set LED OFF
        // code here to switch the relay OFF
      }              
    }
    else{
      if(nowseconds >= startsecondswd){  // only show if motor has already started today
        Serial.println("Motor is still RUNNING");
        // nothing more to do here, waiting for motor to be turned off later today
      }          
    }
  }
  else{
    Serial.println("Schedule INACTIVE today");
    // nothing to do today, check again in 1 minutes time    
  }
  Serial.println();
}

void reconnectBlynk() {
  if (!Blynk.connected()) {
    if(Blynk.connect()) {
      BLYNK_LOG("Reconnected");
    } else {
      BLYNK_LOG("Not reconnected");
    }
  }
}

void loop()
{
  if (Blynk.connected()) {
    Blynk.run();
  }
  timer.run();
}
2 Likes

@Dmitriy with TimeInput set as ON at 20:00 and OFF at 21:00 I am getting the following results with AdvancedTimeInput and server 0.18.2

Start: 17:0:0
Stop: 18:0:0
Time zone: Europe/Nicosia
Time zone offset: 0
Day 7 is selected

Start: 20:0:0
Stop: 21:0:0
Time zone: Etc/UTC
Time zone offset: 0
Day 7 is selected

Start: 17:0:0
Stop: 18:0:0
Time zone: Europe/Kiev
Time zone offset: 0
Day 7 is selected

Timezone offset has disappeared again and the Start and Stop times are not being adjusted for the Timezones.

@Costas please try to remove and add widget again. Does that help?

Tried that, no joy.

Tried 0.18.0, no joy either.

Seems like outdated app…

1 Like

@Dmitriy at your side or mine?

Yours.

You were right, I do that much with Droid4X these days I had forgotten to upgrade to version 15.2 on my actual phone.

Can you confirm that there are currently no widgets that allow users to paste text into a “field”.

Just terminal If I understood you correctly.

I thought I tried in Terminal but I’ll try again.

@Dmitriy I tried to paste to Terminal on my Samsung S3 and the only option I have is to enter text from the pop up keyboard. Paste works in other apps.

I have tried this example. When I change the time zone the t.getStartHour and t.getStopHour is always UTC time.
nowseconds = ((hour() * 3600) + (minute() * 60) + second()); this is the correct time zone.
How do I get the two in the same time zone?

Checked schedule at: 19:31:12
Schedule ACTIVE today
Start: 0:35
Stop : 1:30
Time zone: America/New_York
Time zone offset: 4294949296
Day 1 is selected
Motor STARTED at 0:35
Motor STOPPED at 1:30

Checked schedule at: 19:31:21
Schedule INACTIVE today

Checked schedule at: 19:31:30
Schedule ACTIVE today
Start: 0:35
Stop : 1:30
Time zone: America/New_York
Time zone offset: 4294949296
Day 1 is selected
Day 2 is selected
Day 3 is selected
Day 4 is selected
Day 5 is selected
Day 6 is selected
Day 7 is selected
Motor STARTED at 0:35
Motor STOPPED at 1:30

[670256] Time sync: OK
Checked schedule at: 19:29:13
Schedule ACTIVE today
Start: 0:20
Stop : 1:30
Time zone: GMT
Time zone offset: 0
Day 1 is selected
Motor STARTED at 0:20
Motor STOPPED at 1:30

Checked schedule at: 19:30:12
Schedule ACTIVE today
Start: 0:20
Stop : 1:30
Time zone: GMT
Time zone offset: 0
Day 1 is selected
Motor STARTED at 0:20
Motor STOPPED at 1:30

@BSlaght do you have the RTC widget in your Project?

Perhaps post your sketch and your project. Maybe the sketch we posted doesn’t like AM / PM used in America and for test purposes you could try to use the 24 hour clock to see if that helps.

I have reached the max the number of pictures I can upload upload.
I am using the iPhone App
I have RTC on V0
Time Input to V1

Changed to the 24 hour clock.
Set start to 15:56
Set Stop to 15:59

Output:
[240] Connecting to XXX
[1241] Connected to WiFi
[1241] IP: 192.168.1.100
[1241]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.4.0 on NodeMCU

[5001] Connecting to blynk-cloud.com:8442
[5079] Ready (ping: 1ms).
[10080] Connecting to blynk-cloud.com:8442
[10157] Ready (ping: 0ms).
[10212] Time sync: OK

Checked schedule at: 15:58:38
Schedule ACTIVE today
Start: 20:56
Stop : 20:59
Time zone: America/New_York
Time zone offset: 4294949296
Day 2 is selected
Motor NOT STARTED today