[SOLVED] Item JS Transform Determine which Item "invoked" the javascript?

Number denTemperature { mqtt="<[broker:shellies/<denSensor>/sensor/temperature:state:JS(tempSensor.js)]" }
Number bedroomTemperature { mqtt="<[broker:shellies/<bedroomSensor>/sensor/temperature:state:JS(tempSensor.js)]" }

tempSensor.js (pseudo code)

(function(i) {
    if (itemName contains "DEN")
        return (parseFloat(i) - 1.0)
        return (parseFloat(i) - 0.5)

Is it possible for the script to determine which Item is calling it? I’d like to do something like my pseudo code script.

Alternatively, is it possible to code an argument in the Item definition that gets passed to the script?

Number denTemperature { mqtt="<[broker:shellies/<denSensor>/sensor/temperature:state:JS(tempSensor.js):"DEN"]" }
Number bedroomTemperature { mqtt="<[broker:shellies/<bedroomSensor>/sensor/temperature:state:JS(tempSensor.js):"BEDROOM"]" }



Neither options are possible as far as I know. You will have to move to proxy items and a Rule to do this.

Nothing ventured, nothing gained :wink: Was hoping to avoid the extra hop.



If you were using MQTT v.2, an offset profile could be used on the channel.

I’ll get there (MQTT2) eventually… maybe kicking & screaming, but I’m sure it’ll be inevitable at some point when MQTT1 begins to feel its unsupported age (hopefully way) down the road :wink:

With an offset profile, I can have one profile that can determine which device to apply which specific offset to? Or would I have to define a different profile (with its device specific offset) per Thing?

That one, a profile applies to a channel

Then it’s the same as requiring a separate script per Item… and not an improvement on consolidating the logic for a set or “related” Items to a single module to update/maintain. I need the script/profile to act on the received data before the Item is updated. Changing it afterwards requires a proxy/Rule setup, as Rich mentioned.

This (Would a multiply/math transformation make sense) looked promising, but alas, it was not adopted.


Doesn’t require any scripts per Item.
Number myItem { channel="blah"[profile="offset", offset="-0.5"]}

Ah, I misunderstood from reading. I thought I had to create my own “offset profile”. I missed that the “offset profile” is a built in feature. That fits the bill exactly.

Now to tackle MQTT2 :wink:

It’s all a bit new and there aren’t many examples yet.

I want a “factor” version - “x10” , “/100”, etc. :smiley: