Java Script transformation service

1,370 views
Skip to first unread message

Pali

unread,
Aug 14, 2013, 4:16:22 PM8/14/13
to ope...@googlegroups.com
I tested Java Script transformation service, which imho is pretty handy. It can be used to manipulate data by java scripts. 

Simple example to covert energy pulses to kWh's:

Number EnergyConsumption "Energy consumption [%.1f kWh]" { http="<[http://foo.com/get_pulse_count:60000:JS(convert_pulsesTokWh.js)]" }

convert_Wh2kWh.js:
var pulseConstant = 800;
var result = (input / pulseConstant).toString();


Kai/Thomas do you see that JS transformation service could be something which could included to main?

Br,
Pali




davy vanherbergen

unread,
Aug 15, 2013, 2:37:44 AM8/15/13
to ope...@googlegroups.com

Kai/Thomas do you see that JS transformation service could be something which could included to main?
 
+1 
I think this would be a really useful addition to openHAB.

Davy

Till Klocke

unread,
Aug 15, 2013, 2:45:37 AM8/15/13
to ope...@googlegroups.com
Java 8 will bring even its own JS-Engine (Nashorn). For earlier versions we could probably use Apache Rhino. This should be much simpler than XML transformations for most users.

Kai Kreuzer

unread,
Aug 19, 2013, 5:10:24 PM8/19/13
to ope...@googlegroups.com
Hi Pali,


Kai/Thomas do you see that JS transformation service could be something which could included to main?

Sounds useful indeed. What JS engine are you using?

Regards,
Kai

Cyril Jaquier

unread,
Aug 20, 2013, 2:31:35 AM8/20/13
to ope...@googlegroups.com
Hi all,

This is my own opinion and I do not mean to offense but I don't really like the idea of adding a new language here, a new one there, etc. Would it be possible to also use Xtend for this? Or if adding JS for transformation then also support it in rules/scripts? Of course, the purposes are not always the same and using a specific technology at some places has also advantages. But I would try to avoid adding too many of them if possible and thus avoid making the platform heavier and more complicated to maintain.

Regards,
Cyril

Pauli Anttila

unread,
Aug 20, 2013, 2:31:40 AM8/20/13
to ope...@googlegroups.com
I use rhino which is embedded to Java SE1.6 as a default java script engine, so it does not have any dependencies to external libraries. Embedded rhino does not support script compilation, so scripts are always interpreted.

Currently transformation services seems to be part of the core bundle, so it's probably wise to make them modular as well on the future.

I will clean up code a little bit, commit code on my clone and make an new feature proposal issue. I also implemented exec transformation service, so I will commit that as well.




2013/8/20 Kai Kreuzer <k...@openhab.org>

--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/groups/opt_out.

Kai Kreuzer

unread,
Aug 20, 2013, 1:48:02 PM8/20/13
to ope...@googlegroups.com
Hi Cyril,

I think as long as we do this as optional addons, it enriches the possibilities of openHAB while not increasing the complexity of the core. So if somebody wishes to use it - why not.

Regards,
Kai

Cyril Jaquier

unread,
Aug 21, 2013, 2:30:05 AM8/21/13
to ope...@googlegroups.com
Hi Kai,

Yes, having it as optional add-on is definitely a requirement. I just fear that this will make the configuration of openHAB more "fragmented". Some people will use Xtend with XSLT, others Drools with JS transformation, others X with Y, etc. Nothing bad actually but new users looking for help might get confused by all those different technologies.

I would just prefer one single script language (Drools, Xtend, JS or whatever) with good examples and documentation.

Just my 2 cents. Actually, I should contribute more to the project and write less ;-)

Regards,
Cyril

Pauli Anttila

unread,
Aug 22, 2013, 9:18:39 AM8/22/13
to ope...@googlegroups.com
Kai, I added review request http://code.google.com/p/openhab/issues/detail?id=414,  but I forgotten to change the issue name :( So could change it little bit more describable ;)

Br,
Pali

i...@schaussi.com

unread,
Nov 6, 2013, 1:24:33 AM11/6/13
to ope...@googlegroups.com
Hi,

this feature is only available for the HTTP binding, is this right?

Would be great if this worked also for the KNX binding, or every binding in general.

E.g. I get the power current values from KNX switching actors in mA and would multiply the output value with 230. At the moment, I have to define a rule for every single item...

Pauli Anttila

unread,
Nov 6, 2013, 5:16:53 AM11/6/13
to ope...@googlegroups.com
There are several bindings which support transformation service, so it's not just for the HTTP binding. But unfortunately, KNX binding does not support it.

Currently every binding need to handle transformations "manually", so depends on the binding implementation is transformation service support or not.

Br,
Pali


2013/11/6 <i...@schaussi.com>

--

Gert Konemann

unread,
Nov 6, 2013, 3:58:32 PM11/6/13
to ope...@googlegroups.com
Pali,

I cannot find how to use the javascript transformation service. Is there an example ? 

Gert

Op woensdag 6 november 2013 11:16:53 UTC+1 schreef Pali:

Pauli Anttila

unread,
Nov 6, 2013, 4:17:55 PM11/6/13
to ope...@googlegroups.com
Simple example:

Number phase1Current { openenergymonitor="phase1Current:JS(divideby100.js)" }

Java script files need to be located to OH transform directory.

My divideby100.js file content:

input / 100;


-Pali

Gert Konemann

unread,
Nov 6, 2013, 4:21:17 PM11/6/13
to ope...@googlegroups.com
Thanks for your quick reaction.

Gert

Op woensdag 6 november 2013 22:17:55 UTC+1 schreef Pali:
Reply all
Reply to author
Forward
Message has been deleted
0 new messages