# Convert Mqtt created string tags to number

**URL:** <https://forum.inductiveautomation.com/t/convert-mqtt-created-string-tags-to-number/25621>\
**Category:** Ignition\
**Created:** [June 6, 2019, 7:08pm UTC](https://forum.inductiveautomation.com/t/convert-mqtt-created-string-tags-to-number/25621 "2019-06-06T19:08:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris.roys](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@chris.roys](https://forum.inductiveautomation.com/u/chris.roys)\
**Post date:** [June 6, 2019, 7:08pm UTC](https://forum.inductiveautomation.com/t/convert-mqtt-created-string-tags-to-number/25621/1 "2019-06-06T19:08:47Z")

</div>

Hi  
I use Matt engine and get some tag from my plc. All tags which is created in mqttengine folder are string.  
I want to know what are best way to convert them to float easily so I can define history and alarm on them.  
Unfortunately my plc doesn’t support Matt sparkplug.

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [June 6, 2019, 9:24pm UTC](https://forum.inductiveautomation.com/t/convert-mqtt-created-string-tags-to-number/25621/2 "2019-06-06T21:24:13Z")

</div>

Caveat: I’m not familiar with your data source and there may be a better way to accomplish this. That said, would expression tags like this do the trick?  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/ca395e537dedef78643cc5e5a25631fcb480edb7.png)  
If your string tags have multiple values packed into them or other characters that need to be stripped out, that can be done in expression tags too. If you need a lot of these tags, you can create a script to go through the string tags and create the necessary expression tags for them.

---

<div class="post-metadata">

**Author:** ![chris.roys](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@chris.roys](https://forum.inductiveautomation.com/u/chris.roys)\
**Post date:** [June 7, 2019, 4:49am UTC](https://forum.inductiveautomation.com/t/convert-mqtt-created-string-tags-to-number/25621/3 "2019-06-07T04:49:52Z")

</div>

Hi  
Thanks. If I have UDT structure for my Mqtt tag list, is there any way to create the tags manually and link them to related topic like creating opc tag that need indicate the opc address?

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [June 7, 2019, 5:06am UTC](https://forum.inductiveautomation.com/t/convert-mqtt-created-string-tags-to-number/25621/4 "2019-06-07T05:06:37Z")

</div>

Can you share an example of your UDT structure?

---

<div class="post-metadata">

**Author:** ![chris.roys](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@chris.roys](https://forum.inductiveautomation.com/u/chris.roys)\
**Post date:** [June 7, 2019, 5:41am UTC](https://forum.inductiveautomation.com/t/convert-mqtt-created-string-tags-to-number/25621/5 "2019-06-07T05:41:20Z")

</div>

Yes.  
For example valve udt:  
Opened Boolean  
Closed Boolean  
Open command Boolean  
Close command Boolean  
Traveling Boolean  
Fault Boolean  
Position float

I want to use udt instead of automatically created mqttt tag in Matt engine.  
I can manually link them to my udt but this cause system use a lot resource( ones for Matt tag and one for udt tag)

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [June 7, 2019, 6:23am UTC](https://forum.inductiveautomation.com/t/convert-mqtt-created-string-tags-to-number/25621/6 "2019-06-07T06:23:19Z")

</div>

I’m sorry, I think I misunderstood your last question. You could definitely create a UDT with the boolean tags as derived tags and an expression tag that would convert the position string to a position float, but you probably already knew that. I’m not sure if you can replace the MQTT engine tags with UDTs and don’t have an MQTT device to play with. Someone else may weigh in with more knowledge.

Assuming you can’t replace the MQTT engine tags with UDTs and you also can’t get the MQTT engine to give you the position as a float (ideal solution), I’d guess making your UDTs with derived and/or expression tags shouldn’t be too hard on resources. If you have a lot of these to make, [system.tag.configure (Ignition 8)](https://docs.inductiveautomation.com/display/DOC80/system.tag.configure) or [system.tag.addTag (Ignition 7.9)](https://docs.inductiveautomation.com/display/DOC79/system.tag.addTag) is the way to go.

---

<div class="post-metadata">

**Author:** ![chris.roys](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@chris.roys](https://forum.inductiveautomation.com/u/chris.roys)\
**Post date:** [June 7, 2019, 7:20am UTC](https://forum.inductiveautomation.com/t/convert-mqtt-created-string-tags-to-number/25621/7 "2019-06-07T07:20:18Z")

</div>

Thanks again.  
For derived tag how I can reference them to write back to mqtt tag? For setpoint tag. There is one direction by expression.  
At the moment I don’t know why write value on mqtt engine tag get back access denied error.

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [June 7, 2019, 7:41am UTC](https://forum.inductiveautomation.com/t/convert-mqtt-created-string-tags-to-number/25621/8 "2019-06-07T07:41:19Z")

</div>

If position is a read/write value (rather than read-only), a derived tag would do the job like this:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/caec6e888de11c04025bd52643011cd698a73ae9.png)  
I’m guessing there’s a setting somewhere that determines whether you can write to the MQTT tags and you’re getting the error because they are read-only. They’d need to be setup to allowing publishing to them, rather than just subscribing.
