• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DATE_FORMAT → invalid: trying to compare string variable "21:30:00" to an integer
#1
I'm using pilight to switch my christmas lights. All rueles work, but after a few days (2-3) the sender stops working - after a reboot of the PI everything is fine again for a few days.

Looking at my rules, I found that each rule loke
Code:
"KuecheNacht": {
        "rule": "IF DATE_FORMAT(CurrentDateTime, %H.%M) == 21.30 THEN switch DEVICE Intertechno_0 TO off",
        "active": 1
},
might be executed 60 times between 21:30:00 and 21:30:59. All examples take the second as well, so I thought it might be better to do this.

However, after changing the rule to
Code:
"KuecheNacht": {
        "rule": "IF DATE_FORMAT(CurrentDateTime, %H.%M.%S) == 21.30.00 THEN switch DEVICE Intertechno_0 TO off",
        "active": 1
},
I get the error message
Code:
ERROR: rule #2 invalid: trying to compare string variable "15.18.55" to an integer
ERROR: rule #2 invalid: trying to compare string variable "21.30.00" to an integer

This remains even after trying
Code:
IF DATE_FORMAT(CurrentDateTime, \"%H.%M.%S\") == 21.30.00 THEN
IF DATE_FORMAT(CurrentDateTime, \"%H.%M.%S\") == \"21.30.00\" THEN
IF DATE_FORMAT(CurrentDateTime, %H.%M.%S) == \"21.30.00\" THEN

Any ideas what's wrong with these rules?

pilight-daemon version v7.0-150-g0f27f58
 
Reply
#2
Welcome to the forum.

It would have been nice to post the definition of CurrentDataTime in your config.json as well. I assume it is the devicename for the protocol "datetime".

This behaviour is by design.

Please read the corresponding section about the return value of the function Date_Format in the WIKI.

The Format of the Return value for the Date_Format function differs depending on the input parameters used. Sometimes it is a numeric value, sometimes it is a string value. For the string value you do need to use the IS operator.
 
Reply
#3
Or just transform the whole thing to a valid number.
213000 will work just as fine as 21.30.00
 
Reply
#4
(12-17-2016, 04:47 PM)wo_rasp Wrote: For the string value you do need to use the IS operator.

Replacing == by IS will do the job? I'll try, thank you in advance
 
Reply
#5
Yes, it will.
 
Reply
#6
Indeed. Thank you for your kind help.
 
Reply
#7
You are welcome.
Please note that the DATE_FORMAT function has a known bug as discussed in this forum.
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  invalid: trying to compare string variable "arctech_switch.unit" to an integer diman87 5 2,559 12-19-2017, 11:04 PM
Last Post: diman87
  variable "label" not allowed in rules Niek 4 2,557 09-30-2017, 06:39 PM
Last Post: curlymo
  DATE_FORMAT & DATE_ADD heural 7 2,372 12-22-2016, 10:21 PM
Last Post: curlymo
  using generic_switch as variable / presence detection by "ping" winterfluss 3 1,606 12-11-2016, 10:43 AM
Last Post: Niek
  invalid: trying to compare string variable "datetime.minute" to an integer raj 1 1,800 05-02-2016, 10:50 AM
Last Post: Niek
  ERROR: rule #21 invalid: variable "label" of device "WindMax" cannot be used in even koos147 2 1,837 04-02-2016, 10:24 PM
Last Post: koos147
  rule #1 invalid: trying to compare string variable "datetime.hour" to an integer Michel 2 1,888 12-16-2015, 09:45 PM
Last Post: Michel

Forum Jump:


Browsing: 1 Guest(s)