Http javascript transformation - need help

Tags: #<Tag:0x00007f61705e9768>

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:
i.e.
Vac=240.0</br>Iac=0.1</br>PowerGrid=0.0</br>VS1=223</br>VS2=256</br>IS1=0.0</br>IS2=0.0</br>PowerPV=0.0</br>VBatt=49.6</br>IBatt=9.7</br>PowerBatt=0.5</br>PercentBattery=68</br>ACinvTemp=45.0</br>BatteryTemp=31.4</br>PowerHouse=0.6</br>InvFlag=1071</br>

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 …
etc.

How can I transform the cached http string using javascript?

thanks

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.

Resuming:
@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.

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

Managed to get it working. Thanks