openHAB 3.3 with HTTP-Binding - X-PATH Question

Dear Community,

i am using the openHAB 3.3 Version with a HTTP-Binding to read out data from a HTML page with x-path.

Now i read in the value 123 rpm. But now i cannot declare this in the Channel as “Number” because it contains not only the 123 rather also rpm. Now the question if there is a possibility to remove all except numbers from the read in x-path?

Can anybody helps me? if i define the x-path as “String” all working fine. when i define as “number” i get NULL back.

i have attached a screenshot here.

thank you so much!

Why not use a Number:Frequency Item instead. That will accept and keep the rpm unit on the Number. Then you don’t need to do anything.

XPath is very powerful. It might let you manipulate the values extracted. See XPath Tutorial.

The HTTP binding supports chaining transformations so you could tack on a REGEX transform to extract just the number from the result of the XPath.

1 Like

Dear rlkoshak,

thank you. i have tried to use Number:Frequency but getting also a NULL as output.
The data in the output from XPath = 784 rpm.

I have also checked via XPATH but have no idea how i can remove the rpm from the output. then i can save also as number.

i have tried with xpath and replace, but dont know if the syntax is correct.

maybe i can output it correctly via state command?

thank you so much

many greets iceget

The you should be getting a reasonable error in the logs indicating why it didn’t work. Number:Frequency explicitly supports rpm as a unit.

There are XPath testers online. You can experiment there. The intricacies of XPath syntax and usage is outside the scope of this forum. Few if any of us are experts on XPath.

For the most part, screen shots are useless to us. Please click on the code tab and paste what you find there when trying to show what you’ve done.

But like I said above, you can chain transformations so chain youer XPath to a REGEX (something like REGEX:(.*) rpm should work assuming the XPath is returning what you think it is).

Thank you.

The one and only what i can get from sidebar log is that:

* openhab/items/Maico_WS320KB_DrehzahlAb/updated


[{"type":"Number:Frequency","name":"Maico_WS320KB_DrehzahlAb","label":"Aktuelle Drehzahl Ventilator Abluft\t","category":"","tags":["Point"],"groupNames":["Maico_WS_320_KB"]},{"type":"Number:Frequency","name":"Maico_WS320KB_DrehzahlAb","label":"Aktuelle Drehzahl Ventilator Abluft\t","category":"","tags":["Point"],"groupNames":["Maico_WS_320_KB"]}]

in code self, i have only the main channel there:

UID: http:url:cab92a5e43
label: Maico WS 320 KB
thingTypeUID: http:url
  authMode: BASIC
  ignoreSSLErrors: false
  delay: 0
  stateMethod: GET
  refresh: 15
  commandMethod: GET
  contentType: text/xml
  timeout: 3000
  username: admin
  bufferSize: 2048
  - id: Maico_WS320KB
    channelTypeUID: http:string
    label: Maico WS320 KB
    description: ""
    configuration: {}

Direct in /var/log/openhabian/events.log:

2023-12-20 19:40:53.209 [INFO ] [openhab.event.ItemUpdatedEvent      ] - Item 'Maico_WS320KB_DrehzahlAb' has been updated.

Where i can find additional logs?

When i change from String to Number.Frequency i get only NULL values back. No data will be updated also not any visible reason in the log files.

thank you so much!

You will have to look openhab.log on the machine where openHAB is running or, if you have openHABian, Frontail in the browser. Errors are not going to appear in the Developer Sidebar.

Same folder as events.log

Thank you @rlkoshak but nothing with Maico or the Channel will be logged.
I have much other logs from my other components, but no log for the changed channel.

maybe OH 3.3 its too old? how i can maybe enable debug logging? did you have another idea how i can check the log why this happenes?

thank you!

The one and only what i see in the logs when i change it from string to number.frequency, this (and then no update happens until i change it back to string):

2023-12-20 20:15:27.747 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Maico_WS320KB_DrehzahlAb' changed from NULL to 787 rpm
2023-12-20 20:15:41.810 [INFO ] [openhab.event.ItemUpdatedEvent      ] - Item 'Maico_WS320KB_DrehzahlAb' has been updated.

here then after the last line, no update in log appears. and in web interface i only see NULL.

when i change back, then its updating correct with the value and rpm.

You should see an error when a message is processed and passed to the Item along the lines of “Failed to update Item BlahBlahBlah 123 rpm is not a valid state for a Number Item” if the problem is the data being passed to the Item. If not, the problem isn’t the Item type but the value being returned by the transform.

If I recall, rpm was a more recent addition to the UoM lists. OH 3.3 (which is pretty old at this point) might be too old to support rpm as a unit.

As for getting just the value, XPath does have some basic string functions you should be able to use (search for substring-before I think it’s called), but personally I would fine it quicker and easier to use regex instead of xpath in this situation.

Thank u for your reply.

Now i have Upgrade today to current stable v 4.

When I now use number frequency, I get now back the Hz. But is it possible to get it back through rpm?

Or have I now more optiona with New open hab for doing that?

Thank u so much!

Many greets iceget

For the old Setup I dont get anything with v3. 3 before.

Yes, you can. See the docs on setting the unit metadata for your item:

I hadn’t considered that. That makes sense here.

The default conversion the framework will use is locale-based: The framework tries to convert a QuantityType to the default unit of the configured locale.

This means that the units used by an Item, without the unit metadata is the system default. For many units that default depends on your region but others are not specific to regions and something needs to be the default. Apparently Hz is the default for Frequency (that makes some sense, Hz is likely to be more commonly used in a home automation context than rpm).

1 Like