It’s also possible to run it in a shell if you pass the command to a shell. For example:
val myText = "bash -c 'sudo -u openhab /usr/bin/curl... | /usr/bin/jq \..."
Though I would still recommend using a shell script like you have done already. As mentioned, getting the quotes right and all the escaping becomes challenging. But I wanted to mention that it is possible to run commands in a shell so you can get pipes and redirects and such.
NOTE: There is no reason to sudo -u openhab
, it’ll already be running as user openhab.