sendCommand with a string


I have a question regarding the sendCommand statement. I calculate the days to an event (dif_days) and let Alexa tell it.
Why does this code work:

Echo_Living_Room_TTS.sendCommand(“Es sind noch " + dif_days.toString() + " Tage bis olper Schützenfest 2021”)

And this does not:

var string answer = “Es sind noch " + dif_days.toString() + " Tage bis olper Schützenfest 2021”
Echo_Living_Room_TTS.sendCommand(“Es sind noch " + dif_days.toString() + " Tage bis olper Schützenfest 2021”)

By the way, what is the best way to get deeper into rule programming. I can only find the very basic documentation in the configuration guide.

Welcome to the community!

Your sendCommand actions are identical, so it’s unclear as to what you’re trying to do. I think you meant to substitute your variable in the second version.

When you say it doesn’t work, what result do you get? The more detail you provide, the easier it is for others to help diagnose.

The best way to get started, in my opinion, is to search through the community and find examples of rules to study. If you don’t find something, just ask! In most cases, someone has tried that exact thing or something similar. As well, if you search for “design pattern”, you’ll find that some of our members have written great tutorials on how to accomplish specific tasks.

If you’re just getting started in openHAB, you might also want to skip right to using Jython rules, as this is the direction openHAB is moving. The current rule system will continue to work in the next version, but there are a lot of advantages to Jython. I haven’t jumped in yet, but there are lots of people to help if you run into troubles. This thread is a good place to start.

Best to not cast to a specific type… let the DSL do it for you. So, remove the ‘string’, which should be in uppercase anyway. Better yet, run from the DSL before it draws you in like quicksand… and use the new rule engine with scripted automation, Jython, and the helper libraries!

events.sendCommand("Echo_Living_Room_TTS", u"Es sind noch {} Tage bis olper Schützenfest 2021".format(dif_days))
1 Like

Of course the Alexa command is


Sorry, I grew up with programming languages that don’t allow that…
The lowercase was the problem. I just wonder why the command

logInfo(“myLog”, answer)

right before the Alexa command worked properly.

I’ll give it a try. Thanks for your help.

1 Like