JavaScript rules: Access to channel information?

I’m wondering if it’s possible in some way to access Thing channels from a JavaScript rule?

The use-case is having a Thing like this:

UID: hdpowerview:hub:hub
label: PowerView Hub
thingTypeUID: hdpowerview:hub
configuration:
  host: powerview
channels:
  - id: automations#14214
    channelTypeUID: hdpowerview:automation-enabled
    label: God morgen, 06:25, Ugedage
    description: Aktiverer/deaktiverer automatiseringen 'God morgen'
    configuration: {}

and wanting to get the label of the channel automations#14214. Ideally I would find this channel through a linked item. When having access to the label, I could avoid hardcoding the local time “06:25” in my rules for switching between fixed time and sunrise, whichever comes last - described here: Automating Hunter Douglas PowerView automations

You will have to use the raw Java Objects.

things.getThing("hdpowerview:hub:hub").rawThing.getChannel("automations#14214").getChannels()

The above will get all the Channels of the Thing.

There is no easy way to get to the Channel through the Item. The Link between them is not a part of the Item nor is it part of the Channel. It’s a separate entity and there is no API exposed in rules to access them. You’ll need to use the REST API to query for all of the Links and find the ones (an Item can be a part of multiple Links) that involve that Item and from there you can get the Channel ID. You’ll still need to get the Thing and pull the Channel from the Thing.

Note, what you will get back from the above is a Java List<Channel> so you will have to use Java “stuff” to access and manipulate the list, not JavaScript.

Thanks @rlkoshak, that did the trick:

const timeRegex = /\b\d{2}:\d{2}\b/;

var channel = things.getThing("hdpowerview:hub:hub").rawThing.getChannel("automations#14214");
var match = channel.getLabel().match(timeRegex);

if (match) {
    var localTime = time.LocalTime.parse(match[0]);
    console.log("Time of day found: " + localTime);
} else {
    console.log("Time of day not found in label");
}