False Z-Wave Power Meter Readings

It’s just string formatting, as used in many places throughout openHAB, and so it is the java string format style. %s would be the generic example.
It would not be any help here.

Many of these little hints and tips appear when you use the GUI to set things up, which of course you don’t get when choosing file configurations.

OH documents are editable by all, link at the bottom of every page, few bother even though the viewpoint of ‘unfamiliar user’ would help others…

1 Like

Ok, how does this look?

// filter to not capture values that are negative or over 1800w
(function(i) {
	var string = i;
    var val = parseFloat(i);
    if (string == 'UNDEF')
       { return string; }
	if (val > 1800 || val < 0 )
        { return 'UNDEF'; }
            {return val + 'W'; }	
} )(input);

It seemed to test out ok via a JS tester online.

So I have banged my head against the wall pretty thoroughly and figured I would go back to basics and see if I could simply take in an input, and return it back out in my JS transform. Well, so far I have been unable to do even that. My best guess based on reading a lot and your tips (you are a super active contributor here!), is that the issue is that my channel and item are dealing in a QuantityType (In this case Number:Power) but the JS Transformation can only accept and output Strings. Does that sound right? Is there any known way to handle this?

Your script looks reasonable, though I would append " W" not “W” to the end result.

But I’ve just realised that you are on openHAB version 2 still.
Transformation profiles are limited to only working with String Items in
OH2, so you can’t do it this way after all.
It’ll work to a String type Item, but that is probably no use to you, can’t chart it etc.

You’ll have to go via a rule and an interim Item. Rule to be triggered from update and do basically what your JS does to update another Number:Power type Item

Yes, using OH 2.5.12 as I had seen that OH3 had some issues - is it more stable now? What would the uplift to move platforms look like? This is a pretty consistent issue I would want addressed as I currently use OH primarily for reading these power readings from my various meters around the house and then I persist them to InfluxDB and chart them so I can easily monitor things and get trending data. This example from today shows the problem I desperately need to address…This reading was from a 120v/200a clamp (one side of a ZW095 meter).

Most of the threads on this forum for the last six months relate to OH3, it’s the primary version now. I can’t assess it for you.

If you don’t want to go OH3 the rule and ‘dummy’ Item method is easy enough.

I have reattempted OH 3.1 and now that I understand the java and variables better in Windows it has started, will see about migrating over now. Thanks

After trying to make this work in OH 2.5, OH 3.1 feels like cheating it is so much more straightforward :smiley:

1 Like