[Solved] State Transformation

transformations
sitemap
items
Tags: #<Tag:0x00007f51e4b0daf0> #<Tag:0x00007f51e4b0d8e8> #<Tag:0x00007f51e4b0d7a8>

(Andreas) #1

I have an EnOcean window handle that sends the following states once you turn it basically “full circle”:
closed --> open --> tilted --> open_from_tilted --> closed

In my sitemap, I would like to use the contact icon set (contact, contact-closed, contact-open, contact-ajar) in order to show the status. However, I am struggling with state transformation. Right now, my item definition is as follows:

String ug_sz_sensor_fenster “Spielzimmer [%s]” {mqtt="<[mosquitto:ug/sz/sensor/fenster:state:closed:closed],<[mosquitto:ug/sz/sensor/fenster:state:open:open],<[mosquitto:ug/sz/sensor/fenster:state:open:open_from_tilted],<[mosquitto:ug/sz/sensor/fenster:state:open:tilted]"}

The corresponding sitemap definition is as follows:

Text item=ug_sz_sensor_fenster

As you can see from the item defintion, the different states distinguishes between open and closed. However, I would like to see “tilted” in my sitemap whenever the window is tilted. That should go in conjunction with the contact-ajar icon.

How am I supposed to do the state transformation?


(Rich Koshak) #2

Use a map to transform the “tilted” and “open_from_tilted” Strings to “ajar”. You can either do the transform on the mqtt configs (last element I believe) or do it in the label: [MAP(contact.map):%s]

See http://docs.openhab.org/configuration/items.html#state-transformations

Or change what is reporting the state to use “ajar” instead of “open_from_tilted” and “tilted”.

Or create a couple copies of the icon named contact-ajar.png and contact-open_from_tilted.png (use svg copies if you are using svg icons) http://docs.openhab.org/configuration/items.html#icons


(Andreas) #3

Hi @rlkoshak

It’s partly working, i.e. the icon is changing correctly when doing the correct transformation within the MQTT binding, such as:

String eg_wz_sensor_fenster2 “Wohnzimmer 2 [%s]” {mqtt="<[mosquitto:eg/wz/sensor/fenster2:state:closed:closed],<[mosquitto:eg/wz/sensor/fenster2:state:open:open],<[mosquitto:eg/wz/sensor/fenster2:state:open:open_from_tilted],<[mosquitto:eg/wz/sensor/fenster2:state:ajar:tilted]"}

Now, I am facing the problem that I do see “ajar” as a written status next to the correct icon on my sitemap where I actually want to see “tilted”. I then created an “EnOcean_window_handle.map” with the following content:

closed:closed
open:open
ajar:tilted

I changed the item definition to

String eg_wz_sensor_fenster2 “Wohnzimmer 2 [Map(EnOcean_window_handle.map):%s]” {mqtt="<[mosquitto:eg/wz/sensor/fenster2:state:closed:closed],<[mosquitto:eg/wz/sensor/fenster2:state:open:open],<[mosquitto:eg/wz/sensor/fenster2:state:open:open_from_tilted],<[mosquitto:eg/wz/sensor/fenster2:state:ajar:tilted]"}

However, the status is still shown as “ajar”. Is it possible that the transformation within the MQTT binding has precedence of the .map file?


(Rich Koshak) #4

No, the mqtt binding dictates the state of the Item. The label MAP dictates how the state appears on your sitemap.

One thing to note is that the icon chosen is based on the transformed label so if you do get the label to say tilted your icons will stop working. (unless this changed again).

Rather than having four MQTT configs, why not use a transformation like you are with the icon. Then you would only need the one mqtt config.

Do you actually have the Map transform installed?

Are you seeing errors in the log?


(Andreas) #5

Good point. What would then the correct syntax for the MQTT biding look like?

Hmmm, probably not, i.e. I didn’t install it on purpose. I am using openhabian, so if it didn’t come along with it, this might be the reason. How can I install it or at least check whether it is already installed?


(Rich Koshak) #6

Through PaperUI like any other addon. It is listed in the Transformations folder.

From the docs:

