Modbus Transform

Tags: #<Tag:0x00007fc8f67de620> #<Tag:0x00007fc8f67de440> #<Tag:0x00007fc8f67de350>

ok well I have come up with another fun modbus config question I am trying to JS transform a number I am receiving but it’s not working :confused: I have tried two different ways. The number is 6.10HZ the register returns 61 so I am dividing it by 10 the multiplying it by 60 to get RPM. When I have the JS inside the quotation marks it kicks an error when I have it outside the quotation marks it does nothing and I see the raw number.
HZ_RPM.js

(function(i){ return Math.round(i / 10 * 60); })(input)
Number Fan1RPM_H "Compressor Exaust Fan RPM [%d]" (modbus_raw,modbus) {modbus="slave5:0":JS(HZ_RPM.js)}
Number Fan1RPM_H "Compressor Exaust Fan RPM [%d]" (modbus_raw,modbus) {modbus="slave5:0:JS(HZ_RPM.js)"}

here is the error

org.openhab.model.item.binding.BindingConfigParseException: Register references should be either :X or :<X:>Y
        at org.openhab.binding.modbus.internal.ModbusGenericBindingProvider$ModbusBindingConfig.<init>(ModbusGenericBindingProvider.java:207) ~[na:na]
        at org.openhab.binding.modbus.internal.ModbusGenericBindingProvider.parseBindingConfig(ModbusGenericBindingProvider.java:108) ~[na:na]
        at org.openhab.binding.modbus.internal.ModbusGenericBindingProvider.processBindingConfiguration(ModbusGenericBindingProvider.java:91) ~[na:na]
        at org.openhab.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:348) [org.openhab.model.item_1.8.1.jar:na]
        at org.openhab.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:324) [org.openhab.model.item_1.8.1.jar:na]
        at org.openhab.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:171) [org.openhab.model.item_1.8.1.jar:na]
        at org.openhab.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:390) [org.openhab.model.item_1.8.1.jar:na]
        at org.openhab.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:159) [org.openhab.model.core_1.8.1.jar:na]
        at org.openhab.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:100) [org.openhab.model.core_1.8.1.jar:na]
        at org.openhab.model.core.internal.folder.FolderObserver.checkFolder(FolderObserver.java:142) [org.openhab.model.core_1.8.1.jar:na]
        at org.openhab.model.core.internal.folder.FolderObserver.run(FolderObserver.java:99) [org.openhab.model.core_1.8.1.jar:na]

I am able to do it in a rule but it gets messy in the rules after a while and I have to make a new rule and output item for every item that needs the transform.

rule "fan div10 division"
when
	Item Fan1RPM_H received update
then
	var Number temp = (Fan1RPM_H.state as DecimalType) 
        temp = temp / 10 * 60
	postUpdate(Fan1RPM_div, temp)
end

Indeed putting in the modbus configuration string will not work and in that way modbus binding seems to be different from http (see transformations page in the wiki).

As a workaround, I wonder if it possible to have the transformation in the label string

In the wiki there is quite interesting snippet

Number WuUvCode "UV Level [SCALE(uvindex.scale):%s]"

I understand that the “scale transformation service” is not what you need but could similar syntax be used with javascript transformation service? Thanks

1 Like

it worked.

Number Fan1RPM_H "Compressor Exaust Fan RPM high [JS(HZ_RPM.js):%d]" (modbus_raw,modbus) {modbus="slave5:0"}

Spoke too soon… because the transform is essentially in the sitemap and not the item the number recorded is the raw number and not the transformed number. when charting I see 63 instead of 372

I see. So the label thingie really just changes the display.

I propose you post a new feature request to github on supporting transformations in the modbus binding. It might fit well what @w2vy is currently doing.

edit: for the record, tcp binding seems to have pretty much something we want.

I have no clue how transformations work nor do I understand how the “[JS(HZ_RPM…” works

so I am not sure which thing I am currently doing you are referring to…

Submitted… Issue #4204