Create a rule in console triggered by Item string value

  • I migrated to Openhabian 3.1 stable version. Java openjdk version 11.0.12
    I have a string Item “registerA” that randomly changes (‘0x00’ through ‘0xff’). This is a hex value but stored as a String.

I would like to run a script that parses the register on every change.

My OH2.5 used the following rules file:
//*************************************************************
rule “Parse 23017A chip”
//*************************************************************
when
Item RegisterA changed
then
do a happy dance and sing a song

This gets imported to OH3.1 and does a song and dance.

However, I tried to convert this to the UI in the OH console and have been unsuccessful on building the trigger. The UI gives the following choices:
core>Item state updated
core>Item state changed
both of these choices fail to trigger.
I am looking for the Item value to be changed and trigger the rule and call the script.
The rule Code looks like this:
triggers:

  • id: “1”
    configuration:
    itemName: RegisterBIn
    type: core.ItemStateChangeTrigger

Thanks in advance for any help on how to trigger off of a change in the string Item.

The rule trigger on item state change is quite robust with the UI rules so the problem lies somewhere with your system or configuration.

Note: Your java version is not recommended, although I don’t think that’s the issue here,as I don’t believe that this is one of the known issues with it.

There’s a lot of information missing here that will help us find the problem for you:

  1. Log files: right now we have to take your word that the problem is that rule doesn’t trigger, but it might help if you show us the OH logs from when your item changes state. Are there errors? Does the rule actually run but fail to do what you are expecting? Have you tried a version of the rule with a simple action to test if the problem is the trigger or your “song and dance”?
  2. The actual rule code: the few trigger lines that you’ve included look fine but there’s much more to the rule than that and we can’t know if the problem is somewhere else if we can’t see it.
  3. The full item definition: I assume you are saying that the rule works when it was a text based rule just not with the UI so the item definition should be correct, but it doesn’t take too much extra effort to give us that too just in case there’s something there.

Lastly, just to make everybody’s life easier, please use code fences when posting any sort of logs or code or it’s just too hard to see what’s going on:

If it were the “do the dance” part that went wrong instead of the triggering, we couldn’t tell from this. You might have a “but only on Sunday” condition etc., it is worth sharing all in case of poorly understood problems.

Thank you for the responses. I have located and fixed the issue but it creates something that you folks that are smarter than me may want to review.

The problem was when I ported the Text Rule into the UI Script, I only removed the When section. At the top was the original “Rule Parse register A” line. When I commented out the original “Rule…” line in the UI Script, the trigger fired as expected.

The thing that is beyond me is why Openhab.log didn’t throw an error on the “Rule…” line. The log file showed nothing from the UI Rule or Script that would indicate that it triggered but failed to run.

After I commented out the original “Rule…” line at the top, the log file showed a few other syntax errors in the UI Script that I will have no trouble fixing. I will mark this issue resolved.

In response to JustinG, my apologies about not using fences, I will follow those guidelines in the future. You also say that my Java version is not recommended but that is what came with the Openhabian image distro (3.1 stable). You may want to pass your comments along to someone on that team.

Thank you again to everyone.