martiniman
(martiniman)
February 11, 2019, 9:11am
1
This item shows “-NaN”
Number m8p34_temp "m8p34_temp [%.1f °C]" { channel="megad:device:in:m8_p34:i2c" [profile="transform:JS", function="megad_i2c_1.js"] }
But when i use rule - all ok:
rule "m8p34_i2c"
when
Item m8p34_i2c received update
then
logInfo("-----TEST------", transform("JS", "megad_i2c_1.js", m8p34_i2c.state.toString))
end
log:
12:09:50.653 [INFO ] [smarthome.event.ItemStateChangedEvent] - m8p34_i2c changed from temp:23.32/press:766.53/hum:39.927 to temp:23.31/press:766.51/hum:39.958
12:09:50.656 [INFO ] [marthome.model.script.-----TEST------] - 23.31
Any idea?
How to do transform in thing definition?
vzorglub
(Vincent Regaud)
February 11, 2019, 10:06am
2
What openHAB version are you running?
vzorglub
(Vincent Regaud)
February 11, 2019, 11:33am
4
Just for a test, change the item to a String
String m8p34_temp "m8p34_temp [%.1f °C]" { channel="megad:device:in:m8_p34:i2c" [profile="transform:JS", function="megad_i2c_1.js"] }
martiniman
(martiniman)
February 11, 2019, 11:39am
5
Yes, start working
2019-02-11 14:36:23.889 [vent.ItemStateChangedEvent] - m8p34_temp changed from NULL to 23.62
And Site map does not shows value, i delete conversion “[%.1f °C]” and SAVE items file, but error still appear:
Item is:
String m8p34_temp "m8p34_temp" <temperature> (allItems) { channel="megad:device:in:m8_p34:i2c" [profile="transform:JS", function="megad_i2c_1.js"] }
2019-02-11 14:41:36.064 [WARN ] [ui.internal.items.ItemUIRegistryImpl] - Exception while formatting value '23.66' of item m8p34_temp with format '%.1f °C': f != java.lang.String
vzorglub
(Vincent Regaud)
February 11, 2019, 11:53am
6
Ok try that:
String m8p34_temp "m8p34_temp [%s °C]" { channel="megad:device:in:m8_p34:i2c" [profile="transform:JS", function="megad_i2c_1.js"] }
martiniman
(martiniman)
February 11, 2019, 11:57am
7
vzorglub:
[%s °C]
Yes, item is displayed in sitemap.
This is only String conversions? Is it possible convert to Number?
rossko57
(Rossko57)
February 11, 2019, 12:01pm
8
I think this is a deficiency in the fairly new profile feature.
JS transforms always return strings, so there needs to be an “extra” step in the linkage between channel and Item to parse a profile result into something suitable for the Item type.
1 Like
vzorglub
(Vincent Regaud)
February 11, 2019, 1:14pm
9
Yes there is. This the second case this week I have seen.
martiniman
(martiniman)
February 11, 2019, 4:32pm
10
Do not clear for me, this is error in trasformation code?
shorty707
(Shorty707)
March 22, 2020, 3:38pm
11
I look how to make it work with http binding items
Number PV_testdel “Tagessumme [%0f Wh]” <energy3> (gFroniusFlow) { http="<[FroniusPowerFlowCache:30000:JSONPATH($.Body.Data.Inverters.1.E_Day)]" [profile="transform:JS", function="divide1000.js"] }
any idea
?
rossko57
(Rossko57)
March 22, 2020, 5:46pm
12
Yes, a transform profile will just not work with a Number Item.
opened 10:41PM - 19 Jun 19 UTC
Profiles allow for manipulation of values in between Items and binding channels.
Transform profiles allow user-defined manipulations e.g. numeric SCALE or arbitrary...
shorty707
(Shorty707)
March 22, 2020, 6:46pm
13
could I wrap this JSONPATH in another JS(divide1000.js) somehow to divide the value before its written to the item?
{ http="<[FroniusPowerFlowCache:30000:JSONPATH($.Body.Data.Inverters.1.E_Day)]" }
rossko57
(Rossko57)
March 22, 2020, 7:21pm
14
This remains true, however many layers of transform you use.
but if you’re suggesting writing a single transform for use in the binding config, that both handles JSON and does maths, go ahead.
shorty707
(Shorty707)
March 22, 2020, 8:24pm
15
But those items use a transform… Why can they be a number then?
See
I did not install a fronius binding - instead I am using the http binding to fetch the data from the fronius.
In order to do this you need to install the http binding form the Paper UI, then place three lines in your /services/http.cfg file, where you specify the IP address and update intervall of your fronius, like:
froniusrtd.url=http://192.168.1.59/solar_api/v1/GetPowerFlowRealtimeData.fcgi?Scope=System
froniusrtd.updateInterval=5000
format=false
Then you put one line for each value to f…
rossko57
(Rossko57)
March 22, 2020, 8:46pm
16
Because it is the binding that deals with matching and converting the string from the transform to the type of Item that the channel supports. (or the link in the case of 1.x versions)
Looking more closely at your previous post, it would never work. Profiles work with channels. but you’re using a version 1.x binding, No channel, no profile.
You can only use the transforms if the binding supports them. Hurrah, http binding does support transforms. (Not all bindings do)
Furthermore, http binding supports linking to Number type Items.
shorty707
(Shorty707)
March 22, 2020, 8:49pm
17
And now I tried to do 2 transforms js divide and jsonpath in one go. But if possible won’t find a working syntax
rossko57
(Rossko57)
March 22, 2020, 8:58pm
18
You cannot do two transforms. The binding does not support that.
Instead, you can write one script that does both of the functions you want to do.