ojek
(Maciek)
October 29, 2018, 5:24pm
1
Hey,
I’m trying to assert that my heating system is not triggered more often than every 2 minutes. My rule works perfectly fine, only exception is that Desired_Temp_State_Bedroom.changedSince(now.minusMinutes(2), "influxdb")
does not do anything. I tried with second parameter, without it, I tried == false
, == true
, but it doesn’t matter. Openhab just ignores it, as if it didn’t exist in there in the first place. What’s wrong with it?
rule "Bedroom_Temperature"
when
Item TempHumidSensor_Bedroom_Main_Temperature received update or
Item Desired_Temp_Bedroom received update
then
val Number BedroomTemp = TempHumidSensor_Bedroom_Main_Temperature.averageSince(now.minusMinutes(10))
if ( BedroomTemp < Desired_Temp_Bedroom.state && Desired_Temp_State_Bedroom.changedSince(now.minusMinutes(2), "influxdb") )
{
Desired_Temp_State_Bedroom.sendCommand("ON")
Sonoff_S20_Bedroom_Main.sendCommand("ON")
}
if (BedroomTemp >= Desired_Temp_Bedroom.state)
{
Desired_Temp_State_Bedroom.sendCommand("OFF")
Sonoff_S20_Bedroom_Main.sendCommand("OFF")
}
end
item:
Switch Desired_Temp_State_Bedroom (gPersistable_everyMinute)
influxdb.persist:
Strategies {
everyMinute : "0 * * * * ?"
everyHour : "0 0 * * * ?"
everyDay : "0 0 0 * * ?"
}
Items {
gPersistable_restore* : strategy = restoreOnStartup
gPersistable_everyChange* : strategy = everyChange
gPersistable_everyMinute* : strategy = everyMinute
}
rossko57
(Rossko57)
October 29, 2018, 8:27pm
2
There have been a few posts over time saying that changedSince does not work with influxdb, example
Sorry for the monologue here. I just migrated to influx.persistance since I want to do some nice graphing with Grafana and the problem is back again. What I just saw is that RRD4J and Influx store 0 & 1 in the database while MySQL stores ON & OFF. Might that be a the reason for invalid changedSince return values?
here’s some output I gathered with InfluxDB
> select * from test_switch where time > 1483534699589000000
name: test_switch
time value
---- -----
…
There is an open issue
opened 01:38PM - 04 Jan 17 UTC
## Expected Behavior
I started writing a rule where I needed changedSince funct… ion. 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.