Profil js script - more parameter

OH 4.1 on Raspi 4

I check the presence of z-wave devices (battery flat even status is 100%) by setting a “life” switch item when data are send. Switch goes off after 25h, if it is not updated within time, showing device is dead.
For setting the “life” switch item I use profil js SCRIPT in the channel config.

(function(data) {
  items.LS01_LifeCheck.postUpdate('ON')
  items.LS01_LifeCheckTimestamp.postUpdate(Date.now())
  return data
})(input)

Is there any way to get more parameters into the function, like channel name etc. So I can have a universal code by assembling the item name as it is always LS01-LS05_LifeCheck or BW01-BW05_LifeCheck.

HI.

Not sure if I’m reading you right but i think i have an answer for you.

I have a JS Script below that is reused in multiple thing channels transformations

(function(data) {  
  var returnValue=null;
  if (data.substring(1,5) == blindAddress+"r") returnValue=data.substring(5,8);
  return returnValue;
})(input)

The value of blindAddress is set in the call to the transformation line like this.

JS:config:js:Trans_BlindCmd?blindAddress=SX6

So in your profile transformations, add a ?variablename=value to the end of the call to the transformation and then you can use variablename in your JS script.
I haven’t tried to use multiple variables but you can try seperating them with a ;

1 Like

Separate multiple parameters with a & just like in a URL

https://www.openhab.org/docs/configuration/transformations.html#script-transformation

transformation?arg1=val1&arg2=val2

2 Likes

Just as an example, if someone needs it.

(function(data) {
  itemname = name+'_LifeCheck';
  itemname_time = name+ '_LifeCheckTimestamp';
  items.getItem(itemname).postUpdate('ON');
  items.getItem(itemname_time).postUpdate(Date.now());
  return data;
})(input)

oh 4.3 snapshot

Hello again
Why is the profile ‚js‘ not applicable for switch items? The device does not react anymore.