Oh2 to oh3 rules file help

Hey all,

decided to change one of my OH2 setups to OH3. (didnt go well. SD card stopped doing writes)
having issues with the Rules file though

rule "polo location"
    Item mqtt_topic_36c23abd20_3e2f966e_polo received update
    val split = mqtt_topic_36c23abd20_3e2f966e_polo.state.toString.split(",")

when i look at the rule in the GUI it looks like this

// Triggers:
// - When mqtt_topic_36c23abd20_3e2f966e_polo was updated

// context: car-1
val split = mqtt_topic_36c23abd20_3e2f966e_polo.state.toString.split(",")

i have no idea why the Triggers is committed out though. any ideas? latest version of openhabian on rpi3

What’s the problem?


Never see the rule trigger.
The 2 Items polo_lat and polo_lon never receive updates from the rule. There’s no error’s in the log’s when I add the rule or when the rule should trigger.

Did you add a trigger to the “When” section of the rule? That’s how a UI rule gets triggered, and I assume that’s the reason it’s commented out in the rule you pasted from your .rules file.

FYI, you don’t have to move your rules to the UI. You can just leave them in .rules files and they’ll continue to work, so long as you update them for any breaking changes. Then you can port them over at your leisure. That’s how I’m approaching OH3.

Some things to consider:

  • As mentioned, in the UI the rule triggers are separate from the “code”.

  • Based on the name of your Item it looks a whole lot like you were using simple mode to create your Items. OH 3 does not have simple mode. Depending on how you upgraded I wouldn’t necessarily expect those Items to have transferred over. Especially if you recreated your Things, they are likely to have a different set of Channel IDs than what you had before so, if this Item did get transferred over, it might not be linked to the right Channel any more.

  • You probably don’t even need this rule. You can crate a Location Channel linked to a Location Item to store the lat/lon.

@rpwong the rule is still in the rules folder.(1st post shows the rule file) it just shows up in the rules UI. how do i add a Trigger to a rules file in the UI? when i click on it in the UI it just shows me the page with the trigger committed out(also shown in the 1st post)

@rlkoshak the items where made via items file.

Number polo_lat
Number polo_lon

storing them this way for grafana map addon (TrackMap) via influxdb.

i have updated the MQTT item inside the rule to match what OH3 called it.

so fair all i have done is copy the rules file and items file from OH2 and put them in there folders in OH3 and updated the MQTT item to match what OH3 called the item.

the MQTT item is updating in logs and in the overview layout page.

just noticed at bottom of UI page i can make it run??
it shows a error in the log when i do this

[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'car-1' failed: The name 'mqtt_topic_36c23abd20_3e2f966e_polo' cannot be resolved to an item or type; line 5, column 17, length 35 in car

the API also says it doesnt exist
{“error”:{“message”:“Item mqtt_topic_36c23abd20_3e2f966e_polo does not exist!”,“http-code”:404}}

yet here is the item…

just looked up Polo in the api items GET /items
there was no mqtt_topic_36c23abd20_3e2f966e_polo but there was Polo. (the name i gave the thing/item) have updated the rule to this and is now working

Sorry, it sounded like you were trying to copy/paste your rules from your files into the GUI, which some people have been doing. I never look at any of my rules in the UI, as there’s no need to do that. So, don’t worry about the triggers being commented out…that’s normal.

I was just about to ask if your item name had changed in the transition. Glad you got it working.

All good.

thanks for the help.

much appreciated!

Need to learn there’s a difference between item and things now without simple linking