Item myItem {mqtt="<direction>[<broker>:<topic>:<type>:<transformer>:<regex_filter>]

transformation[:] Rule defining how to transform the received message content into something openHAB recognizes. Transformations are defined in the format of TRANSFORMATION_NAME(transformation_function). Allowed values are ‘default’ or any of the transformers provided in the org.openhab.core.transform bundle. Custom transformations can be contributed directly to the transform bundle by making the Transformation available through Declarative Services. Any value other than the above types will be interpreted as static text, in which case the actual content of the message is ignored.

From this we see it should be:

String eg_wz_sensor_fenster2 "Wohnzimmer 2 [Map(EnOcean_window_handle.map):%s]" {mqtt="<[mosquitto:eg/wz/sensor/fenster2:state:Map(window.map)]"}

And your map file would be:

closed=closed
open=open
open_from_tilted=open
tilted=ajar

Not the use of = instead of :. I don’t know if : will work which could explain your other problem. I would expect to see errors in the logs for that.


(Andreas) #7

Yes, it is installed. However, I also do see some Map related entries in the log.

==> /var/log/openhab2/openhab.log <==
2017-06-27 08:13:00.123 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type Map
2017-06-27 08:13:00.127 [WARN ] [.core.transform.TransformationHelper] - couldn’t transform value because transformationService of type ‘Map’ is unavailable


(Rich Koshak) #8

Hmmm. The error indicates it is not installed.

First, try using “MAP” instead of “Map”.

If that doesn’t work try uninstalling it, restarting OH, then reinstalling it.


(Andreas) #9

That did the trick! Using a transformation within the configBinding is also useful. The whole solution follows.

My item file now looks like this:

String eg_wz_sensor_fenster2 “Wohnzimmer 2 [MAP(EnOceanWindowHandle_label.map):%s]” {mqtt="<[mosquitto:eg/wz/sensor/fenster2:state:MAP(EnOceanWindowHandle_configBinding.map)]"}

The .map files are as follows:

EnOceanWindowHandle_label.map (German translation)

closed=geschlossen
open=offen
ajar=gekippt
-=unbekannt

EnOceanWindowHandle_configBinding.map

closed=closed
open=open
open_from_tilted=open
tilted=ajar

Now, the final problem is a non-functional icon. However, you already mentioned what the problem is:

So, I donwloaded the contact*.svg files from https://github.com/eclipse/smarthome/tree/master/extensions/ui/iconset/org.eclipse.smarthome.ui.iconset.classic/icons and saved them under openHAB-conf/icons/classic and renamed them accordingly, i.e.

  • contact.svg
  • contact-geschlossen.svg
  • contact-offen.svg
  • contact-gekippt.svg

Now, the icons are working properly.

@rlkoshak Thanks a lot for your help! I appreciate it.


(Alexandr) #10

I have Item:

Number brz_Settings_Mode "Settings_Mode [MAP(ModeSet_label.map):%.0f]" {mqtt="<[localmqtt:breezart/vent/STATUS:state:JSONPATH($.Settings.Mode)]"}

What should I write after :state:?
Thanks


(Rich Koshak) #11

what did the message look like? what part of the message do you want?


(Alexandr) #12

after :state:
I have JSONPATH transform.
I don’t understand.
How to write MAP if I have transformation


(Rich Koshak) #13

I repeat, what does the message look like? What part of the message do you want. I can’t tell you how to write ModeSet_label.map if I don’t know what you are mapping from and to.


(Alexandr) #14

Dynamic icon don’t work.
I need this trick:

String eg_wz_sensor_fenster2 “Wohnzimmer 2 [MAP(EnOceanWindowHandle_label.map):%s]” {mqtt="<[mosquitto:eg/wz/sensor/fenster2:state:MAP(EnOceanWindowHandle_configBinding.map)]"}

EnOceanWindowHandle_label.map (German translation)

closed=geschlossen
open=offen
ajar=gekippt
-=unbekannt

EnOceanWindowHandle_configBinding.map

closed=closed
open=open
open_from_tilted=open
tilted=ajar


(Rich Koshak) #15

That will only work if the message coming from breezart/vent/STATUS is closed, open, and ajar. The fact that you originally had a JSONPATH transformation that means that is probably not the case and you are getting a full JSON message and the JSONPATH transformation is extracting one piece of data.

So again, what is the message you are receiving? What are the possible values that are being extracted using JSONPATH?


(Alexandr) #16

I’m sorry. I do not understand what you ask.

Resieved JSON from mqtt:

{"ContVer": "3.34.6", "TPDVer": "4.18", "Temperature": {"Current": 14, "Minimum": 15, "Target": 15}, "Settings": {"MaxTemperature": 40, "MaxSpeed": 8, "MinSpeed": 1, "isSceneBlock": false, "isShowHumidity": false, "isCascTempReg": false, "MinTemperature": 15, "MaxHumidity": 85, "isCooler": true, "MinHumidity": 30, "isVAV": false, "isAuto": true, "isHumidifier": false, "Mode": 1, "isRegPressVAV": false, "isCascHumReg": false, "NumZoneVAV": 2, "isPowerBlock": false}, "Scene": {"WhoActivate": 0, "SceneState": "OFF", "Block": "OFF", "Number": 0}, "DateTime": {"Date": "09-02-2019", "Time": "02:36"}, "State": {"ColorInd": 2, "AutoRestart": "OFF", "ChangeFilter": "OFF", "IconHF": 1, "Overheat": "OFF", "Power": "ON", "Warning": "OFF", "ColorMsg": 0, "Comfort": "OFF", "FilterDust": 0, "PowerBlock": "OFF", "Critical": "OFF", "AutoOff": "OFF", "Unit": "Включено"}, "Msg": "Работа   ", "Sensors": {}, "Humidity": {"Current": 0, "Auto": "OFF", "Mode": "OFF", "Target": 0}, "Speed": {"Current": 8, "SpeedIsDown": "OFF", "Actual": 255, "Target": 8}}
Number brz_Settings_Mode "Settings Mode [%s]"	<statemod> { mqtt="<[localmqtt:breezart/vent/STATUS:state:JSONPATH($.Settings.Mode)]" }

ModeSet_label.map:
1=heating
2=cooling
3=auto
4=vent

In /etc/openhab2/icons:
statemod.png
statemod-1.png
Both copied from https://www.openhab.org/iconsets/classic/fire.png

I want dinamic icons here:


(Rich Koshak) #17

You need to create an icon for each possible number that can be in the $.Settings.Mode filed along with a default.

Then you need to make sure your Item is actually working. The - indicates the Item is still NULL.

The MAP can’t help you because you cannot chain transformations. You can only have one and you need the JSONPATH transformation to get the Mode in the first place. You can use the MAP in the label, but the icons need to be based on the actual state of the Item.

Finally, make sure you have bitmap icons turned on. I think BasicUI uses svg icons by default.


(Alexandr) #18

Ouch…
I turned on bitmap icons and icons began to work.
I am very sorry. And thank you very much