Autor Thema: Time comparison  (Gelesen 428 mal)

Offline @lex99

  • New Member
  • *
  • Beiträge: 11
Time comparison
« am: 18 Oktober 2017, 23:08:54 »
Hello,

My perl used to work OK until recently when comparing times, using (sunrise_abs()) >("06:00:00") (not sure about the exact syntax I used)
Then it started to output an error recently (following an update I did on FHEM). 
I then switched to using the time_str2num function, but it won't work - what am I doing wrong - see below ?

2017.10.18 23:01:58 1: PERL WARNING: Use of uninitialized value in numeric gt (>) at (eval 341) line 1.
2017.10.18 23:01:58 3: eval: {if (time_str2num(sunrise_abs()) > time_str2num("06:00:00")) {fhem("set 0_SpotsExt_Entree on-until {sunrise()}" ) } }

Thanks !

Offline amenomade

  • Hero Member
  • *****
  • Beiträge: 2195
Antw:Time comparison
« Antwort #1 am: 18 Oktober 2017, 23:44:53 »
time_str2num needs a full timestamp with date.

Try these in command field in FHEMWEB:
{time_str2num("06:00:00")} => Empty
{time_str2num("2017-01-01 06:00:00")} => 1483246800
FHEM 5.8 Pi 3, EchoDot, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, und HM Komponenten

F:"Schatz? Mach aus bitte"
M: "Alexa? Licht aus"-"Ich bin mir leider nicht sicher"  M:"Alexa? aus Licht"-"Das weiss ich leider nicht" M:"Alexa? Schalte...
F: "Drück mal auf den blöden Knopf!

Offline @lex99

  • New Member
  • *
  • Beiträge: 11
Antw:Time comparison
« Antwort #2 am: 26 November 2017, 13:10:30 »
I finally solved the problem using the isday() function:

*06:00 {if (!(isday())) {fhem("set 0_SpotsExt_Entree on-until {sunrise()}" ) } }
Summary: if it is not daytime (yet) at 06:00, then I put ON the spots until sunrise.

Thanks for your help.

 

decade-submarginal