# UDT on Mqtt Engine Tags

**URL:** <https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258>\
**Category:** Maker\
**Created:** [January 21, 2022, 5:03pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258 "2022-01-21T17:03:32Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![dp\_engsberg](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@dp\_engsberg](https://forum.inductiveautomation.com/u/dp_engsberg)\
**Post date:** [January 21, 2022, 5:03pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/1 "2022-01-21T17:03:32Z")

</div>

I’d like to create a UDT where the data is coming from similar valves via mqtt engine. I have setup the UDT properties using expression tags.  
Here is what a typical valve tag looks like, where the “C01A” is the valve name.  
{[MQTT Engine]Edge Nodes/tellus/ipusa/epic01/Strategy/Numeric Variables/C01A\_SAV\_domode}

Then I created a parameter string called ValveName.

So this is the expression I used so the tag uses the parameter value:  
like {[MQTT Engine]Edge Nodes/tellus/ipusa/epic01/Strategy/Numeric Variables/{ValveName}\_SAV\_domode}

For the tag instance I am testing with, the parameter is set to “C01A”  
But I’ve got something wrong because it is not substituting the value for the parameter, it is using the literal {ValveName}. I’ve tried an extra set (and even a third) of curley braces around {ValveName} within the expression, with no luck.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/e/2edb38d0e5c4e679d229fd088d9ed8608a42d11c.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 21, 2022, 5:10pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/2 "2022-01-21T17:10:54Z")

</div>

You cannot nest curly braces. Construct your outer tagpath as a string, concatenating with the inner curly braces. Supply that to the `tag()` expression function.

(The tag() expression function is a horrible hack to be avoided in all contexts other than expression tags, btw. IMNSHO.)

---

<div class="post-metadata">

**Author:** ![dp\_engsberg](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@dp\_engsberg](https://forum.inductiveautomation.com/u/dp_engsberg)\
**Post date:** [January 21, 2022, 5:15pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/3 "2022-01-21T17:15:49Z")

</div>

Are you saying I should not use an Expression Tag? What would be a better choice?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 21, 2022, 5:22pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/4 "2022-01-21T17:22:01Z")

</div>

No, an expression tag is the right answer. And the `tag()` function is the right answer in an expression tag. I’m just advising you to **not** use the tag() function in UI bindings.

---

<div class="post-metadata">

**Author:** ![dp\_engsberg](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@dp\_engsberg](https://forum.inductiveautomation.com/u/dp_engsberg)\
**Post date:** [January 21, 2022, 5:45pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/5 "2022-01-21T17:45:23Z")

</div>

It is close.  
I’m getting a conversion error.  
Error\_TypeConversion “The actual value was not able to be coerced into the configured data type for the source of this value.”

Here is the expression for the tag:  
concat("{[MQTT Engine]Edge Nodes/tellus/ipusa/epic01/Strategy/Numeric Variables/", {ValveName} , “\_SAV\_domode}”)

Here is the error showing up for the tag instance :  
Error\_TypeConversion(“Error trying to coerce ‘{[MQTT Engine]Edge Nodes/tellus/ipusa/epic01/Strategy/Numeric Variables/C01A\_SAV\_domode}’ to a number.”)

Can I explicitly tell it to covert to an integer somehow?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 21, 2022, 5:50pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/6 "2022-01-21T17:50:27Z")

</div>

The toInt() expression function, perhaps?

---

<div class="post-metadata">

**Author:** ![dp\_engsberg](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@dp\_engsberg](https://forum.inductiveautomation.com/u/dp_engsberg)\
**Post date:** [January 21, 2022, 6:52pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/7 "2022-01-21T18:52:13Z")

</div>

The toInt() is not able to do the conversion. I can pass a failover value to the toInt(), but that really doesn’t help. I wonder what is really going on?

I am puzzled.  
I set up two test UDT properties, one with the hard coded full mqtt path, and another with the concat function creating the same hardcoded full path.  
They produce the same expression string, but the hardcoded one works and the concat one errors.  
Do I have to do something to the result of the concat before it can be evaluated properly by the expression?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/c/2c62d748f04557ad3c83795e3e52b5b3627fadda.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 21, 2022, 6:55pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/8 "2022-01-21T18:55:18Z")

