New rule engine startup - rule initialisation

Hello, the problem still exists on my Openhab.
With the OH2 2.3 Release the Script is not working, because the errormessage above.
Any Idea how to fix it ?

Thank you for your help

All brackets and the end are there, you just need to scroll down :wink:

Its a warning, so it might not be the problem. Are you sure there is no error message?

I get this error:
JsonPath expressions with more than one result are not allowed, please adapt your selector. Result: [ā€œ64c95514-6b13-44f9-88e0-d7a4ee5bfbb5ā€,ā€œ5b9aa4ca-4e31-495b-8e33-6e16da2aa796ā€,ā€œ1efc53b3-8865-4d7b-a453-9bd9f046b2daā€,ā€œ9b770b8e-da44-4bba-a161-df6e93f10f84ā€,ā€œc8f513f6-23aa-4e59-93bd-f251491bfe2aā€,ā€œa1ab8298-89c4-4385-9e44-b8939a1bd7e9ā€]

1 Like

Well it is the same as mine, but i am pretty shure, that it says Warning in front of it, like in my log.

1 Like

same issue on fully stable release updated system for me :

[WARN ] [ternal.JSonPathTransformationService] - JsonPath expressions with more than one result are not allowed, please adapt your selector. Result: ["ae1ddc92-c44d-4c8a-845d-d222fc15cc16","18d4d1db-08ec-47e4-bb7f-59c131a6e70b","fcd460b9-b3d6-4f5b-b302-f4ab3c657fd1","5328b8ef-3292-456d-a2eb-eda38f32651f","5a1e9fa7-0a4f-4607-b8cd-9e8f4a7a9bb5","0e1e1726-fe25-499a-8265-c91fa1c83025","8410fe2c-8eeb-4cae-be65-e0bdd39c84cb","2f5460d3-d2db-42e6-b660-2bb1c2cfae41","6d149182-c9b7-45d1-b2ad-bc380d873baa","59856c87-e815-4e7f-8d24-ae24aea50320","0b211638-5cc5-4793-a0c1-9b6a6d24ffa6","c59f260c-11b1-4ea9-89d9-2c5537967986","91faf007-bca9-4cdb-8bb8-ab53a9809118","0c545fc9-5809-4c3f-99f8-d75d92297d63"]

no other error

@epicurean and @Bernard_Laurenzo_Kem, please use code fences when pasting definitions of things, items or rules, as well as logs. With pasted text inside code fences, it is much easier to read!

How to use code fences

1 Like

The next gen rule engine has had a lot of updates since 2.3. The issue reported in the OP may no longer be an issue on a newer build. It seems to not effect everyone all the time. Here is an open ESH issue for what is reported in the OPā€¦

Also, this would cause a problem with your use of the JSONPATH transformā€¦

I suggest you setup JSR223-Jython, which includes a startup delay script to prevent the loading of rules until everything has been loaded. The links I provided go to a branch that has not been released yet, but I hope to have the PR merged this weekend.

1 Like

So i have made some modifications to the above script to include a startup delay of 60 seconds and added one more . to the jsonpath transform and it seems to be working for me now.

rule "InitializeExperimentalRules"
  when
    System started
then
createTimer(now.plusSeconds(60)) [|
  // Get all JSON based rules
  var String jsonRules = sendHttpGetRequest("http://127.0.0.1:8080/rest/rules")
  var String jsonuids = transform("JSONPATH", "$...uid", jsonRules)
  var String uidsAsString = jsonuids.substring(1, jsonuids.length - 1)
  // Split rules uids
  var uidsArray = uidsAsString.split(",")
  // Update each rule
  for (var i = 0; i < uidsArray.length; i++) {
  // Prepare API URL for config update
  // Check if the current chunk of the split string contains "uid" (this is dirty, but works)
  if(uidsArray.get(i).contains("uid")){
    //get the substring which represents the uid string e.g. Rule_1
    var String uid = uidsArray.get(i).substring(7, uidsArray.get(i).length - 1)
	//Build the URL for updating the Rule
    var String ruleConfigUrl = "http://127.0.0.1:8080/rest/rules/" + uid + "/config" 
    //Log the Rule update with the UID
    logInfo("INFO","Rule "+uid+" updated: "+ruleConfigUrl)
    //send the http put request to update the rule
    sendHttpPutRequest(ruleConfigUrl, "application/json", "{}")
    logInfo("INFO","10")
  }
  }
  ]
  end

@scottk cleaned up my newbie postā€¦ thank you

1 Like

Good deal! Iā€™m not trying to beat up on anyone, hope you didnā€™t take my post the wrong way. It just helps everyone, those who respond with help and those who experience the same problems you did.

Glad to hear you seem to have solved your issue.

:+1: thanks for the solution!

Just be aware that this will no longer work the next time you upgrade due to the change detailed in the post I linked to.

Thank you will look into it when i upgrade

Is there any new work-around to initialize the rules on start up? Iā€™m using version 2.4 and with the work-around from this thread 90% of the rules are initialized on start up, but a couple of them do not work anymore neither if I try to initialize them manuallyā€¦
Iā€™m not a big expert so maybe Iā€™m messing with somethingā€¦

Which type of rule (DSL, Paper UI, Jython, JS, etc.)? If youā€™re initializing them, then probably Paper UI. And which workaround helped? :slight_smile:

TMK, there hasnā€™t been any change since 2.4 in this area. Post the rules that arenā€™t working, and people in the forum may be able to help sort them out.

Sorry, Paper UI
Iā€™m using Rule Engine (Experimental) misc-ruleengine - 2.4.0
As work-around Iā€™m using the script ā€œInitializeExperimentalRulesā€, the fact is that the two experimental rules that arenā€™t working now, were working before.

So these rules will not initialize manually? Do you see any errors logged when you try? You can find the JSON for these rules in your jsondb folderā€¦ maybe posting them will help.

Iā€™m looking right now in the JSON file, I just realized that old experimental rules are still in this fileā€¦

1 Like
"a5d7d9c5-72d8-41a5-af8b-b8c986409756": {
"class": "org.eclipse.smarthome.automation.dto.RuleDTO",
"value": {
  "triggers": [
    {
      "id": "1",
      "label": "an item state is updated",
      "description": "This triggers the rule if an item state is updated (even if it does not change).",
      "configuration": {
        "itemName": "Kitchen_Temperature"
      },
      "type": "core.ItemStateUpdateTrigger"
    }
  ],
  "conditions": [
    {
      "inputs": {},
      "id": "3",
      "label": "an item has a given state",
      "description": "Compares the item state with the given value",
      "configuration": {
        "itemName": "AqaraWindowKitchen",
        "state": "CLOSED",
        "operator": "\u003d"
      },
      "type": "core.ItemStateCondition"
    },
    {
      "inputs": {},
      "id": "4",
      "label": "an item has a given state",
      "description": "Compares the item state with the given value",
      "configuration": {
        "itemName": "Kitchen_Temperature",
        "state": "19",
        "operator": "\u003c\u003d"
      },
      "type": "core.ItemStateCondition"
    }
  ],
  "actions": [
    {
      "inputs": {},
      "id": "2",
      "label": "send a command",
      "description": "Sends a command to a specified item.",
      "configuration": {
        "itemName": "Heating",
        "command": "ON"
      },
      "type": "core.ItemCommandAction"
    }
  ],
  "configuration": {},
  "configDescriptions": [],
  "uid": "a5d7d9c5-72d8-41a5-af8b-b8c986409756",
  "name": "Temperature \u003c19ƂĀ°C",
  "tags": [],
  "visibility": "VISIBLE",
  "description": "Window closed"
}
  },