openhab1-addons icon indicating copy to clipboard operation
openhab1-addons copied to clipboard

changedSince() gives wrong return values for rrd4j & influx persistence

Open MrMontesa opened this issue 8 years ago • 1 comments

Expected Behavior

I started writing a rule where I needed changedSince function. As it spit wired values I started troubleshooting and hooked up to an existing thread on community forum. https://community.openhab.org/t/changedsince-and-so-on-does-not-work-have-to-use-timers-instead/17975/4 Any persistence addon supporting historic values should be able to be used in changedSince() function. Right now it seems that changedSince only works for switches when persistence engine stores ON/OFF rather than 1/0.

Current Behavior

The changedSince() function always spits false in case rrd4j persistance or influx persistance is used. But works with MySQL persistance.

Possible Solution

Up to the DEVs

Steps to Reproduce (for bugs)

c&p of my test setup to debug this issue: item: Switch test_switch "Test Switch" (gChart, gPersist) rule:

rule "test changedSince in rule"
    when
        Item test_switch changed
    then
        Thread::sleep(500) // give persistence time to populate
        logInfo("test_switch", "changedSince returns  : " + test_switch.changedSince(now.minusMinutes(1), "rrd4j"))
        logInfo("test_switch", "historicState returns : " + test_switch.historicState(now.minusMinutes(1), "rrd4j"))
        logInfo("test_switch", "lastUpdate returns    : " + test_switch.lastUpdate)
        if(test_switch.changedSince(now.minusMinutes(1), "rrd4j")){
            logInfo("test_switch", "Function returns "  + test_switch.changedSince(now.minusMinutes(1), "rrd4j") + " thus last change SMALLER 60 seconds")
        } else {
            logInfo("test_switch", "Function returns "  + test_switch.changedSince(now.minusMinutes(1), "rrd4j") + " thus last change GREATER 60 seconds")
        }
    end

Log snippets: OK with MySQL:

2017-01-03 14:51:53 - test_switch received command OFF
2017-01-03 14:51:54.228 [INFO ] [enhab.model.script.test_switch] - changedSince returns  : true
2017-01-03 14:51:54.238 [INFO ] [enhab.model.script.test_switch] - historicState returns : 03.01.2017 14:49:41: test_switch -> OFF
2017-01-03 14:51:54.242 [INFO ] [enhab.model.script.test_switch] - lastUpdate returns    : Tue Jan 03 14:51:53 CET 2017
2017-01-03 14:51:54.259 [INFO ] [enhab.model.script.test_switch] - Function returns true thus last change SMALLER 60 seconds
2017-01-03 14:52:59 - test_switch received command ON
2017-01-03 14:53:00.071 [INFO ] [enhab.model.script.test_switch] - changedSince returns  : false
2017-01-03 14:53:00.304 [INFO ] [enhab.model.script.test_switch] - historicState returns : 03.01.2017 14:51:53: test_switch -> OFF
2017-01-03 14:53:00.398 [INFO ] [enhab.model.script.test_switch] - lastUpdate returns    : Tue Jan 03 14:52:59 CET 2017
2017-01-03 14:53:00.588 [INFO ] [enhab.model.script.test_switch] - Function returns false thus last change GREATER 60 seconds
2017-01-03 14:54:34 - test_switch received command OFF
2017-01-03 14:54:34.701 [INFO ] [enhab.model.script.test_switch] - changedSince returns  : false
2017-01-03 14:54:34.714 [INFO ] [enhab.model.script.test_switch] - historicState returns : 03.01.2017 14:52:59: test_switch -> ON
2017-01-03 14:54:34.718 [INFO ] [enhab.model.script.test_switch] - lastUpdate returns    : Tue Jan 03 14:54:34 CET 2017
2017-01-03 14:54:34.741 [INFO ] [enhab.model.script.test_switch] - Function returns false thus last change GREATER 60 seconds

Bad with Influx:

