openhab / openhab-js

openHAB JavaScript Library for JavaScript Scripting Automation
https://www.openhab.org/addons/automation/jsscripting/
Eclipse Public License 2.0
38 stars 31 forks source link

Rule Builder API doesn’t support the DateTimeTrigger #280

Closed jlaur closed 10 months ago

jlaur commented 11 months ago

Currently there is no Rule Builder trigger for DateTimeTrigger (see https://www.openhab.org/addons/automation/jsscripting/#jsrule)

As an example, this cannot be built with the rule builder:

rules.JSRule({
    name: "Dishwasher start",
    description: "Start dishwasher based on calculated price",
    triggers: [triggers.DateTimeTrigger('Dishwasher_CalculatedStartTime')],
    execute: event => {
        if (items.Dishwasher_RawState.isUninitialized || items.Dishwasher_RawState.numericState != 4 || items.Dishwasher_CalculatedStartTime.isUninitialized) {
            return;
        }
        items.Dishwasher_Switch.sendCommand("ON");
    }
});

This would be a nice addition.

Your Environment

jlaur commented 10 months ago

To be precise: I'm not sure if actually supported, but it's not documented. I just noticed that there is a RuleBuilder example with timeOfDay("SUNSET"), but actually this is not documented besides the example.

The TimeOfDayTrigger is documented just before the DateTimeTrigger in the JSRule section.

florian-h05 commented 10 months ago

I just noticed that there is a RuleBuilder example with timeOfDay("SUNSET"), but actually this is not documented besides the example.

There is no actual support for that, the source code does not contain that. I will add the timeOfDay trigger, however it does not support something like SUNSET (looking at openHAB Core).

jlaur commented 10 months ago

I will add the timeOfDay trigger, however it does not support something like SUNSET (looking at openHAB Core).

In that case the example should probably be updated:

// Turn on the kitchen light at SUNSET
rules.when().timeOfDay("SUNSET").then().sendOn().toItem("KitchenLight").build("Sunset Rule","turn on the kitchen light at SUNSET");
florian-h05 commented 10 months ago

@jlaur I have created a PR to add the trigger, see #291 and I also updated the documentation. The sunset rule is now triggered by using the Astro binding.

You can test the PR by installing my fork, execute in $OPENHAB_CONF/automation/js:

npm install git+https://github.com/florian-h05/openhab-js.git#rule-builder