# Celsius \<=\> Fahrenheit

**URL:** <https://forum.inductiveautomation.com/t/celsius-fahrenheit/7592>\
**Category:** Ignition\
**Created:** [November 20, 2013, 10:42am UTC](https://forum.inductiveautomation.com/t/celsius-fahrenheit/7592 "2013-11-20T10:42:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [November 20, 2013, 10:42am UTC](https://forum.inductiveautomation.com/t/celsius-fahrenheit/7592/1 "2013-11-20T10:42:10Z")

</div>

I just saw this in one of SCADA systems on the market:  
There is a global setting in the project: Display temperature in Celsius/Fahrenheit, and it can also be changed/used in Runtime.  
So, in the Runtime, you have a screen with temperatures (in labels/input fields/trends…). And there are two radio buttons with Celsius and Fahrenheit. When you choose Celsius, all temperatures are shown in Celsius, and when you choose Fahrenheit, all temperatures on the screen are shown in Fahrenheit.

Is it possible to do that somehow in Ignition?

I know, how to convert from Celsius to Fahrenheit and vice versa in Ignition (tag scaling, scripting). But you have to do it for every tag/label/input field.  
Or I’m missing something?

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [November 20, 2013, 9:42pm UTC](https://forum.inductiveautomation.com/t/celsius-fahrenheit/7592/2 "2013-11-20T21:42:58Z")

</div>

you can do this easily with a script and call the script from the button/label/whatever

---

<div class="post-metadata">

**Author:** ![Dravik](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Dravik](https://forum.inductiveautomation.com/u/Dravik)\
**Post date:** [November 20, 2013, 10:26pm UTC](https://forum.inductiveautomation.com/t/celsius-fahrenheit/7592/3 "2013-11-20T22:26:09Z")

</div>

I think Z is wondering if a feature could be added to define say a tag as F,and on using it for a screen bind it as C(or set an override ‘unit’) and have Ignition do the conversion for it.

I’d imagine there would need to be a prebuilt conversion table for simple ones(F to C, C to F, inches to cm, etc) and possibly a user defined table for more esoteric conversions.

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [November 21, 2013, 8:02am UTC](https://forum.inductiveautomation.com/t/celsius-fahrenheit/7592/4 "2013-11-21T08:02:56Z")

</div>

> [@drewdin](#):
>
> you can do this easily with a script and call the script from the button/label/whatever

[quote="Dravik"]I think Z is wondering if a feature could be added to define say a tag as F,and on using it for a screen bind it as C(or set an override 'unit') and have Ignition do the conversion for it.

I'd imagine there would need to be a prebuilt conversion table for simple ones(F to C, C to F, inches to cm, etc) and possibly a user defined table for more esoteric conversions.[/quote]  
I've been playing with this:  
Yes, you can do it with script (in fact, there is no other option for now), but you must do it for every TAG (or label or input field).  
I found that the 'easiest' way to do it is to set scaling of tag to 0 (OFF) or 1 (linear scaling).  
Somewhere on the screen I put two radio buttons (one for Celsius and one for Fahrenheit). Then in property change event of this two radio buttons I change the 'ScaleMode' of the tag:

```auto
# For Fahrenheit
system.tag.writeToTag('Vipa/MW20.ScaleMode', 1)
# For Celsius
system.tag.writeToTag('Vipa/MW20.ScaleMode', 0)
```

The 'problem' is, you have to do it for all tags. For example I have 20 temperatures and I have to write 20 writeToTag commands (or writeAll, with the predefined tags paths and values).  
The second problem I have is, that I want to change the EngUnit also:

```auto
# For Fahrenheit
system.tag.writeToTag('Vipa/MW20.ScaleMode', 1)
system.tag.writeToTag('Vipa/MW20.EngUnit', "F")
# For Celsius
system.tag.writeToTag('Vipa/MW20.ScaleMode', 0)
system.tag.writeToTag('Vipa/MW20.EngUnit', "C")
```

The change to EngUnit works only for first write (for examle 'F'). The second write ('C') writes the 'C' in the EngUnit, but something overwrites it back to 'F'. I was unable to find what is doing this.  
The third 'problem' I see with this (changing the 'ScaleMode') is, that every time I change ScaleMode, the tag quality changes for a second (becomes bad and then good again). I understand why (the tag must be unsubscribed and subscribe again to use new setting), but maybe, if this was on some 'system' or project level, we can avoid that.

I think also, that making the 'Scale Mode' property in the Tag editor bindable to another tag or property or expression will help a lot.

---

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://forum.inductiveautomation.com/u/Pat)\
**Post date:** [November 21, 2013, 3:12pm UTC](https://forum.inductiveautomation.com/t/celsius-fahrenheit/7592/5 "2013-11-21T15:12:33Z")

</div>

Create two tags for each process value, one would be the process value the other would be an expression to convert the process value to the other temperature range. Use a client string tag to hold the values C or F, and then use indirect binding to display the temperature units the user wants.

The problem with changing the scaling with scripting as shown in your example is that you’ll mess up your tag history. Using two tags for each temperature process value allows you to store the history in both C and F which will allow you to easily display history data in the units the user wants. The other problem is that your forcing every user to view the temperature values in the units the last user selected.

The simplest way would to be to create a Temperature UDT -`Temp/C
Temp/F`Then create a Client Tag “userTempUnits” and would use indirect binding to display the user’s desired temperature units -`Temp/{userTempUnits}`

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [November 22, 2013, 8:25am UTC](https://forum.inductiveautomation.com/t/celsius-fahrenheit/7592/6 "2013-11-22T08:25:46Z")

</div>

[quote=“Pat”]Create two tags for each process value, one would be the process value the other would be an expression to convert the process value to the other temperature range. Use a client string tag to hold the values C or F, and then use indirect binding to display the temperature units the user wants.

The problem with changing the scaling with scripting as shown in your example is that you’ll mess up your tag history. Using two tags for each temperature process value allows you to store the history in both C and F which will allow you to easily display history data in the units the user wants. The other problem is that your forcing every user to view the temperature values in the units the last user selected.

The simplest way would to be to create a Temperature UDT -`Temp/C
Temp/F`Then create a Client Tag “userTempUnits” and would use indirect binding to display the user’s desired temperature units -`Temp/{userTempUnits}`[/quote]  
Thank you, Pat, for your explanation and suggestion, but I think you lost me here… ☹  
I don’t quite understand, what you mean (about UDT and client tag???)… example, maybe… or some pictures… 😊

---

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://forum.inductiveautomation.com/u/Pat)\
**Post date:** [November 25, 2013, 4:49pm UTC](https://forum.inductiveautomation.com/t/celsius-fahrenheit/7592/7 "2013-11-25T16:49:57Z")

</div>

A client tag is a tag that is unique to each client instance, so each client can have a different value for that tag - [http://www.inductiveautomation.com/support/usermanuals/ignition/index.html?types\_of\_sqltags.htm](http://www.inductiveautomation.com/support/usermanuals/ignition/index.html?types_of_sqltags.htm)

I’ll assume that your temperature units are coming in in Fahrenheit.

1. Create a string client tag called TempUnits that holds the value C or F.
2. Create an OPC tag called FurnasTemp\_F.
3. Create an Expression tag called FurnasTemp\_C it’s expression will be -code\*5/9[/code]
4. Add a numeric display to a window, bind the value to the expression -`tag("FurnasTemp_" + {[Client]TempUnits})`

Changing the TempUnits value to C or F will display the proper value in your numeric display.

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [November 25, 2013, 5:56pm UTC](https://forum.inductiveautomation.com/t/celsius-fahrenheit/7592/8 "2013-11-25T17:56:05Z")

</div>

@Pat  
Thank you. Now I understand. 😃
