Design Pattern: Proxy Item

Tags: #<Tag:0x00007f6ce5f14c90> #<Tag:0x00007f6ce5f14ab0>

(rbausdorf) #21

What would be the best approach if some of the bound items would overlap between two proxy items ?
The use case:

  • 3 bound outdoor light items: frontgate, entry, carport
  • Different bound and virtual trigger items: darkness, manual, gate contacts
  • 2 proxy items:
    • fromFrontgate: handles frontgate and entry when front gate opens in darkness
    • fromCarport: handles carport and entry when carport gate opens in darkness

I currently have a wild combination of the virtual and proxy approach, which finally works somehow but the code is ugly and it takes me every time half an hour to re-understand it.

(Rich Koshak) #22

I would create a Group for each trigger and send command to the group. Items can be members of multiple groups and a command sent to a group gets forwarded to all it’s members.

You run into trouble when you start to need scenes (e.g you have a mix of dimmers, switches and color and each needs a custom value) in which case you need to use proxy items and rules.

(rbausdorf) #23

Tried that but that led to the following conflict:
Lets say we have two groups A and B. Members of A are x and y, member of B are y and z.
Assume both groups are ON. Then the timer for group A expires, the timer for group B has still some time left. Switching off group A would switch off y which is not intended in this situation. As far as I concern there is no possibility to define an XOR
Group which would solve this situation.

(Rich Koshak) #24

That want clear from your posting. You can still use groups but you need to use a proxy item to trigger the on and off.

On the rule you can do something like:

GroupA.members.filter[light | !light.groups.contains("B")].forEach[light| light.sendCommand(OFF)]

Of course the logic will be a bit more complex because you don’t need to send off if the light is already off and you only want to exclude B members sometimes, but this should address the problem somewhat.

(rbausdorf) #25

Smart. There is so much you can do with the rules DSL and so little documentation. Even the Xtend / Xtext docs I found only cover the definition and implementation of a DSL, not its usage - do you have some hints where to look on the usage of an already defined DSL ?

(Rich Koshak) #26

I learned a lot from the Xtend movie demo.

Beyond that look at the Design Patterns. In particular almost everything you can do with Groups is in Design Pattern: Working with Groups in Rules.