Bayesian Sensors - Activation Rule [4.0.0;5.0.0)

logo

This is the required rule the use of bayesian sensor groups in OH4. For a complete description of the installation, and use of this rule please see the main discussion:

Language:

  • JSscripting ECMAScript 2021+

Dependencies:

  • JSScripting Add-on

Changelog

Version 0.1

  • initial release

Resources

https://raw.githubusercontent.com/JustinGeorgi/oh-public/main/oh4/bayesian/bayesian_sensor_activation.yaml

Hi @JustinG,

Just wanted to say thank you for all of this (tons) of work on the Bayesian Sensors setup you have. I’ve been wanting to implement it for some time, but have just gotten through enough prep and have a little time to start.

I believe there may be an error in the Activation Rule, however. I set an observation with a neq test, and OH threw an error:

[ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'bayesian_sensors' failed: org.graalvm.polyglot.PolyglotException: ReferenceError: "it" is not defined

Separately, it threw an error around sL in the same object definition when I changed “it” to “sItem” (just guessing there was a change from an earlier rule version. The object defined is:

        var sensorTest = {
          'gt': (sItem, test) => { return items[sItem].numericState > test[sItem].testState },
          'lt': (sItem, test) => { return items[sItem].numericState < test[sItem].testState },
          'bt': (sItem, test) => { return (test[sItem].testState[0] > items[sItem].numericState) && (items[sItem].numericState > test[sItem].testState[1]) },
          'neq': (sItem, test) => { return items[it].state != sL[it].testState },
          'list': (sItem, test) => { return test[sItem].testState.contains(items[sItem].state) },
          'eq': (sItem, test) => { return items[sItem].state == test[sItem].testState }
        }

Should the neq test be:

          'neq': (sItem, test) => { return items[sItem].state != test[sItem].testState },

instead, as in the inverse ‘eq’ definition? I figure it’s just a typo, but in case I’m missing something (which I well could be!).

Again, thanks for all of the work on this. I’m still getting my feet wet with it, but I believe it’s going to be a really big improvement to my system (which is becoming unwieldy in it’s current state).

Yep, looks like you’re correct both on the error and the fix. I’m traveling right now, but I’ll fix it up when I get a chance.

Great. I’ll make the change in the rule short term. Again, thanks for all of the work on this! It’s really coming along well. Really great work!