[SOLVED] Can a transform access other items?

Is it possible to use the values from two items in a single command?

I’m trying to migrate my lights off the Hue hub and onto MQTT via zigbee2mqtt. I’ve got dimmer switches working great, and now I’m working on the lamps, and I hit a snag. I’ve got a brightness slider configured, and it changes the brightness ok, but I’d like to have control of the transition time. I can hardcode this in the output format for the channel:

This isn’t very flexible though, and I’d much rather be able to control the transition time through another item. I can’t see how it is possible to do this in item configuration. Is it possible for a transform to pull in values from other items? Is there some other trick I’m missing? Or is the only way to publish raw commands onto the MQTT broker through rules?

A Rule. Create Text MQTT Thing and combine the states of the two Items into one outgoing String in a Rule.

You cannot reference the state of another Item in a Thing’s definition.

Thanks, I was just starting to think along those lines, and it works decently. I also had to add a get channel and item in order to ask MQTT for the item state because it wasn’t getting updated after the transition time. I ended up with this:

Items:

Number Hue_OfficeLamp_Brightness                    "Brightness"                            { channel="mqtt:topic:b80400aa:brightness"}
Number Hue_OfficeLamp_TransitionTime                "Transition time"
String Hue_OfficeLamp_Command                       "Command"                               { channel="mqtt:topic:b80400aa:command"}
String Hue_OfficeLamp_Get                           "Get"                                   { channel="mqtt:topic:b80400aa:get"}

[{"id":"d36bb0f3.c22d8","type":"change","z":"2368f2dd.7ffe86","name":"Use brightness","rules":[{"t":"set","p":"command.brightness","pt":"msg","to":"payload.payload.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":120,"wires":[["aa44bd51.54231"]]},{"id":"aa44bd51.54231","type":"openhab2-get","z":"2368f2dd.7ffe86","name":"get transition time","controller":"8d5b202.2cf62e","itemname":"Hue_OfficeLamp_TransitionTime","x":510,"y":120,"wires":[["84f00198.3ec4a8"]]},{"id":"84f00198.3ec4a8","type":"change","z":"2368f2dd.7ffe86","name":"Use transition time","rules":[{"t":"set","p":"command.transition","pt":"msg","to":"payload.state","tot":"msg"},{"t":"set","p":"delay","pt":"msg","to":"$number(msg.payload.state) * 1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":120,"wires":[["e09b630.0a989a"]]},{"id":"de5f6187.b95428","type":"openhab2-out","z":"2368f2dd.7ffe86","name":"","controller":"8d5b202.2cf62e","itemname":"Hue_OfficeLamp_Command","topic":"ItemCommand","payload":"","x":780,"y":180,"wires":[["e76a84e2.d90a3"]]},{"id":"e09b630.0a989a","type":"json","z":"2368f2dd.7ffe86","name":"Format as json","property":"command","action":"str","pretty":false,"x":380,"y":180,"wires":[["f4c78f5a.ecf818"]]},{"id":"4b62ca94.3ffe5c","type":"switch","z":"2368f2dd.7ffe86","name":"filter for commands","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"ItemCommandEvent","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":60,"wires":[["d36bb0f3.c22d8"]]},{"id":"f4c78f5a.ecf818","type":"change","z":"2368f2dd.7ffe86","name":"Set the payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"command","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":180,"wires":[["de5f6187.b95428"]]},{"id":"e76a84e2.d90a3","type":"delay","z":"2368f2dd.7ffe86","name":"delay by transition time","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":450,"y":240,"wires":[["33528c3d.35779c"]]},{"id":"33528c3d.35779c","type":"openhab2-out","z":"2368f2dd.7ffe86","name":"Refresh values","controller":"8d5b202.2cf62e","itemname":"Hue_OfficeLamp_Get","topic":"ItemCommand","payload":"","x":680,"y":240,"wires":[[]]},{"id":"90dd043b.a29a","type":"openhab2-in","z":"2368f2dd.7ffe86","name":"","controller":"8d5b202.2cf62e","itemname":"Hue_OfficeLamp_Brightness","x":140,"y":60,"wires":[[],["4b62ca94.3ffe5c"]]},{"id":"8d5b202.2cf62e","type":"openhab2-controller","z":"","name":"OpenHab","protocol":"http","host":"localhost","port":"8080","path":"","username":"","password":""}]