</div>

> [@dp\_engsberg](#):
>
> concat("{[MQTT Engine]Edge Nodes/tellus/ipusa/epic01/Strategy/Numeric Variables/", {ValveName} , “\_SAV\_domode}”)

Your expression is supplying a literal string, which is trying to be coerced into an integer.  
You need to wrap that entire expression in the `tag()` function to make it a dynamic lookup.

---

<div class="post-metadata">

**Author:** ![dp\_engsberg](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@dp\_engsberg](https://forum.inductiveautomation.com/u/dp_engsberg)\
**Post date:** [January 21, 2022, 7:18pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/9 "2022-01-21T19:18:11Z")

</div>

pturmel said that right off, but I did not understand.  
tag( concat("[MQTT Engine]Edge Nodes/tellus/ipusa/epic01/Strategy/Numeric Variables/", {ValveName}, “\_SAV\_domode”))

I just needed to pull the curley braces off the tagname. Working Now! Thank you very much.

---

<div class="post-metadata">

**Author:** ![dp\_engsberg](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@dp\_engsberg](https://forum.inductiveautomation.com/u/dp_engsberg)\
**Post date:** [January 21, 2022, 8:03pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/10 "2022-01-21T20:03:47Z")

</div>

I see from some other posts that writing to expression tags does not seem possible. I guess that makes sense. So I think that will be a problem with the UDT I’m try to put together. Is there an alternative way to approach this UDT to the MQTT Tags. The on/off devices for this UDT are Valves, Pumps, Motors - so being able to write is a big part of it.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 21, 2022, 8:24pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/11 "2022-01-21T20:24:19Z")

</div>

A derived tag is similar to an expression tag, but you define expressions for data to go in both directions.

---

<div class="post-metadata">

**Author:** ![FrankP](https://avatars.discourse-cdn.com/v4/letter/f/34f0e0/32.png) [@FrankP](https://forum.inductiveautomation.com/u/FrankP)\
**Post date:** [January 26, 2022, 4:45pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/12 "2022-01-26T16:45:15Z")

</div>

I’ve found myself using the tag() expression in UI elements more often lately. I’m curious to know why you recommend against using in that context and what alternative you prefer (if other than the standard indirect binding).

Thanks!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 26, 2022, 5:21pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/13 "2022-01-26T17:21:36Z")

</div>

Indirect binding is significantly more efficient than the `tag()` function due to eliminating recomputing string expressions. The `tag()` expression function also has a history of producing pathological CPU use, particularly in Perspective. (Much reduced in current v8.1, though.)

Adding a custom property for an indirect tag binding also make dependent expressions much easier to understand/maintain. Just say no to `tag()`.

---

<div class="post-metadata">

**Author:** ![cegge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cegge/32/74942_2.png) [@cegge](https://forum.inductiveautomation.com/u/cegge)\
**Post date:** [September 21, 2023, 7:22pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/14 "2023-09-21T19:22:13Z")

</div>

I know this conversation has been done for a while, but I am running into a project that has used the expression function tag() in a lot of places, we are seeing occasional runaway CPU and client lockups. I stumbled upon this post and I am wondering if you think it could be a reason and why?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 21, 2023, 7:37pm UTC](https://forum.inductiveautomation.com/t/udt-on-mqtt-engine-tags/55258/15 "2023-09-21T19:37:36Z")

</div>

Yes, because expression functions _ **must return a value** _. When starting up a binding, or dynamically changing the tag path, the tag value is not instantly available. `tag()` can do one of two things: **stall** for a result (which typically stalls the UI), or return "uncertain initial value". In the latter case, when the true initial value becomes available, the expression must execute completely again to pick it up.

Tag bindings (indirect or not) can simply do **nothing at all** until the proper value arrives, without stalling anything.
