For my sprinklers I set up several “channels” in openHAB, that are grouped by a group:switch. Works. I’d like to stop watering automatically using a rule. My idea was to define a switch (that is not part of the switch-group) with (time-duration-)mappings as input for the rule:
rule "Gartenbewaesserung 1"
when
Item gBewaesserung changed to ON
then
logInfo("rules", Bewaesserungsdauer.state)
createTimer((now.plusMinutes(Bewaesserungsdauer.state as DecimalType).intValue), [|
gBewaesserung.sendCommand(OFF)
])
end
However, rule doesn’t hit because of:
“Rule ‘Gartenbewaesserung 1’: An error occurred during the script execution: Could not invoke method: org.joda.time.DateTime.plusSeconds(int) on instance: 2018-12-16T23:40:12.182+01:0”
I also tried to set e.g. “30.0” instead of “30” - didn’t work.
Thanks for your quick answer!
Well observed No, it’s just because I changed it meanwhile (to seconds) in order to shorten waiting a bit Later, in productive, it should be minutes. However, result was/is the same.
Unfortunately, your suggestion proposed, leads to the same error-msg. And I really made sure, this element was set.
Log:
2018-12-17 08:28:37.995 [ome.event.ItemCommandEvent] - Item ‘Bewaesserungsdauer’ received command 1
2018-12-17 08:28:41.405 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Gartenbewaesserung 1’: An error occurred during the script execution: Could not invoke method: org.joda.time.DateTime.plusMinutes(int) on instance: 2018-12-17T08:28:41.394+01:00
Almost the same - just put it in for debug-purposes:
2018-12-17 08:18:08.296 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Gartenbewaesserung 1’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null
Anyway, all values are sent to mqtt and using the client, it shows the item is not empty. Tried it several times:
rule "Gartenbewaesserung 1"
when
Item gBewaesserung changed to ON
then
logInfo("rules", Bewaesserungsdauer.state)
val int timerTime = (Bewaesserungsdauer.state as Number).intValue
createTimer((now.plusMinutes(timerTime), [|
gBewaesserung.sendCommand(OFF)
])
end
openhab.log
2018-12-17 11:27:54.145 [ERROR] [ntime.internal.engine.RuleEngineImpl] -
Rule ‘Gartenbewaesserung 1’: An error occurred during the script
execution: Could not invoke method:
org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[])
on instance: null
=> It only produces one error-msg. When I remove logging, null-instance
error-msg is created for createTimer.
events.log
2018-12-17 11:27:53.079 [ome.event.ItemCommandEvent] - Item
‘Bewaesserungsdauer’ received command 1
2018-12-17 11:27:53.775 [vent.ItemStateChangedEvent] - Temperature_ZT
changed from 20.2 to 20.3
2018-12-17 11:27:54.088 [ome.event.ItemCommandEvent] - Item
‘gBewaesserung’ received command ON
2018-12-17 11:27:54.101 [ome.event.ItemCommandEvent] - Item
‘Seitenstreifen’ received command ON
2018-12-17 11:27:54.116 [ome.event.ItemCommandEvent] - Item
‘Hauptflaeche’ received command ON
2018-12-17 11:27:54.127 [ome.event.ItemCommandEvent] - Item
‘Wassersteckdose’ received command ON
2018-12-17 11:27:54.133 [ome.event.ItemCommandEvent] - Item ‘Pumpe’
received command ON
2018-12-17 11:27:54.140 [ome.event.ItemCommandEvent] - Item ‘Vorgarten’
received command ON
2018-12-17 11:27:54.163 [vent.ItemStateChangedEvent] - Seitenstreifen
changed from OFF to ON
2018-12-17 11:27:54.166 [vent.ItemStateChangedEvent] - Hauptflaeche
changed from OFF to ON
2018-12-17 11:27:54.170 [vent.ItemStateChangedEvent] - Wassersteckdose
changed from OFF to ON
2018-12-17 11:27:54.174 [vent.ItemStateChangedEvent] - Pumpe changed
from OFF to ON
2018-12-17 11:27:54.177 [vent.ItemStateChangedEvent] - Vorgarten changed
from OFF to ON
=> After setting duration (was already set, but I wanted to make sure,
it really is) I clicked on the group-button.
When having a closer look at the log, I recognize “Bewaesserungsdauer”
receives command, but doesn’t change state!? Or is this just the way
openHAB does logging?
Commands do not directly change Item states. As a generalism, a command would be sent out via a binding to hardware, and at some later time a response would come back in and update the Item.state.
OH includes an “autoupdate” feature that acts like a binding, and make the state update. It’s enabled by default and looks to be enabled for Bewaesserungsdauer.
With no event.log for state update and no evidence in your rule that state ever gets set - there is certainly something weird about that Item.
I’ll put forward my duplicate theory again - one from .items fle and one from paperUI.
Make yourself a fresh Item and see how that goes. Please give it both “label” and <icon>, or neither, for the sake of looking more sensible
In order to not run into the problem with having defined things twice
(cfg / paperUI), I usually don’t create any items via paperUI
“Usually” means for Jeelink-things I did. However, I added a description
for the number-item and had a look at paperUI’s Items-list. After using
webbrowser’s search-function for “dauer”, it turned out that number-item
is there, but switch-item is not. But maybe this is, because I defined
the switch-item directly in the sitemap?!
Nobody complained to far, but is it correct, to define
“Bewaesserungsdauer” as switch in sitemap (not in items) while a
same-named item of type Number is defined in items?
There could be a hidden character somewhere in the files… It’s happened before.
Delete the item from the item file. Don’t comment it out, delete it.
Save the file. What do the logs say?
Recreate your item, by typing it in. Don’t copy and paste. Save. What do the logs say?
@vzorglub:
Ok, I’ll do so later. Currently, I’m not at home and using my
smartphone’s terminal is a bit crappy for debugging-purposes
@rossko57:
To be honest, I’m still having some problems with sitemap vs. items (not
technically, but understanding). In the past, I just had a pretty short
sitemap-file with one frame that pointed to a group. All the
group-configuration along with every item was done using an item-file.
However, as I learned recently, sitemap is more powerful and if I got it
right, item-file should only carry definitions while sitemap should be
the link for representation <=> items. That said, your sentence
“whatever goes in the sitemap is purely about presentation” made things
a lot clearer to me
@All:
For now: many thanks for the support, which is really appreciated!
There must be a second Constant in the Log-Staetment
The Rule is like @vzorglub posted, including a further closing bracket after (timerTime))
Tested with
now.plusSeconds
rule "Gartenbewaesserung 1"
when
Item gBewaesserung changed to ON
then
logInfo("rules", "test" + Bewaesserungsdauer.state)
val int timerTime = (Bewaesserungsdauer.state as Number).intValue
createTimer((now.plusSeconds(timerTime)), [|
gBewaesserung.sendCommand(OFF)
])
end