New rule engine startup - rule initialisation

rules
paperui
ere
Tags: #<Tag:0x00007fe05759b9f8> #<Tag:0x00007fe054f4fe20> #<Tag:0x00007fe054f4fce0>

(wildzone) #22

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


(wildzone) #23

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


(J Wee) #24

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”]


(xasz) #25

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


(Bernard “Laurenzo” Kemp) #26

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


(Scott Karns) #27

@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


(Scott Rushworth) #28

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.


(Bernard “Laurenzo” Kemp) #29

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

(Bernard “Laurenzo” Kemp) #30

@scottk cleaned up my newbie post… thank you


(Scott Karns) #31

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.


(wildzone) #32

:+1: thanks for the solution!


(Scott Rushworth) #33

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.


(Bernard “Laurenzo” Kemp) #34

Thank you will look into it when i upgrade


(Mr Cupola) #35

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…


(Scott Rushworth) #36

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.


(Mr Cupola) #37

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.


(Scott Rushworth) #38

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.


(Mr Cupola) #39

I’m looking right now in the JSON file, I just realized that old experimental rules are still in this file…


(Mr Cupola) #40
"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"
}
  },

(Scott Rushworth) #41

When posting something like this, or a log, it is very helpful to use code fences so that the formatting is preserved… and readable. :slight_smile:

Everything looks OK. The only thing I could not recreate is the name of your rule. I’m not sure if the forum did something odd without formatting, or if there might be a strange character. When I use the degree symbol in a rule name, it shows as a degree symbol in the JSON, and the rule still works. If that’s not it, have you tried recreating the rule, and do you have the same issue?