Transformation service JS for pattern Heizoel.js not found!

I get the following WARN every time my Http binding receives the webpage.

Transformation service  JS for pattern Heizoel.js not found!

The Transformation Service is installed and i have other bindings witch use it successfully

Here is my Thing Code

UID: http:url:1bf89b2603
label: Heizöl24
thingTypeUID: http:url
configuration:
  authMode: BASIC
  headers:
    - ""
  ignoreSSLErrors: false
  baseURL: https://www.heizoel24.de/api/kalkulation/berechnen
  delay: 0
  stateMethod: POST
  refresh: 600
  commandMethod: GET
  contentType: text/plain
  timeout: 3000
  bufferSize: 2048
channels:
  - id: UnitPrice
    channelTypeUID: http:number
    label: Preis
    description: ""
    configuration:
      mode: READONLY
      stateContent: #other Contend
      unit: €/100l
      stateTransformation: JSONPATH:$.Items[0].UnitPrice ∩ JS:Heizoel.js

Here is the Heizoel script:

(function(i) {
	
  result = Math.round(i.replace('.',',')
  return (result);
})(input)

The Jsonpath Transformation works for a String because it returns [123.456] in the JSONPath Online Evaluator and sets a String to 123.456 but not the Number Item so i have to Transform it a second time.

I have also tried it with REGEX there is the same Problem as stated above it dos not find the Transformation service.

Please help me

Greetings Markus

Just a guess:
Remove spaces surrounding .

1 Like

Yes, that is it Thanks
Also i cant have the unit: €/100l doesn’t work.
Also i have changed the Javascript

(function(i) {
  result = parseFloat(i)
  return (result);
})(input)

Units Of Measurement | openHAB don’t include currencies - support for currencies would open a can of worms (currency conversions are dependent on location and time).

Dear Markus,

I tried to get your code working, but the http request returns no data. All I get is:

[WARN ] [p.internal.http.HttpResponseListener] - Requesting 'https://www.heizoel24.de/api/kalkulation/berechnen' (method='POST', content='null') failed: 400 Bad Request

Do you have a tip?

Thanks,
Robbi

Hey,

I have deleted the stateContent of the Channel for Privacy reasons. Without that the Request dosent work/failed.

Here is my stateContent

stateContent: '{"ZipCode":"xxxxx","Amount":2000,"Stations":1,"Product":{"Id":1,"ClimateNeutral":false},"Parameters":[{"Key":"MaxDelivery","Id":5,"Modifier":-1,"Name":"maximal","ShortName":null,"DisplayName":"max.
        Lieferfrist","CalculatorName":"siehe
        Angebot","SubText":null,"HasSpecialView":false,"IsUpselling":false,"BlackList":[],"Selected":true,"HasSubItems":false,"UseIcon":false},{"Key":null,"Id":24,"Modifier":-1,"Name":"ganztägig
        möglich (7-18
        Uhr)","ShortName":null,"DisplayName":null,"CalculatorName":null,"SubText":null,"HasSpecialView":false,"IsUpselling":false,"BlackList":[],"Selected":true,"HasSubItems":false,"UseIcon":false},{"Key":null,"Id":-2,"Modifier":-1,"Name":"alle","ShortName":null,"DisplayName":null,"CalculatorName":null,"SubText":null,"HasSpecialView":false,"IsUpselling":false,"BlackList":[],"Selected":true,"HasSubItems":false,"UseIcon":false},{"Key":null,"Id":11,"Modifier":-1,"Name":"mit
        Hänger","ShortName":"groß","DisplayName":"TKW mit
        Hänger","CalculatorName":"mit
        Hänger","SubText":null,"HasSpecialView":false,"IsUpselling":false,"BlackList":[],"Selected":true,"HasSubItems":false,"UseIcon":true},{"Key":null,"Id":9,"Modifier":-1,"Name":"bis
        40m","ShortName":"40m","DisplayName":null,"CalculatorName":null,"SubText":null,"HasSpecialView":false,"IsUpselling":false,"BlackList":[],"Selected":true,"HasSubItems":false,"UseIcon":false}],"CountryId":1,"ProductGroupId":1,"Cn":false,"Ap":false,"AppointmentPlus":false,"Ordering":0,"UpsellCount":0,"InitialOpenedSettings":true}'

Here you must change xxxxx to your zip code.
If you want a different search inspekt the website with F12 while searching for prices.

Greetings Markus

Is this really necessary? The output of a transform is STRING anyway. If the only purpose of the JS transform is to convert it to float, it’s pointless because the transformer will convert the float back to string.

Thank you Markus, that did the trick!