Setting F values using C values with Expressions

Hi All,

I have been working around trying to find a way to set values from C to F using expression.
I have used an expression that will be ©*1.8+32 to give me F value.
That was good when I ONLY wanted to view the values.

But when I try to SET POINT using the expression IT does NOT work at all.
The setpoints works when I am using indirect tags normally to the C tag but when I use expression I does not do anything. I have Read/Write and Bi-Directional enabled and all that is needed to make it works - But when I try to set point IT DOES NOT work.

I know that I am not doing something correctly but what - and I am sure that I need to do a script - But how? and Where?

I would be happy if some of you experts can help me understand how to solve this and be able to set F values using C values directly.

Thank you!

Hi arye,

I would like to help you but I do not understand enough what you are trying to do. What does trying to SET POINT using an expression mean?

Perhaps you can give more details or an example or screenshots of what you are trying to do.

Best,
Nick

I think this is what you want to do:

Create a SQLTag that has your Celsius value.

Create an expression tag named Fahrenheit that has this expression: {[~]Celsius}*1.8+32

Expression tags cannot be directly written to. So in order to change the value of your Fahrenheit tag you will need to write to your Celsius tag.

Thanks.
That exactly what I did - BUT
you wrote “Expression tags cannot be directly written to. So in order to change the value of your Fahrenheit tag you will need to write to your Celsius tag.”

How can I do that if I want the user to see 55 and change it to 56 while behind scene it is 12.7 to 13.4
I don’t want the user to input 13.4 instead I want to enable only F values - i.e. 56 and not 13.4.

How can I do that?
Thank You.

Good question.

You could make a Fahrenheit memory tag.

Then make two Gateway Tag Change Scripts that bidirectionally connect the Celsius and Fahrenheit tags together.

The logic is when the Fahrenheit tag changes write to the Celsius tag, and when the Celsius tag changes write to the Fahrenheit tag.

Here is the script to use for the Celsius On Change script:

fahrenheit = newValue.value*1.8+32
system.tag.write("Fahrenheit",fahrenheit)

Here is the script to use for the Fahrenheit On Change script:

celsius = (newValue.value-32) * 5.0 / 9.0
system.tag.write("Celsius",celsius)

Here’s some documentation about Tag Change scripts: inductiveautomation.com/support/ … cripts.htm

Once you set this up you can read and write to the Fahrenheit tag and the Celsius tag will automatically change and vice versa.

I think you guys are overthinking it a bit… just set up scaling on the OPC tag, it automatically goes both ways… if you need both values, just make two copies of the OPC tag, one without scaling.
[attachment=0]conversion.png[/attachment]