Http javascript transformation - need help

Hi all,
I am struggling with this problem:
I created an http cache url with http binding that returns a string that contains several values separated with line breaks:

What I need is assign the single values to distinct items.

How can I do that with javascript transformation?

What I did:

String returned_values "Current values" { http="<[http://192.168.x.x/data:30000:JS(getValue.js)]" }

What I need are the following items:
Number Vac …
Number Iac …

How can I transform the cached http string using javascript?


Why does it have to be JavaScript? Regex is a more natural fit.

No matter what you choose, you will need a separate transform for each value you want to extract from the string.

Hi Rich,
I thought about javascript but REGEX could fit too.
My goal was to read only once (using http cache) from the unit and then populate the items with a transformation. But then I stopped as I haven’t been able to extract the single values from the string.

Can you point me to a way to extract the values from the cached http string into the items?

An option would be to put the value in a String item (with the http binding), without any transformation. Then create a rule that is triggered when this item changes. In this rule you can split up the values over multiple items.

1 Like

See Comprehensive Wunderground using HTTP Binding Example

You just need to create your items and use the proper transform to extract the value for each item.

For example, .*Iac=(.*)</br>.* would the regex to extract the Iac value.

@idserda, you are suggesting to send one periodic request to the server and then elaborate in a rule the single items.
While @rlkoshak, you are suggesting to send 16 periodic requests to the server, one for every item.
Which is better?

That isn’t what I’m suggesting at all. You said that you are using the HTTP cache configuration (i.e. added the URL to poll to http.cfg). This will poll the URL once per polling period and cache the results. Then when you use that config in your Items, the Items will poll the cache and apply the transform and populate the Item. You can have 100 Items but the actual web service only gets polled once.

I would go with @rlkoshak’s solution, and use caching as he mentioned. That way you have the complete configuration in one place (your item files), which is more convenient than having to maintain both the items and the rule.

sorry I misinterpreted.
Now I understand better the http binding.

Managed to get it working. Thanks