How to create a dynamic number of buttons for sendTelegramQuery in Rules

  • Platform information:OpenHABian on Raspberry Pi 3+
    • openHAB version: 2.5.10
  • Issue of the topic: I am trying to iterate through group members with forEach , check the state and if a state matches, return it as an argument to “sendTelegramQuery” as one of the buttons.
...
var String command_list = ""
gLight.members.forEach[ lamp |
	if (lamp.state == ON) {
		if (command_list != "") command_list += ", "
		command_list += "\"" + lamp.name + "\""
	}
]
telegramAction.sendTelegramQuery("what to turn off?", "lights_off", command_list)
...

and it shows me just one button with text ‘“light_1”, “light2”, “light3”’.

sendTelegramQuery accepts one argument for each button (

sendTelegramQuery("question text", "reply_id", "light_1, "light2", light3", "some other button")

Telegram - Bindings | openHAB
)

Specifically the question is: is there an equivalent to eval() function so that command_list is treated as a list of arguments and not just a string, or is there another way to do this?

Sorry for the noob question, but I am a newbie to openHAB and Java (and objects and variable types in Java and how to convert between them)

The rules DSL is extremely limited, but scripted automation can do what you are after. Using Jython, you can unpack a list to use as arguments.

1 Like

Thanks for the tip, will read through.

1 Like

By the end of the weekend you can install Jython and the helper libraries from the Eclipse IoT Marketplace using Paper UI. Just shout if you need more details on how to implement this.