Reading the arguments of a telegram command should work in this way, but it seems that it’s impossible to add an argument to a inline keyboard command (or a callback query). It’s true? or there’s another way to do it? so… where I’m wrong?
The only data Telegram sends is the callback query.
What exactly are you trying to achieve? You might be able to use AppDaemon to send relay_on_# as your callback query and use AppDaemon to parse the callback to separate out the number. Let me know if that’s something you’d be interested in trying and I can try and walk you through it.
I wouldn’t want to set, on Telegram, a command for every relay and every state (a total of 16 commands), like relay_on_1, relay_off_2, relay_on_2 and so on… I would want to use, instead, only 2 commands, like relay_on and relay_off and the use the arguments to append the relay number; this is possibile using the telegram_command event, but I’ve no luck with the telegram_callback; in this way it seems there’s no solution to use the inline keyboard programmatically.
Okay, I think I see what you are saying now. I didn’t realize a command could pass args. I think you could still do what you want to do programmatically, you’d just have to dynamically append _# to your relay_on command when generating the message, and you’d need to dynamically parse the number out of the callback when the callback is received. Again, while you might be able to pull that off with some Jinja2 templating in your automations, it’s probably going to be easiest to put together with AppDaemon.
I have tried to do that, but I can’t find a sollution. Once you press the keyboard command, it is sent. You don’t get the option to add an argument - unless you type the command by hand.
The closest I could find was to use “telegram_text”. It works like telegram_command, but there is no / and the text has to be 100% exactly like in the automation.
In your case you could send “on 8” (not using the command keyboard!) and as long as no other automation uses that, it will do what you want. The downside of course is that you need 16 automations to handle your variable input!
An other alternative is to set up a menu (which is what I did). Use a keyboard command to show an other set of keyboard keys. In your example, when your automation sends you the question what to do now, add a keyboard saying “/relay_on, /relay_off” but do NOT use them to trigger an action, but send you a keyboard with “/on 1, /on 2, /on 3,…” and “/off 1, /off 2, /off 3,…”
Note: I know it works if you have multiple automations checking for unique commands (on_1, on_2,…). I do not know, if sending “on 1” is seen as “command: on, argument: 1”. You’d have to test that.