PWM + JS rule issue

, ,
  • Platform information:
    • Hardware: x86
    • OS: proxomox+debian
    • openHAB version: 4.2.1

Faced an unclear behavior of the PWM algorithm in JS rules; regardless of the minimum-value constraints, the result is always in the 0-100 range and ignore min max limitation (50-100 in example below). I looked at the openhab-js trigger code, and it seems like all parameters are being passed correctly. Am I misunderstanding the PWM logic somehow?

rules.JSRule({
    name: 'VentilationBedRooms PWM rule',
    triggers: [
        triggers.PWMTrigger('VentilationBedRooms_PWM', 30*60,50,100)
    ],
    execute: (event) => {
        items.VentilationBedRooms_DumperSwitch.sendCommand(event.receivedCommand);
    }
});

rules.JSRule({
  name: 'VentilationBedRooms_CO PID rule',
  triggers: [
    triggers.PIDTrigger(
      'VentilationBedRooms_CO', 
      'VentilationBedRooms_COSetpoint', 
      0.5,
      0,
      0,
      1,
      5*60*1000,// loopTime
      undefined, 
      1, 
      100
    )
  ],
  execute: (event) => {
    let pwm = 50 + -1* parseFloat(event.receivedCommand);
    if (pwm > 100) pwm = 100;

    items.VentilationBedRooms_PWM.sendCommand(pwm < 1 ? 1 : Math.round(pwm));
  },
  tags: ['Ventilation']
});

Looking at the docs for the PWM add-on, you don’t seem to have the right arguments. Unfortunately there isn’t an example in the docs to confirm so lets go look at the code in openhab-js: triggers - Documentation

It’s interesting that the properties do not line up between the add-on docs and the JS implementation; we’re missing the two boolean flags equateMinToZero and equateMaxToHundred. The docs for the PWM add-on indicate that equateMinToZero defaults to false but equateMaxToHundred defaults to true.

My understanding of the properties you’ve passed, is the VentilationBedRooms_PWM should be updated with a value between 50% and 100% and the switch should not be switched ON for more than half an hour. The latter appears to be happening but the former is not. But I can’t say why.

I’m not sure I’ve shed any light on what we are seeing here but maybe there are enough clues to continue exploration and figure out what is going on. Maybe try creating the trigger in a UI rule and compare the code generated (click the code tab) and behaviors to what your rule does.

The idea behind my rule is that the switch should turn on in cycles of 30 minutes, within a range of 15 to 30 minutes, but in reality, I see a range from 0 to 30min (it seems like those constraints are being ignored). Regarding the two additional flags not present in JS, as far as I understand, they only affect the values strictly 0 and strictly 100. To eliminate their impact, I limited the PWM value from below to 1. I tried comparing the code with the UI, but so far, I haven’t come up with any ideas.

So, does it look like a bug? Does it need to be additionally documented as a bug report?

No one else has chimed in so I guess soi. The missing boolean flags needs to be implemented by openhab-js but the erroneous behavior needs to be handled by the PWM add-on so there might need to be two issues.