/var/log/openhab$ tail -f openhab.log events.log |grep test_switch
2017-01-04 13:57:22 - test_switch received command ON
2017-01-04 13:57:23.370 [INFO ] [enhab.model.script.test_switch] - changedSince returns  : false
2017-01-04 13:57:23.506 [INFO ] [enhab.model.script.test_switch] - historicState returns : null
2017-01-04 13:57:23.585 [INFO ] [enhab.model.script.test_switch] - lastUpdate returns    : Wed Jan 04 13:57:22 CET 2017
2017-01-04 13:57:23.800 [INFO ] [enhab.model.script.test_switch] - Function returns false thus last change GREATER 60 seconds
2017-01-04 13:57:30 - test_switch received command OFF
2017-01-04 13:57:30.941 [INFO ] [enhab.model.script.test_switch] - changedSince returns  : false
2017-01-04 13:57:30.944 [INFO ] [enhab.model.script.test_switch] - historicState returns : null
2017-01-04 13:57:30.946 [INFO ] [enhab.model.script.test_switch] - lastUpdate returns    : Wed Jan 04 13:57:30 CET 2017
2017-01-04 13:57:30.954 [INFO ] [enhab.model.script.test_switch] - Function returns false thus last change GREATER 60 seconds
2017-01-04 13:57:43 - test_switch received command ON
2017-01-04 13:57:44.452 [INFO ] [enhab.model.script.test_switch] - changedSince returns  : false
2017-01-04 13:57:44.455 [INFO ] [enhab.model.script.test_switch] - historicState returns : null
2017-01-04 13:57:44.456 [INFO ] [enhab.model.script.test_switch] - lastUpdate returns    : Wed Jan 04 13:57:43 CET 2017
2017-01-04 13:57:44.462 [INFO ] [enhab.model.script.test_switch] - Function returns false thus last change GREATER 60 seconds
2017-01-04 13:58:19 - test_switch received command OFF
2017-01-04 13:58:20.099 [INFO ] [enhab.model.script.test_switch] - changedSince returns  : false
2017-01-04 13:58:20.103 [INFO ] [enhab.model.script.test_switch] - historicState returns : null
2017-01-04 13:58:20.105 [INFO ] [enhab.model.script.test_switch] - lastUpdate returns    : Wed Jan 04 13:58:19 CET 2017
2017-01-04 13:58:20.112 [INFO ] [enhab.model.script.test_switch] - Function returns false thus last change GREATER 60 seconds

Data stored: MySQL:

mysql> select ItemId from Items where ItemName = 'test_switch';
+--------+
| ItemId |
+--------+
| 39 |
+--------+
mysql> select * from Item39;
+---------------------+-------+
| Time | Value |
+---------------------+-------+
....
| 2017-01-03 15:00:42 | OFF |
| 2017-01-04 13:57:22 | ON |
| 2017-01-04 13:57:30 | OFF |
| 2017-01-04 13:57:43 | ON |
| 2017-01-04 13:58:19 | OFF |
| 2017-01-04 13:59:28 | ON |
| 2017-01-04 14:03:35 | OFF |
+---------------------+-------+

Influx:

> select * from test_switch where time > 1483534699589000000
name: test_switch
time                    value
----                    -----
1483534740002000000     0
1483534740003000000     0
1483534768471000000     1
1483534768472000000     1
1483534800002000000     1
1483534800003000000     1
1483534860002000000     1
1483534920002000000     1
1483534920003000000     1
1483534980003000000     1
1483534980004000000     1
1483535015087000000     0

Context

Your Environment

  • openhab & bindings 1.8.3
  • influx.1.9.0.SNAPSHOT
  • java version "1.8.0_111"
  • Debian GNU/Linux 8

Any questions, let me know.

MrMontesa avatar Jan 04 '17 13:01 MrMontesa

I'm experiencing the same error. But since jan 2017 has nobody done something (even not a little comment), so I think nobody uses this function with a switch and influxdb

ljsquare avatar Oct 31 '19 15:10 ljsquare