Bayesian Group Suite - Modification Rule [3.2.0;3.4.9)

logo

This rule is one part of a bundle designed to allow the creation, configuration, and utilization of Bayesian probability calculations for some item states using the MainUI. The three parts are:

Credit: This is an OH3-ready implementation of @cweitkamp’s awesome Bayesian aggregation design pattern. So, much of the credit goes to him and you will want to read through his post for a more detailed explanation of the underlying concepts and very clear description and example of probability selection.

This rule is intended for use only with the Bayesian Group Control Widget (see link above). It provides much of the functionality for that widget and will not offer much functionality without it.

Installation and Use

After downloading this rule from the marketplace you only need to create one instance of the rule and there are no required parameters. The rule is usually triggered by an item but that item will be automatically created the first time the rule is run or when the widget is initialized, so there is no need to create the item or input the item name into the rule.

Use without the widget

This rule does have one use indepenent of the widget. If this rule is run manually (press the Run Now button or ctrl + r from the rules detail page) then it will run a check of the metadata for all Bayesian groups and print any errors or warnings to the log as well as adding those errors and warnings to the metadata for each item as necessary.

Language:

  • JSscripting ECMAScript 2021+

Dependencies:

  • JSScripting Add-on

Changelog

Version 0.3

  • Updated addItem for newest js helper library

Version 0.2

  • Fixed template formatting issue

Version 0.1

  • initial release

Resources

https://raw.githubusercontent.com/JustinGeorgi/openhab-public/main/rules/bayesian_sensor_modification.yaml

2 Likes

Hello started playing with this but found got stuck directly with eror[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Rule_BayesianModify' failed: org.graalvm.polyglot.PolyglotException: SyntaxError: <eval>:6:11 Expected ; but found : ││ trueState: 'ON', ││ ^ ││<eval>:8:7 Expected ; but found : ││ prior: 0.5, ││ ^ ││<eval>:10:9 Expected ; but found : ││ sensors: { ││ ^ ││<eval>:13:11 Expected ; but found : ││ pTrue: 0.75, ││ ^ ││<eval>:15:4 Expected eof but found } ││ } ││ ^ │└

Sorry about that, for some reason the template installation was completely mis-formatting any lines that followed comments which started at the beginning of a line. Not sure what was causing that. I’ve reloaded the script to git-hub and tested, it now downloads a properly formatted script file and runs.

There isn’t yet any way to directly update a rule template. You’ll need to go back to the automation settings and uninstall the version you have now and then reinstall. That should get you the version 0.2 which I can verify works. If you also have already installed the Activation Rule, then you’ll need to do the same thing to get the corrected version (it suffered the same issue).

Hi Justin. This is really a very nice work you have done here. I am surprise it didn’t catch more attention.

I’ve been playing with it and after some time spent struggling, i found the problem : there is a compatibility issue with latest stable release of Openhab (3.4) and the modification rule.

Apparently, the parameters of “items.addItem()” have changed and the rule cannot create items anymores. It need an ItemConfig object as parameter

I have been able to work around it by editing code this way :

        items.addItem({
          name: modifyItem,
          type: 'Group',
          label: modifySetting || 'New Bayesian Group'
        });

and later in the same function :

    items.addItem({
          name: 'Rule_BayesianModify',
          type: 'String',
          label: modifySetting || 'Modify Bayesian Item'});

Cheers

1 Like

Thank you, you are correct, I haven’t updated this since the itemConfig object was added to the JSscripting. I’ll try to get to this update when I get back home in a few days.

Hi Justin, should this add-on work in Openhab 4.1. I can’t seem to find the required JSscripting Add-on from the marketplace? After installation its seems to run into syntax errors.

failed: org.graalvm.polyglot.PolyglotException: TypeError: undefined has no such function "toString"

I am, personally, running a version of this system that is now highly modified and I’ve been thinking about how to get that newer version posted, but haven’t gotten to it yet (in large part because I have increased the complexity and modified it to the point where I am not sure it is a useful to a general population).

I have not optimized this code for newer version of the JSScripting add-on or helper library, and it is possible that you are running into a version of the same issue as reported (and corrected) by Guillaume in the post above.

There are only two places in the code the where toString() is used:

//Parse Parameters Passed Via Rule Item
var modifyInput = event.itemState.toString().split(',');

and

if (extraConfigs.length > 0) warnings.push(extraConfigs.toString() + ((extraConfigs.length == 1) ? ' is not a group member item' : ' are not group member items') + ' - configurations will be ignored');

So why you are seeing this error depends on how you are running the rule. Is it being triggered by a changes in the Rule_BayesianModify item or are you triggering it manually via the UI?

In the meantime, I’ve actually got some time later today. Maybe I’ll try and see if I can get the the OH4 version posted in some way.

I have not optimized this code for newer version of the JSScripting add-on or helper library, and it is possible that you are running into a version of the same issue as reported (and corrected) by Guillaume in the post above.

A question about this, should I modify the script as instructed in the earlier posts or was it fixed in the marketplace Add-on ? In this case I created the two missing items manually. So far the widget and calculation rule are working fine, just this modification rule is having issues.

So why you are seeing this error depends on how you are running the rule. Is it being triggered by a changes in the Rule_BayesianModify item or are you triggering it manually via the UI?

I’m seeing this error message when I run the modification rule manually.

I just fixed it (I hope) in the marketplace add-on last night. So you can either apply the change yourself in the version you’ve downloaded or delete that rule and re-download the add-on which should then have the correct version.

I also started work on getting the newer version for OH4 ready and posted, but cleaning it up for other users is taking a little bit of time.

Thanks for the update. I removed the rule and the modification add-on. I then tried to reinstall the modification rule, but it is not found in the add-on store anymore. I can see the activation rule and widget add-on, but not the modification add-on.

All effort on OH4 version is much appreciated, I can already see this as a bit of a game changer as it allows to take away a lot of complexity in rules.

If you are on OH 4 it won’t show up. The [3.2.0;3.4.9) means that by default this rule template will only show up on OH instances between those two versions.

Under Settings → Community Marketplace you can toggle “show unpublished entries” and you’ll see it listed again.

Right, sorry about that, I also added versioning to this rule so that it only appears in the OH3 marketplace, thinking I would get the OH4 version out more quickly than I have. It turns out it needed a few updates for user friendliness. I should be able to finish up the OH4 version and push it out this weekend.

If you really want it right now you can follow the link in the top post and copy paste the script code from that post into a new rule in the ui. But I hope it won’t be long before I get the new one out.

OH4 versions are now in the marketplace and the new system is fully described here: