Profile transformation in item channels - does someone use it successfully?

Hi all,
after a longer while I started updating to 2.3 and in the transformation documetation I found a section saying transformations for inbound channels, e.g like that:

String <itemName> { channel="<channelUID>"[profile="transform:JS", function="<filename>", sourceFormat="<valueFormat>"]}

I have tried various combinations and I can’t get my RSSI value transformed for the item:

Number SSHeizungFlurStrasse2 "Test" <qualityofservice> (gSignalStrength) { channel="homematic:HM-CC-RT-DN:OEQ0458727:OEQ0844182:0#RSSI_DEVICE" [profile="transform:JS", function="rssi.js"] }

rssi.js

(function(i) {
var Wert1 = Math.abs(i);
var Rueck = 0;
if ( Wert1 < 1 ) Rueck = 0;
if ( Wert1 > 1 && Wert1 <=25 ) Rueck = 1;
if ( Wert1 > 25 && Wert1 <=50 ) Rueck = 2;
if ( Wert1 > 50 && Wert1 <=75 ) Rueck = 3;
if ( Wert1 > 75 && Wert1 <=100 ) Rueck = 4;
return Rueck;
})(input)

If I do the transformation in the label it works - but I do not get the dynamic icons to work as the item.state is a negative number.

Any hep would be very much apreciated. & THX in advance!
Stefan

Grumble, I thought this was fixed!

OK, when you go to the OH docs you are looking at the latest and greatest docs, meaning the documentation for OH 2.4 SNAPSHOT. At the upper right you will see a little box that says “Version:Latest”. Select 2.3 from that list and you will see the docs for 2.3.

Applying transformations to arbitrary channels like this is not available in OH 2.3. In fact, I’m not certain it is even available in the most recent milestone release. You may need the latest snapshot.

soon :slight_smile: Docs and Addons should display the release version by default · Issue #815 · openhab/openhab-docs · GitHub

I should have looked at the date of the comments. I thought that issue had gone fallow and ignored. I just added a comment to it to boost it to people’s attention again. Guess it is already being taken care of. Good! :slight_smile:

1 Like

Greatly appreciated your help here! Even though I might need some help getting the dynamic icos working on the sitemap. I understand doing the transformation is for the view only - nevertheless I have all RSSI values nicely transformed to 0,1,2,3,4s - and the item.state being e.g. “-65” which I can’t get working with my items. Any advice on how to map negative values to dynamic icons? … ah, writing this, rules come to mind - being the lazy type and having over 20 RSSI items… i’ be looking form something more elegant than writing a rule for each item… Any other idea someone?

Starting with openHAB 2.3, you can use the MemberOf group identifier in your rules - so you’d only need to write one rule, group your 20 items into one group, and the one group would work for all cases :slight_smile:

You should change this to “<=”, as an input of 1 fails your check currently. The fact Rueck is set to 0 at the start means it doesn’t really matter and you’ll get what you meant (0), but it’s bad practice to leave gaps between range checks. Technically, the last check should also just be “> 75” with no upper bound, in case you get “101” as an input :wink:

1 Like

Bartus, thx a lot - i had a look at the groups and triggering item rules recently - and seems I missed the goodies :slight_smile: > Will have a look again & thx for your comments on the code - makes all sense. Stefan

hm, “Member of…” triggers do not seem to be in 2.3 … at least I haven’t found it in the docs -. and repectively it does not work (trigger rule to fire) … considering an update.

edit (again) they should be on 2.3.0 Stable

see: Design Pattern: Working with Groups in Rules - #70 by Nicholas_Waterton

and: Rules | openHAB

This: Allow binding DSL Rules to all items contained in a group by jmsjones · Pull Request #4800 · eclipse-archived/smarthome · GitHub was merged on Jan/18 and OH2.3 stable was released on May/18, so it should be there

Well, you are right - it seems they are triggered - but items change rarel< - why i did not see any effect. Interstingly the 2.3. documentation does not list the triggers (same spot wheer 2.4 docu lissts them)

latest

long, painful story :slight_smile:

most of us (including me) update only the latest version (2.4) of the docs on the master branch (even when the updates apply to both 2.3 and 2.4).

Ps: don’t let @Confectrician see this :slight_smile:

2 Likes

no offense :slight_smile: - THX for helping and the great work!

1 Like

Theoretically we would have to cherry pick those pull requests to the stable docs and then re tag so the build recognizes them.
That’s really much effort, to be honest.

So I am blaming no one for not adding stuff to the stable docs. :smile:

1 Like

I’m not sure that I understand the purpose of the profile function as it is not working as expected for me. I’m using with MQTT Binding with a Switch item and trying to transform a command “off” to “OFF” as Openhab does not recognize lowercase.

String <itemName> { channel="<channelUID>"[profile="transform:JS", function="<filename>", sourceFormat="<valueFormat>"]}

Smartthings sends MQTT “off” or “on”. The profile below is intended to transform these values to “OFF” or “ON”, but openhab is reporting it can not apply the “on”/“off” commands to item.

Switch KitchenLightSwitch "Kitchen Light" {channel="mqtt:topic:MqttBroker:SmartthingsMqttThing:KitchenLightSwitch" [profile="transform:MAP", function="smartthings.map"]}

smartthings.map

on=ON
off=OFF
locked=ON
unlocked=OFF

A related question: Why does my switch item through sitemap send a “1” or “0” to the MQTT broker when “ON” and “OFF” are the valid item states? I was able to deal with this by editing the Smartthings smart app, but it just seems oddly inconsistent.

Running version 2.4

First of all, this can be done in the Channel config for the MQTT 2 binding.

Just put “on” in the “On/Open Value” section and “off” in the Off/Closed Value section.

A Profile is overkill for this.

You would have to show your Thing and Item definitions for one that is behaving like this.

I appreciate the quick response Rich. Can you confirm that I’m using profile incorrectly?

I have bindings defined in addons.cfg. “binding = mqtt” I can’t find the any configuration in the paper UI for the binding.


My item is in previous post. Thing below:

Bridge mqtt:broker:MqttBroker [ host="192.168.86.63", secure=false ] 
{
	Thing topic OpenhabMqttThing {
    	Channels:
    		//Topic = alarm/mode/state(or)set. Openhab reads stateTopic and publishes to commandTopic
        	Type number : alarmmode "Alarm Mode" [ stateTopic="alarm/mode/state", commandTopic="alarm/mode/set" ]
    }

    Thing topic SmartthingsMqttThing {
        Channels:
            //Topic = alarm/mode/state(or)set. Openhab reads stateTopic and publishes to commandTopic
            Type string : SideDoorLock          "Side Door Lock" [ stateTopic="smartthings/Side Door Lock/lock/state", commandTopic="smartthings/Side Door Lock/lock/cmd" ]
            Type dimmer : KitchenLightDimmer    "Kitchen Light Level" [ stateTopic="smartthings/Kitchen Light/level/state", commandTopic="smartthings/Kitchen Light/level/cmd" ]
            Type switch : KitchenLightSwitch    "Kitchen Light Switch" [ stateTopic="smartthings/Kitchen Light/switch/state", commandTopic="smartthings/Kitchen Light/switch/cmd" ] //, on="on", off="off"
    }

}

I see the channel configuration now. I was looking for a binding config. Can I edit the paper ui config if thing is defined in .things file?

Any documentation on how to define these parameters in the .things file?

Edit: updated image. I’m not sure how the “1”/“0” got here, but that answers that question.

Probably not. All I know about them is what I’ve read in the docs. From what I can tell the syntax at least looks fine.

There is no separate configuration. Create Things as documented at:

No.

There might be examples on the forum. I don’t use .things files so I don’t know. I also know the binding developer doesn’t use .things files either.

Solved my issue:

Type switch : KitchenLightSwitch    "Kitchen Light Switch" [ stateTopic="smartthings/Kitchen Light/switch/state", commandTopic="smartthings/Kitchen Light/switch/cmd" , transformationPattern="MAP:smartthings.map" , on="ON", off="OFF"

I initially had some trouble understanding application of “MQTT Generic Thing - Bindings” documentation and examples, but my solution was within the examples.

I discovered that ON/OFF config defaults to 1/0 if not specified and updating the text configuration doesn’t immediately update channel, so restart may be required.

1 Like