OH3 Rules enhancement proposal - OR, NOT and ELSE

With the current OH3 rule engine you cannot (as far as I know) add OR clauses at the conditions, define NOT for a condition or define ELSE actions . With these additions, I think you only would have to revert to scripting for really complex rules.

Heavily inspired by how Homey solves this, it could be added in the following way to the yaml:
“Beter goed gejat dan slecht verzonnen.” we call this in Dutch.


OR conditions
Add a group property to the condition.
Conditions with the same group are AND-ed, groups are OR-ed with other groups.
To be backwards compatible, conditions without a group are also a group.
I left the first group nameless in the example, but it could be named “1”.
And to avoid confusion, I named the second group (the first named one below) “2”

Example yaml (condition part, rules are bogus):

conditions:
  - inputs: {}
    id: "3"
    configuration: {}
    type: ephemeris.HolidayCondition
  - id: "4"
    configuration:
      itemName: Spirit1_Currenttemperature
      operator: ">"
      state: "20"
    type: core.ItemStateCondition
  - id: "5"
    group: "2"
    configuration:
      ? offset
    type: ephemeris.WeekendCondition

This would mean:
when ( it is a holiday AND the Spirit1_Currenttemperature > 20 ) OR ( it is weekend )


NOT conditions

Add an ‘inverted’ property as boolean, when true it is a NOT condition.

conditions:
  - inputs: {}
    id: "3"
    inverted: true
    configuration: {}
    type: ephemeris.HolidayCondition

This would mean:
when ( it is NOT a holiday )


ELSE actions

Add an else property to the action. When true, it is an else action.
Note: Homey uses a group property with the value “else”, I think this is not needed, but it might be more handy for implementation as some logic of the grouping of the conditions could be reused.

actions:
  - inputs: {}
    id: "7"
    configuration:
      itemName: Spirit1_Setpointheat
      command: "20"
    type: core.ItemCommandAction
  - inputs: {}
    id: "2"
    else: true
    configuration:
      sink: enhancedjavasound
      sound: barking.mp3
    type: media.PlayAction

This would mean:
when the conditons are true ( set the Spirit1_Setpointheat to 20 ) ELSE ( play a barking sound )


Please let me know your opinions on this.
Also if this is going to be implemented by me and/or someone else, we’ll need to coordinate this, so we don’t do double work.

2 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.