Unchanging string in items

Quick question I am struggling to find an answer for…

I am using openhab so get various info from my octoprint server.

An item looks like this:

Number OctoprintJobEstimatedPrintTime   "Estimated Print Time [%.0f s]" <time>  (gOctoprint)    {http="<[$.job.estimatedPrintTime)]"}

There are quite a few of these and my API key sometimes changes when I have to reinstall stuff etc etc, whatever.

I’d like to create a “virtual” item that is simply a string containing the API key, the insert that string variable into the URL above, so when the key changes I only have to update it in one place.

Something like this:

String OctoprintApiKey "Octoprint API Key" (gOctoprint) {"myApiKeyABCDEF123456"}
Number OctoprintJobEstimatedPrintTime   "Estimated Print Time [%.0f s]" <time>  (gOctoprint)    {http="<[" + OctoprintApiKey + ":60000:JSONPATH($.job.estimatedPrintTime)]"}

Obviously, this doesn’t work else I wouldn’t be asking.

Can anyone help, or suggest a better way, please?


You can use the http action instead in a rule
This way you could insert the API in the url

Also see Design Pattern: Encoding and Accessing Values in Rules