WebThingsIO / gateway

WebThings Gateway
http://webthings.io/gateway
Mozilla Public License 2.0
2.61k stars 336 forks source link

Add optional Else statement to Rules #2337

Open madb1lly opened 4 years ago

madb1lly commented 4 years ago

Hi Moz-IoT team,

I find that I have to create almost twice as many rules because I can't have an Else statement to take account of when the rule conditions are not satisfied.

For example, I currently need two rules for my heating system (well, more than that as other limitations of the rules engine mean I need to create many, but anyway...):

  1. If my heating system conditions are true (temperature, time, presence) then turn the heating system on
  2. If my heating system conditions are not true (temperature, time, present) then the heating system off

The second rule could easily be replaced by an Else statement.

I realise that there may be cases when a binary choice is not what is needed, which is why I request that the Else statment is optional, not mandatory.

This request could be expanded to Case statements for when a binary choice is insufficient.

benfrancis commented 4 years ago

Thanks for this suggestion, which we'll look into.

However, regarding this issue and #2190 I want to be up-front about the fact that I'm very cautious about adding any extra complexity to the rules engine. The rules engine UI is designed to be simple enough for non-technical users to configure basic rules, but isn't intended to fulfil every possible use case.

If we can find ways to add features to the rules engine which don't compromise that simplicity then we may do that, but there are some features we will have to say no to in order to prevent the rules engine evolving into a Turing complete graphical programming language!

For more complex logic I recommend writing external scripts and applications which communicate with the gateway via the Web Thing API, or creating your own rules engine as an add-on.

madb1lly commented 4 years ago

Hi @benfrancis,

I actually think it's more mentally taxing to write the exact negative of a condition, especially if that condition is AND or OR, than just to provide an Else option. Else always means when the condition is not true, but to write another if statement we need to invert the logic. The rules engine doesn't provide NOT either, so inverting the logic isn't necessarily intuitive for a non-technical person.

E.g. The opposite of (X = On AND Y = On) is (X = Off OR Y = Off), but a non-technical person might expect it to be (X = Off AND Y = Off). Then not understand why it doesn't work and get frustrated. I've even made this mistake myself, earlier this year I think, and I am a technically-minded person.