Channels Types and Linked Items understanding

  • Platform information: Cubieboard
    • Hardware: CPUArchitecture/RAM/storage ARM/1GB/32GB

    • OS: _what OS is used and which version_ARCHLINUXARM

    • Java Runtime Environment: which java platform is used and what version(Zulu Embedded (build 1.8.0_121-b42)

    • openHAB version:2.4.0

I migrated from OH1 to OH2 and have a question about Channels and Items. And i little stuck with understanding chanel transformation and Item types.
I installed MQTT binding and add Generic MQTT Thing and few channels with JSON transformation. What type of channel i have to assign to channel? If before transformation it is allways STRING but after transformation it will be different (Number Colour etc…).
What profile of item i have assign to my channels? JSONPATH?

Some times my json data not include JSON field for this chanel
and i got error:

16:21:49.856 [WARN ] [al.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path ‘$.sensors.nrf1h1’ in ‘{“system”:{“hostname”:“Bar_NODE”,“uptime”:158400,“rssi”:-70,“freemem”:31264},“sensors”:{},“pwm”:{“0”:0,“1”:0,“2”:0},“gpio”:{“16”:0}}’
and my item assigned with this full JSON data. But i do not need update item if values with HUMIDITY do not present in JSON packet.

Where OPENHAB store items which i added from paper UI? Does it possible to edit it as text files in OH1 style?

I attach screenshot from my Channel config:

If you upgrade to at least OH 2.5 M1 you can use chained transformations and use a REGEX to filter out those messages that don’t have the HUMIDITY present and only pass those that do to the JSONPATH. See MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters


You can define your Items in .items files instead of through PaperUI. But you cannot edit Items defined through PaperUI in the OH1 style.

Thank you @rlkoshak! Does I need PaperUi to define things and channels for mqtt? Or do this in oh1 style item and linked binding without channels and things

You can define Things in .things files. There are lots of good examples in the binding docs.

There are also lots of good examples in many forum postings. But it is worth mentioning that the binding developer only defines Things through PaperUI so if you run into too much trouble you will likely need to rely on help from the forum. Personally, I define ALL my Things in PaperUI to take advantage of automatic discovery and not have two different ways to manage Things in my configuration.

You cannot avoid the use of Things and Channels for OH 2 bindings. Things and Channels are fundamental to the OH 2 architecture.

You might find a lot of useful information in the Migration Tutorial.

Thanks a lot @rlkoshak
How is the right way to use items in mqtt 2.x binding? Using paperui things i cannot discovery automatically but I can add it manual through PaperUi and add channels to it through PaperUi and link items in .items files. Does it right way?

That sounds reasonable.

1 Like

i just add in .items.
Number Lodge_Temp “Температура на балконе” {channel=“mqtt:topic:f024bb19:NRF1_Temperature”}

The transformation of incoming JSON data i set in PaperUI in channel propertie “Transform Values”

and in .sitemaps:
Text item=Lodge_Temp label=“Балкон. [%.2f °C]” icon=“temperature”

in logs i saw item updates:
Lodge_Temp updated to 14.0
But i see only:

Балкон. -

in BasicUI and androidd app. Another items in sitemap work correctly.
What i do wrong?

Do you see errors in openhab.log?

No errors, unfortunatelly-))

Have you refreshed the passage after you see the item getting updated?

The - means the item is NULL or UNDEF. But the events.log is showing the Item successfully updating.

Maybe create a rule the triggers on updates to the item and logging what it’s getting updated to. It’s hard to tell where the error is occurring.

1 Like

OK. I try to use rules for discovery problem.
Now I update oh to 2.5.0.m1 and will try to use chained transformation. How correctly write profile type in item definition for chained transform?

It’s not a Profile on the item. Chained transforms are only supported by the MQTT 2 binding. You will see a couple of sentences under the Channel config entry for the transform that explains how to do that.

1 Like

i just wrote simple rule which set my item to 100 if another item changed

22:55:59.078 [INFO ] [smarthome.event.ItemStateEvent       ] - Lodge_Temp updated to -68
22:55:59.383 [INFO ] [smarthome.event.ItemStateEvent       ] - Lodge_Temp updated to 100
22:55:59.421 [TRACE] [smarthome.event.ItemStateChangedEvent] - Received event of type 'ItemStateChangedEvent' under the topic 'smarthome/items/Lodge_Temp/statechanged' with payload: '{"type":"Decimal","value":"100","oldType":"UnDef","oldValue":"NULL"}'
22:55:59.435 [INFO ] [smarthome.event.ItemStateChangedEvent] - Lodge_Temp changed from NULL to 100

the item was NULL but i do not know why? i suppouse changed event did not fired

Did it change from NULL after that last event where it changed to 100 or is it still NULL?

Yes. Changed from NULL and correctly showed 100.00 in BasicUI.
In rule I use method Lodge_Temp.Postupdate(100)
Changed and updated this is not the same?

No, as with OH 1.x, there are three Item events, Commands, Updates, and Changes. An update does not necessarily mean there is a change. A command does not necessarily result in an update or a change and sometimes when there is a resultant update or change the update or change may be different from the command (e.g. sending an ON command to a Dimmer Item results in a PercentType update or change.