Would a multiply/math transformation make sense

I have some items where I have to convert from w to kw, would it make sense to create a transformation for this, it works with rules but I need an extra item and a rule.

A transformation would make this easier, what do you think?

Some examples:

http="<[http://example.com/var/value:60000:MULTIPLY(1000)]" }
http="<[http://example.com/var/value:60000:MULTIPLY(0.001)]" }

Alternative:

http="<[http://example.com/var/value:60000:MATH("(VALUE * 11) + 1")]" }
http="<[http://example.com/var/value:60000:MATH("VALUE / 1000")]" }
1 Like

Please note that the one with real math is very complex, maybe https://github.com/uklimaschewski/EvalEx could be used as implementation.

For my use case MULTIPLY would be enough and its extremely simple to implement.

I do remember a question in here asking for an ā€œaddā€ transformation.
So, I would find a transformation for single and simple math functions usefull. If one is really in the need for a more complex math function, there is always the possibility of using a rule.

I will check if can offer all simple ones by a single binding, that could even be as simple as adding multiply and add. The rest can be inverted / derived.

@Kai @sjka would it be ok / make sense to offer multiple simple math transformations in a single binding, i.e. having multiple files like https://github.com/eclipse/smarthome/blob/master/extensions/transform/org.eclipse.smarthome.transform.regex/OSGI-INF/regexservice.xml

A PR:

A test version:

https://github.com/eclipse/smarthome/files/1050737/org.eclipse.smarthome.transform.simplemath-0.9.0-SNAPSHOT.jar.zip

And a README

I just realized (some sleep does miracles) that the transformation does not suffice for my goal :blush:

My actual need is to create a graph based on the transformed number and it seems that I cannot transform on the channel, so the actual stored number is not converted.

If there are ways, please share :slight_smile:

The presently working way would be using a seperate item. This item could be updated by a rule, which in turn would make the (math) transformation useless.:blush:

Hi,

@martinvw already knew that, the idea was to avoid that kind of setup!
The only way I see that can solve Martinā€™s requirement is to transform the respective value when persisting (trigger in the database)

BR,
George

I did have some programming fun anyway, maybe it is useful for others lets see the responses on my PR :slight_smile:

1 Like

If someone has use cases for this, which are not about unit conversion please share them in the PR, because there are some doubt about the usefulness:

Thanks!

Martin - is this PR merged into openHAB now or was it decided to not add it after all? If itā€™s in openHAB, do the ā€˜MATHā€™ transform modifiers actually change the value of the item or just the display of the value?

One of my remote temperature sensors reports a value that I know is not accurate. When the MQTT message arrives, the Item receives the value and I display it in my Sitemap. I have a Rule that uses the sensor value and I have a line in the Rule to adjust the reading before I act on the value.

I could update the Itemā€™s value in the Rule so that the correct value is in the Itemā€¦ but updating the value will trigger the Rule (i.e., the Item was updated and it changed) thus a race condition. Having the ADD modifier in the transform would allow me to change the value when it is updated by a new MQTT message.

I have seen that a JS transform could accomplish this, but I have never used thatā€¦ and I donā€™t know how to write the associated script. My preference would be to have one transform approach for all of my temperature sensors. The JS would have to code which sensors should be adjusted and which should not. Yes, if I use your suggested enhanced transform, Iā€™d have different syntax for each Itemā€¦ but it would be right up front in my Items definition and not tucked away in a script.

Regards.

Mike

Its closed without merging, so its not included anywhere