JS-Rule with PWM Trigger failed execution

Hi guys,

I am trying to setup a test rule (JSRule) which is triggered by PWMTrigger. When the rule gets loaded the RuleEngine throws an error:

2023-01-18 18:49:42.567 [INFO ] [.openhab.automation.openhab-js.rules] - Adding rule: Heating Test - PWM-Controller
2023-01-18 18:49:42.571 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule ‘Heating-Test---PWM-Controller-f439b3e2-df75-4810-ac38-7297e5b5098a' with status 'INITIALIZING'

The rule:

rules.JSRule({
  name: "Heating Test - PWM-Controller",
  triggers: [triggers.PWMTrigger(
    /* DutyCyc Item     */  "HC_Test_DutyCyc",
    /* interval in s    */  10,
    /* minDutyCyc       */  10,
    /* maxDutyCyc       */  90,
    /* deadManSwt in ms */  600000
  )],
  execute: (event) => {
    logger.info("PWM-Trigger: " + event.receivedCommand);
  }
});

Platform information:

  • Hardware: Pi4 8Gb
  • openHAB version: 3.4

Does anybody have any idea what’s going wrong here?

Thank you in advance!

Regards,
Matthias

I doubt this will work. PWMTrigger is not a core trigger. It requires installation of an add-on. The way JSRule works is that a JavaScript proxy for the “real” trigger Classes is used to build the rule. There is no such proxy for PWMTrigger, which is not surprising since only the triggers that come with OH by default are supported.

You can get around this by using the UI. In that case the trigger is defined outside of JS Scripting so that should work the same as it would for any other rule.

You can look at the openhab-js triggers.js file to see how the triggers are imported and defined and do the same thing in your code to import and use PWMTrigger (assuming it works the same way).

You should also file an issue on openhab-js to add this trigger and come up with a way to add and/or make available new trigger types provided by add-ons in the future too.

ok… that’s bad news. I am wondering because the PIDController trigger works. I have both add-ons (PID Controller + PWM Automation) installed. I will give it a try to get the trigger working.

I discovered one difference. In the documentation (https://www.openhab.org/addons/automation/pwm/) there is one parameter “equateMinToZero” which is missing in the JSRule triggers. Could this may cause the issue?

It makes sense to raise a ticket that PWM trigger will work also within the js-scripting automation. One stupid question: How do I raise a ticket here? I haven’t done this before :).

Regards,
Matthias

You’ll file it on the openhab-js repo.

Ok thanks I’ll try my best!

Are you sure that this is a problem of openhab-js and not from the PWM Add-On itself? As mentioned above the PID Trigger works well and it’s implemented the same way in triggers.js file.

Because it didn’t work when implemented the same way, there is likely something different that needs to happen to access these. It will probably be a similar situation as with Thing actions compared to the core actions. They are accessed in different ways.

Ok understood.

I’ll tried to setup the PWM trigger within the UI-Rules. Here I’ve got a similar error message!

2023-01-20 17:47:47.646 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule ‘166472cb32' with status 'INITIALIZING'

Hmmm, there might be something else wrong then. The "status INITIALIZING " was always mysterious but I thought it was a red herring (meaning a misleading clue). Perhaps something else more fundamental is going on.

In the UI, the triggers are implemented outside of and independently of JS Scripting.

Maybe the issue needs to be on the openhab-addons repo for the PWM add-on itself.