DOH! While writing below I found at least one major error.
var DateTime timeDooropen = now.millis - doorOpen.millis
This makes no sense. millis is a long, not a DateTime and while the Rules DSL does a bunch of stuff for you, it can’t convert a long to a DateTime. You must create a DateTime (i.e. new DateTime(now.millis - doorOpen.millis)
) but that doesn’t really make sense because that will likely give you a DateTime sometime around 00:05 1970 January 1, not “five minutes” which is what you really want.
You need to convert the millis to minutes yourself:
val timeOpenMillis = now.millis - doorOpen.millis
val timeOpenMin = timeOpenMillis / 1000 / 60
I also notice that I don’t think you understand how logInfo works. logInfo and all the other log actions take two Strings, the first is the name of the logger (this appears in the brackets of the log statements). The second String is your actual log statement.
For example, a logInfo("nest", "Setting Nest to " + Presence.state.toString)
when Presence is set to “AWAY” would appear in the logs as:
2016-07-08 10:18:07.070 [INFO ] [org.openhab.model.script.nest ] - Setting Nest to AWAY
There is a limit to the number of characters that gets printed in the brackets so your log statements above will be truncated which I’m sure is not what you want.
My original ideas below.
Things to try:
-
Upgrade to the latest. There probably isn’t something but knowing you are on the newest eliminates hundreds of bugs which may or may not be relevant.
-
Just create a rule with a logInfo in it that fires on any update to Voordeur
rule "Voordeur updated"
when
Item Voordeur received update
then
logInfo("Voordeur", "Received update " + Voordeur.state.toString)
end
If that fires gradually build up from there and experiment.
Configure Voordeur to save everyChange in your .persist file.
rule "Door changed"
when
Item Voordeur changed
then
if(Voordeur.state == 0){
logInfo("Voordeur OPEN: ", Voordeur.state.toString)
sendHttpGetRequest("https://api..."+Voordeur.state.toString)
}
else {
val lastOpen = Voordeur.previousState(true).timestamp.time
val totalTime = now.millis - lastOpen
val totalTimeMin = totalTime / 1000 / 60
logInfo("Voordeur", "Voordeur state DICHT, minutes open: ' + totalTimeMins)
sendHttpGetRequest("https://api..." + totalTimeMin)
}
end