You have a several lines of this code that are from older versions of javascript rules, and as result you are working with a mixture of javascript and actual java objects.
What version of OH are you running and which Javascript add-on have you installed?
That’s all good. In that case it’s the code you have to change.
You don’t need this. This is from very early versions before the current javascript helper library was fully mature. With your up-to-date versions of the add-on and OH you will almost never need this line.
When you do this, you are getting access to the underlying java object item, not a javasacript version of it. This is where the real issue arises.
All you need to do to get access to a javascript version of an item is:
getState will still work exactly the same way (but it will return javascript types) and the item will have the sendCommand method so you won’t get the error you are seeing at the end of the script.
Here’s a link to the javascript helper library docs. This is extremely helpful when you are just starting out with the jsscripting rules:
You are not transforming the correct thing. If you log your cost variable as currently written, I suspect you willl find that it is '[object object]' which is not what you expect. When you define cost
you are getting the whole javascript item object, not the state of the item (which I’m guessing is what you want) and then calling toString on the item object.
Instead, you just want:
var cost =items.getItem("Tibber_API_Prices_for_today_as_a_JSON_array").state;
which will automatically give you the string version of the item’s state.
Just for good measure, of course, you also have to make sure that you have installed the JSONPath add-on.