Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule chaining #2190

Open
damianon opened this issue Sep 28, 2019 · 16 comments
Open

Rule chaining #2190

damianon opened this issue Sep 28, 2019 · 16 comments

Comments

@damianon
Copy link

I want to be able to create a rule similar to this:

At 8PM turn off light X and set light Y to color . And if light X was on, turn on light Y.

I haven't found a way to do this in one rule. Two rules could be possible, but with that approach the rules view would become very full and cluttered very fast and it's not easily visible which rules belong to the same "routine"

@mrstegeman
Copy link
Contributor

What you're asking for isn't super clear to me. Can you tell me if I have the idea right?

IF (time == 8pm AND lightX.on == TRUE) THEN
    lightX.on = FALSE
    lightY.on = TRUE
    lightY.color = <some color>
END

@damianon
Copy link
Author

damianon commented Sep 28, 2019

Well the exact use case I'd like to cover right now would be

IF (time == 8pm) THEN
    IF (lightX.on == TRUE)
        lightY.on = TRUE
        lightY.color = <some color>
    END
    lightX.on = FALSE
END

The color could be set regardless. I just want to prevent lightY turning on if no light was on in the first place (e.g. we aren't home or in another room)

@mrstegeman
Copy link
Contributor

mrstegeman commented Sep 28, 2019

The color could be set regardless. I just want to prevent lightY turning on if no light was on in the first place (e.g. we aren't home or in another room)

There's no need to set the color if the light won't be turning on. I think my rule above should actually handle your case. lightY will only be turned on if lightX was already on.

Your rule ends up doing the exact same thing as mine, since the lightX.on = FALSE statement is redundant with the inner IF block.

@damianon
Copy link
Author

damianon commented Sep 28, 2019

well. my logic failed me. thanks for that solution (still, i'm sure there are use-cases where nesting would be useful)

@damianon damianon reopened this Sep 28, 2019
@damianon
Copy link
Author

damianon commented Sep 28, 2019

Sorry, I just remembered something:

If lightX is off and lightY is on, the color should still be changed,
So my example IF statement is wrong as I'd actually want the setting of the color outside the inner IF:

IF (time == 8pm) THEN
    IF (lightX.on == TRUE)
        lightY.on = TRUE
        lightX.on = FALSE
    END
    lightY.color = <some color>
END

@mrstegeman
Copy link
Contributor

I think what you really want is:

IF (time == 8pm) THEN
    IF (lightX.on == TRUE OR lightY.on == TRUE)
        lightX.on = FALSE
        lightY.on = TRUE
        lightY.color = <some color>
    END
END

Either way, you're right that you'd currently need multiple rules to handle it, or write an external script using the Web Thing REST API to do this for you.

@flatsiedatsie
Copy link
Contributor

@mrstegeman In theory, from version 0.10 onwards, could someone write an add-on that adds a more complex rule system? For example, one in which people could code or use blockly? Not volunteering, just curious :-)

@mrstegeman
Copy link
Contributor

Yes, in theory. You'd still have to use the manual OAuth token process, but otherwise, it should work fine.

@flatsiedatsie
Copy link
Contributor

You'd still have to use the manual OAuth token process

I'm sure version 0.11 will remove that obstacle ;-)

@damooooooooooh
Copy link

Hi so the Gateway rule engine wont be enhanced to support these types of use cases in the future and rule processing should be triggered outside the gateway?

@mrstegeman
Copy link
Contributor

In most cases, these complex rules can be broken down into a set of simpler rules, so the functionality is already available, albeit in an inconvenient fashion.

@damooooooooooh
Copy link

damooooooooooh commented Oct 10, 2019 via email

@madb1lly
Copy link

madb1lly commented Dec 3, 2019

In most cases, these complex rules can be broken down into a set of simpler rules, so the functionality is already available, albeit in an inconvenient fashion.

Hello @mrstegeman, the inconvenience is the problem, actually, as it makes the rules page very cluttered. Simple rules would be fine if we had a way to visually group or link them, but they are just listed one after the other so it quickly becomes difficult to keep track of which rules are associated with which other ones.

Regarding #2216 and this issue the inability to use more complex logic means that we have no choice but to use simple rules.

So, we need either:

  1. Rules can use more complex logic
  2. Rules pages allows visual grouping or linking of rules (probably need to raise a new issue for this request).

@madb1lly
Copy link

madb1lly commented Dec 5, 2019

@benfrancis considering your comment on #2337 I think my suggested option 2 may be your preferred option:
2. Rules pages allows visual grouping or linking of rules.

@benfrancis
Copy link
Member

Hi @madb1lly,

A long-running feature request is groups for things, so I think we should probably tackle that first.

I'm not so sure about grouping rules, but a first step could be to allow users to re-order rules in the same way that you can already re-order things. That way you can at least put related rules next to each other.

Again, I want to be careful about getting the right balance between simplicity and flexibility for the default rules engine UI. But there's nothing to stop you creating an add-on which provides a more sophisticated view for rules or allows more complex rules to be created.

@madb1lly
Copy link

madb1lly commented Dec 7, 2019

Hi @madb1lly,

A long-running feature request is groups for things, so I think we should probably tackle that first.

I'm not so sure about grouping rules, but a first step could be to allow users to re-order rules in the same way that you can already re-order things. That way you can at least put related rules next to each other.

@benfrancis being able to reorder rules will help. Grouping things will be very useful but won't help this issue, will it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants