Design Pattern: Working with Groups in Rules

...map[ label + " All OFF" ]

nope
 i also tried this
 this is resulting in
[Station 1All OFF, Station 2All OFF]

But i want

[Station 1, Station 2, All OFF]

Underneath


can’t you just do:

reply_buttons = reply_buttons + ", All OFF"

Nope - see #145

this gives me a error in VS Code
Assignment to final variable(org.eclipse.xtext.xbase.validation.IssueCodes.assignment_to_final)

As I said, it was really unclear what you were trying to accomplish.

Just add another element.

reply_buttons.add("All OFF")

That won’t work because reply_buttons is a List Object and there is no + operator for List objects. But there is an add method. Or maybe it’s append. I haven’t done Rules DSL in a long time.

Does it work though? Does openHAB itself give an error. I find that VSCode doesn’t always tell the whole story with openHAB stuff
 See above why it won’t work!

sorry that i was not clear enough :slight_smile:

this gives me also a error:
The method add(String) is undefined for the type Iterable<String>(org.eclipse.xtext.diagnostics.Diagnostic.Linking)

OK, the map returns an Iterable. I’m going to guess that underneath it’s a List of some sort so cast it to a List. You’ll have to import java.util.List.

import java.util.List

val List<String> reply_buttons = (gOSPI_Station.members.filter[ i | i.state == OFF ].map[ label ]) as List<String>
reply_buttons.add("All OFF")

If that doesn’t work you need to use the forEach approach above to manually add each element to a List and then append “All OFF”.

1 Like

this gives me a error
Rule 'Telegram Bot receive rasen': Could not cast [Station 1, Station 2] to java.util.List; line 18, column 38, length 80

So for now i created a dummy item:
Switch OpenSprinklerAllStationsOff "Alle aus" (gOSPI_Station)

and kept that line in the rules:
val reply_buttons = gOSPI_Station.members.filter[ i | i.state != ON ].map[ label ]

2020-08-19 18_51_09-Telegram

this is the result i was searching for
 but requieres such dummy item
 but i can live with that
 maybe this will help me with the second part of the rule for the telegram answer :slight_smile:

Thanks all for you help :slight_smile:

Hi, I am just trying to improve the presence detection in my house.
I would like to detect if a light has been switched since last 10 minutes but to avoid ton’s of rows I would like to use a group function.

All the Items are in a “Luci” Group

A single row function which works is for example:

var Number Presenza=0
if (Luce_1.changedSince(now.minusMinutes(10))) Presenza=1
if (Luce_2.changedSince(now.minusMinutes(10))) Presenza=1



Now Can you Help with the group Function?

I tried:

if (Luci.members.filter[ i | i.changedSince(now.minusMinutes(10)) ]) Presenza=1

But doesn't work as expected (no errors but always Presenza=0 even if I switch a light)

Any help?

Thanks
Lorenzo

That gives you a list. A list is neither true nor false, so far as an if() is concerned.

Maybe you could see if the list length > 0

It works
Thanks
Lorenzo

Hi all,

I have a group of lights that is controlled by a number of different options, OH switch, Alexa, physical wall switch.

I’m writing a few rules to work out if any of the lights in the group are on to then determine if the rule should run or not, they are Phillips Hue spots so I can’t search by ON / OFF, I have to do it by Brightness > 0.

I’ve got different options on how I can code the rule, my question to help determine the best way is
is there a way to determine if:

all lights in the group are brightness = 0
or
any lights in the group are brightness > 0
or
what lights in the group are brighness of either = or > 0

???

Thanks in advance.

You can make a Group just for this purpose, a Switch type with aggregate function OR(ON,OFF) should do.

1 Like

To add on: here’s an example that I use everyday - scroll down to zigbee.items to see the setup, and then just below the screenshot of my sitemap.

To do your first two queries you would just compare against the dimmer group. The last one will have to be done by individually checking each light.

1 Like

Of course, I’m always trying to make things too complicated. Good old KISS theory, keep it simple stupid as my old maths teacher used to say


EDIT:

Right, I’ve just found out that after some scratching of head and some very random results in using a switch, it would appear the Hue spots that I have don’t accept on / off commands in the way you’d hope, they turn the lights on but only to a brightness of 1
they need to be brightness 100
so the group switch is out, but for anyone else reading this, the concept of the group switch certainly works.

Hey guys,

Thanks to this topic, I managed to have the items of a group named and sent to me via telegram that have a certain status.

rule "Abfrage"
when
    Item Abfrage received command ON
then
    sendTelegram("bot1", gWindow.members.filter[i | i.state==OPEN].map[ label ].reduce[ result, label | result = result+", " + label ] + " ist offen" )
end

Unfortunately, I get a “null” message when none of the items in the group have the requested status.

Does anyone know how I can prevent this?

Greetings

Expand your rule. Get your list of Items into a variable first. Then test to see if it has length zero before doing anything with it.

Hi I created a short test to understand the behaviour of Group but I receive always a “null” message

> Items
> Group PIPPO "test group"
> Switch PIPPO_1 "membro 1" (PIPPO)
> Switch PIPPO_2 "membro 2" (PIPPO)
> Switch PIPPO_3 "membro 3" (PIPPO)
> Switch MQTT_Remote  "membro 4"  (PIPPO)

Sitemap
Switch item= MQTT_Remote

Rule (I tried both the logInfo)

rule "testgroup"
when
  	Member of PIPPO received command
then
 	logInfo ("testgroup ", "MQTT_Remote") 	
//	logInfo ("testgroup ", MQTT_Remote)
	val prova=triggeringItem
	logInfo ("testgroup 1", prova)
end

Where am I wrong?
Thanks

logInfo(X,Y) wants to be given two strings. Your prova is an Item object, not a string.
Examples-
logInfo ("testgroup 1", "Testing " + prova.name)
logInfo ("testgroup 1", "State " + prova.state.toString)

There is a handy way to see objects using {} in the text and an extra parameter.
logInfo ("testgroup 1", "trigger Item was {}", prova)