if(now.minusMinutes(filterPeriod.intValue).isAfter(filterChanged))
Still no joy…
.rules
Time cron "0 0/1 * 1/1 * ? *"
then
val DateTime filterChanged=Filter_DateTime.state
logInfo("Filter", "Val filterChanged has " + filterChanged + " state")
val Number filterPeriod=Filter_Period.state as Number
logInfo("Filter", "Val filterMinutes has " + filterPeriod + " state")
if(now.minusMinutes(filterPeriod.intValue).isAfter(filterChanged)) {
logInfo("Filter", "It works...")
}
end
logged error…
2018-08-28 11:15:00.034 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T00:47:49.987-0500 state
2018-08-28 11:15:00.044 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 6 state
2018-08-28 11:15:00.058 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Show Filter_Changed switch': An error occurred during the script execution: Could not invoke method: org.joda.time.base.AbstractInstant.isAfter(org.joda.time.ReadableInstant) on instance: 2018-08-28T11:09:00.049-05:00
@vzorglub After hours of searching and trial / error… I finally found a solution! Here it is…
Now I am curious… let’s say that I change the now.minusMinutes to now.minusMonths and the period is set to 3 months. I change the filter November 1st. So the next due date would be February 1st. Would this solution still work?
rule "Test | Unhide Filter Changed switch"
when
Time cron "0 0/1 * 1/1 * ? *"
then
val filterChanged=new DateTime((Filter_DateTime.state as DateTimeType).zonedDateTime.toInstant().toEpochMilli)
logInfo("Filter", "Val filterChanged has " + filterChanged + " state")
val Number filterPeriod=Filter_Period.state as Number
logInfo("Filter", "Val filterMinutes has " + filterPeriod + " state")
if(now.minusMinutes(filterPeriod.intValue).isAfter(filterChanged)) {
logInfo("Filter", "It works...showing Change Filter switch")
postUpdate(vFilter_Change_Due,ON)
}else{
logInfo("Filter", "Time isn't up...")
}
end
log
2018-08-28 14:52:17.161 [INFO ] [clipse.smarthome.model.script.Filter] - Contact opened... posting DateTime
2018-08-28 14:53:00.024 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T14:52:17.165-05:00 state
2018-08-28 14:53:00.040 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 12 state
2018-08-28 14:53:00.052 [INFO ] [clipse.smarthome.model.script.Filter] - Time isn't up...
2018-08-28 14:54:00.021 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T14:52:17.165-05:00 state
2018-08-28 14:54:00.046 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 12 state
2018-08-28 14:54:00.056 [INFO ] [clipse.smarthome.model.script.Filter] - Time isn't up...
2018-08-28 14:55:00.039 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T14:52:17.165-05:00 state
2018-08-28 14:55:00.052 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 12 state
2018-08-28 14:55:00.059 [INFO ] [clipse.smarthome.model.script.Filter] - Time isn't up...
2018-08-28 14:56:00.022 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T14:52:17.165-05:00 state
2018-08-28 14:56:00.034 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 12 state
2018-08-28 14:56:00.044 [INFO ] [clipse.smarthome.model.script.Filter] - Time isn't up...
2018-08-28 14:57:00.028 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T14:52:17.165-05:00 state
2018-08-28 14:57:00.048 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 12 state
2018-08-28 14:57:00.059 [INFO ] [clipse.smarthome.model.script.Filter] - Time isn't up...
2018-08-28 14:58:00.023 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T14:52:17.165-05:00 state
2018-08-28 14:58:00.034 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 12 state
2018-08-28 14:58:00.043 [INFO ] [clipse.smarthome.model.script.Filter] - Time isn't up...
2018-08-28 14:59:00.023 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T14:52:17.165-05:00 state
2018-08-28 14:59:00.035 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 12 state
2018-08-28 14:59:00.046 [INFO ] [clipse.smarthome.model.script.Filter] - Time isn't up...
2018-08-28 15:00:00.033 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T14:52:17.165-05:00 state
2018-08-28 15:00:00.044 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 12 state
2018-08-28 15:00:00.062 [INFO ] [clipse.smarthome.model.script.Filter] - Time isn't up...
2018-08-28 15:01:00.030 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T14:52:17.165-05:00 state
2018-08-28 15:01:00.042 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 12 state
2018-08-28 15:01:00.051 [INFO ] [clipse.smarthome.model.script.Filter] - Time isn't up...
2018-08-28 15:02:00.043 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T14:52:17.165-05:00 state
2018-08-28 15:02:00.057 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 12 state
2018-08-28 15:02:00.066 [INFO ] [clipse.smarthome.model.script.Filter] - Time isn't up...
2018-08-28 15:03:00.023 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T14:52:17.165-05:00 state
2018-08-28 15:03:00.038 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 12 state
2018-08-28 15:03:00.049 [INFO ] [clipse.smarthome.model.script.Filter] - Time isn't up...
2018-08-28 15:04:00.032 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T14:52:17.165-05:00 state
2018-08-28 15:04:00.046 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 12 state
2018-08-28 15:04:00.056 [INFO ] [clipse.smarthome.model.script.Filter] - Time isn't up...
2018-08-28 15:05:00.028 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterChanged has 2018-08-28T14:52:17.165-05:00 state
2018-08-28 15:05:00.042 [INFO ] [clipse.smarthome.model.script.Filter] - Val filterMinutes has 12 state
2018-08-28 15:05:00.054 [INFO ] [clipse.smarthome.model.script.Filter] - It works...showing Change Filter switch
If it works with plusMinutes I see no reason why it shouldn’t work with plusMonths
Got ya.
More specifically though, would it work if the year goes to the next? I ask because I’m not sure if the “method” accounts for the change in year. For example… I set the period to 3 months and change the filter on 10/1/2018. So the next change would be 1/1/2019.
Does the plusMonths method look at the DateTime as a whole? Knowing that 1/1/2019 is 3 months after 10/1/2018. Please excuse my ignorance!
Yes it would work the dates are absolute
Ok. I thought it would, but wasn’t sure. Thanks for clarifying and your help, Vincent!
Hey,
Thanks for posting your code! I’m working on doing something similar but using it to build a PID controller. I can’t seem to get my sitemap to work properly. Do you mind sharing your sitemap?
Thanks!
So I got my Sitemap up and going but I cannot seem to figure out how to get it to display the temp and humidity correctly. I get the following error…
I’m running the latest Rasbian and Openhab. I also installed the exec binding and GPIO.
> File "/etc/openhab2/scripts/hum.py", line 10, in <module>
> humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
> File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.4.0-py2.7-linux-armv6l.egg/Adafruit_DHT/common.py", line 94, in read_retry
> File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.4.0-py2.7-linux-armv6l.egg/Adafruit_DHT/common.py", line 81, in read
> File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.4.0-py2.7-linux-armv6l.egg/Adafruit_DHT/Raspberry_Pi_2.py", line 34, in read
> RuntimeError: Error accessing GPIO.
Thanks!