my line val reply_buttons = gOSPI_Station.members.filter[ i | i.state == OFF ].map[ label ]
is resluting in this 2020-08-19 18:07:31.988 [INFO ] [se.smarthome.model.script.OSPI_Reply] - [Station 1, Station 2]
Station 1, Station 2 are the labels of current gOSPI_Station members (which will be more in the future)
and beside these Station names… I also want to append the String with “All OFF”
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!
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”.
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 ]
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
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)
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
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.
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.
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