Channel transformations not working when using text files for item creation


I’m trying to create items with channel profiles.
My transformation works and have tested it when creating a new item through the UI. However, when I create the item using a text file, the transformation doesn’t work.
I have compared the two items, one created in UI and one created in text file, and cannot see a reason why it won’t work in the text file.

Item file

Number:Power H1_SolarEdge_TotalImportPower "Total Import Power" (H1_SolarEdge) { 
    channel="modbus:meter-wye-phase:solaredge1:meter:acGeneral#ac-total-real-power"[profile="transform:JS", toItemScript="solaredge_LiveImport.js", toHandlerScript=""]

Transformation file

(function(i) {
    var clamp = Math.min(0, Number.parseFloat(i)) * -1; 
    return clamp.toString() + " W"

Here is a creenshot from the UI created file

Here is the text file created item

When I save the items file, I get this error in the log

Neither 'toItemScript' nor 'toHandlerScript' defined in link 'H1_SolarEdge_TotalImportPower -> modbus:meter-wye-phase:solaredge1:meter:acGeneral#ac-total-real-power'. Profile will discard all states and commands.

I can’t find any difference that would stop the transformation working…
Any ideas?

This is strange. Try commenting out the whole item, save, then uncomment it.

If that doesn’t work, try renaming the .items file.

I’m pretty sure I tried that.

I had a similar problem you have to enter something for both transformations.
I therefore wrote an empty transformation.


(function(i) {
	return i;

@florian-h05 - I noticed that you are changing code around that line logging the error:

Neither 'toItemScript' nor 'toHandlerScript' defined in link 'H1_SolarEdge_TotalImportPower -> modbus:meter-wye-phase:solaredge1:meter:acGeneral#ac-total-real-power'. Profile will discard all states and commands.


Perhaps you have an idea what could be the issue here?

I am using .items files as well and I do not have that problem.

IMO the problem itself is really weird - the log message should only be logged if both config fields are blank, and one of them obviously isn’t.
It seems that somehow the ConfigParser uses else when trying to parse the config.

Number:Power H1_SolarEdge_TotalImportPower "Total Import Power" (H1_SolarEdge) { 
    channel="modbus:meter-wye-phase:solaredge1:meter:acGeneral#ac-total-real-power", [profile="transform:JS", toItemScript="solaredge_LiveImport.js", toHandlerScript=""]

comer space

@MartOs have you managed to resolve this issue? Which version of openhab are you running?

I think so. I’ve been trying to figure it out before replying.

Maybe it was just a case of the items not clearing and reloading properly. I have restarted since then and the following seems to be working for me now

Number:Energy H1_SolarEdge_AggregateLifetime_Import_test "_test Lifetime Import 1 [%.3f %unit%]"  { 
    channel="modbus:meter-single-phase:solaredge1:meter:acGeneral#ac-total-imported-real-energy"[profile="transform:JS", toItemScript="SE_ErrorCatch_Import.js", toHandlerScript=""] 

I’ve just submitted a PR to fix this issue

BTW @MartOs you can omit toHandlerScript="" in your config file if you aren’t setting it to anything.


Thanks. Good job.

I think there is a similar issue with things text files. I have to restart to apply updates to a handful of modbus things I have in text files.

When I omit toHandlerScript=“” it shows ‘NA’ in the UI instead of just a blank space. Haven’t tested this specifically if it actually works when omitted, but it looks different to a UI configured item

I’ve also just submitted a PR to fix update behaviour with .things file. However, the problem was that everything in the file got updated instead of just the one being changed. So if you changed something, it would’ve been applied without restarting openhab.

If you could provide steps to reproduce your .things file issue, please let me know, maybe open a separate topic?

1 Like