arjan-io
(Arjan)
September 3, 2021, 6:50am
1
Hi all,
I have a rule that does a get-request if a specific item state is changed to on. This used to work OK but since I needed to restart OH it comes up with this error in the log:
2021-09-03 07:47:44.952 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule 'e6c6d10d7b': Fail to execute action: 4
Sometimes the rules does work and executes (I can see this by the result of the get-request that is indeed not fed back to OH). But sometimes the rule does not execute and indeed fails. Same error in both cases. Does anybody has a clue please? Logs, as you can see, are pretty minimal.
Rule itself:
triggers:
- id: "1"
configuration:
itemName: network_TF_keuken
state: ON
type: core.ItemStateChangeTrigger
- id: "2"
configuration:
itemName: network_TF_sk4
state: ON
type: core.ItemStateChangeTrigger
- id: "3"
configuration:
itemName: network_TF_woonkamer
state: ON
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "4"
configuration:
type: application/javascript
script: >-
var logger =
Java.type("org.slf4j.LoggerFactory").getLogger("org.openhab.model.script.Rules.Network");
scriptExtension.importPreset("default");
var HttpUtil = Java.type("org.openhab.core.io.net.http.HttpUtil");
var tf = event.itemName.split('_')[event.itemName.split('_').length - 1];
logger.info("var tf = " + tf);
HttpUtil.executeUrl("GET", "http://192.168.10.28/led.php?kamer=" + tf, 1);
type: script.ScriptAction
rlkoshak
(Rich Koshak)
September 3, 2021, 3:19pm
2
So add some more so you can determine which line in that rule it is failing on. Is there a reason you are not using sendHttpGetRequest?
arjan-io
(Arjan)
September 3, 2021, 5:05pm
3
I found my way via google. The sendHttpGetRequest wasn’t working for me but that is most likely due to my coding skills.
I’ll add more info-log-lines but up until I set var tf
this rule looks the same as others so it can’t be going wrong in many ways
arjan-io
(Arjan)
September 3, 2021, 8:36pm
4
Rule:
var logger =
Java.type("org.slf4j.LoggerFactory").getLogger("org.openhab.model.script.Rules.Network");
scriptExtension.importPreset("default");
logger.info("Part 1");
var HttpUtil = Java.type("org.openhab.core.io.net.http.HttpUtil");
logger.info("Part 2");
var tf = event.itemName.split('_')[event.itemName.split('_').length - 1];
logger.info("Part 3");
logger.info("var tf = " + tf);
logger.info("Part 4");
HttpUtil.executeUrl("GET", "http://192.168.10.28/led.php?kamer=" + tf, 1);
logger.info("Part 5");
Log:
2021-09-03 22:34:09.624 [INFO ] [g.openhab.model.script.Rules.Network] - Part 1
2021-09-03 22:34:09.631 [INFO ] [g.openhab.model.script.Rules.Network] - Part 2
2021-09-03 22:34:09.644 [INFO ] [g.openhab.model.script.Rules.Network] - Part 3
2021-09-03 22:34:09.646 [INFO ] [g.openhab.model.script.Rules.Network] - var tf = sk4
2021-09-03 22:34:09.647 [INFO ] [g.openhab.model.script.Rules.Network] - Part 4
2021-09-03 22:34:09.655 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule 'e6c6d10d7b': Fail to execute action: 4
So it fails at HttpUtil.executeUrl("GET", "http://192.168.10.28/led.php?kamer=" + tf, 1);
but the request does get sent…
It was this topic where I got my script from.
rossko57
(Rossko57)
September 3, 2021, 11:40pm
5
It might tell you why if you listen to it
var results = HttpUtil.executeUrl("GET", "http ...
logger.info("results " + results);
Your timeout doesn’t seem very generous, 1mS?
arjan-io
(Arjan)
September 4, 2021, 7:25am
6
Thanks for the hint. Hope with the increase in timeout it will get past your suggested approach because now it does not execute anything after that specific line.
I do/did not need the result, just the command send to the other device so I thought ‘why wait for something I don’t want the reply from?’
We’ll see
arjan-io
(Arjan)
September 5, 2021, 9:13pm
7
Unfortunately it doesn’t. It stops executing at the same line, although that line is now preceded by var results =
.
rossko57
(Rossko57)
September 5, 2021, 10:04pm
8
Worth a try. Maybe if you use the sendHttpGetRequest() Action provided for use in rules, as hinted before, it might be more forthcoming.
javascript usage example
arjan-io
(Arjan)
September 6, 2021, 11:46am
9
It is and works. So all of you thanks for the tips. I do wonder though why that other script did fail. Or sort of failed. The http-get-request was sent but then it still produced an error.