Skip to content

Improve documentation wrt to support for checking receivedCommand in Rule Builder #400

@jlaur

Description

@jlaur

I just uncovered a bug in one of my rules that I migrated from DSL to JavaScript some time ago.

The setup is something like this:

Item:

Switch TestTimer_Switch { expire="15m,command=OFF" }

The DSL rule:

rule "Test Timer DSL"
when
    Item TestTimer_Switch received command OFF
then
    logInfo("Test Timer", "Received command OFF")
end

And the part of a rule restarting the timer:

        items.TestTimer_Switch.postUpdate("OFF");
        items.TestTimer_Switch.sendCommand("ON");

Now, the rule having the bug which was driving me crazy:

rules.when()
    .item("TestTimer_Switch").receivedCommand("OFF")
    .then(event => {
        console.log("Received command OFF");
    })
    .build("Test Timer JS");

And the bugfixed version:

rules.when()
    .item("TestTimer_Switch").receivedCommand()
    .then(event => {
        if (event.receivedCommand == "OFF") {
            console.log("Received command OFF");
        }
    })
    .build("Test Timer Cmd JS");

The real rule has multiple triggers, so actually had to check the item as well:

        if (event.itemName == "OfficeTvSocketIdle" && event.receivedCommand != "OFF") {
            return;
        }

After reading the documentation, the mistake in my migration from DSL to JavaScript became obvious, but nevertheless, I'm wondering if it would make sense - and is feasible - to support providing the command in the Rule Builder Trigger? I.e. so that it would be possible to use .receivedCommand("OFF") (as an example).

Your Environment

  • openHAB version used: 4.2.2
  • openhab-js version used: 5.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions