I am trying to read electricity unit prices for the Octopus Agile tariff into a series of items using an HTTP thing with a JSONPATH transformation and then a JS transformation.
The HTTP binding retrieves the JSON containing the unit prices correctly and the JSONPATH transformation can pick out the particular values that I’m interested in. The URL for the prices is here and returns data like this:
{"count":5614,"next":"https://api.octopus.energy/v1/products/AGILE-23-12-06/electricity-tariffs/E-1R-AGILE-23-12-06-G/standard-unit-rates/?page=2","previous":null,"results":[{"value_exc_vat":11.13,"value_inc_vat":11.6865,"valid_from":"2024-03-18T22:30:00Z","valid_to":"2024-03-18T23:00:00Z","payment_method":null},
etc
etc
etc
(there are 48 sets of data for each 30 minute slot throughout the day)
The JSONPATH transformation I’m using is of the format:
JSONPATH:$.results[0].value_inc_vat
Which retrieves the unit price correctly, however the price is in UK pence (e.g. 11.6865 pence today at 22:30) and the number item is defined using the Energy/Price unit which is GBP/kWh so the value from the JSONPATH transformation needs to be divided by 100.
I’ve created a transform in the transform directory called divide100.js and set the contents to:
(function (data) {
return (data / 100)
})(input)
I then updated the channel transformation to:
JSONPATH:$.results[0].value_inc_vat ∩ JS:divide100.js
However, I get an error in openhab.log:
2024-03-18 11:49:23.538 [WARN ] [.transform.SingleValueTransformation] - Transformation service JS for pattern divide100.js not found!
I have the JavaScript scripting addon installed, the one for ECMAScript 2022+ (has a bright yellow background in the add-on store) and have tried restarting OH after I created the divide100.js transform but that didn’t help.
Can anyone suggest what magic I’m missing to get the chaining of transforms to work?