# Automatic Function

**URL:** <https://forum.inductiveautomation.com/t/automatic-function/66619>\
**Category:** Ignition\
**Tags:** ignition80, vision\
**Created:** [November 17, 2022, 2:05am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619 "2022-11-17T02:05:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mai\_Watanabe](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Mai\_Watanabe](https://forum.inductiveautomation.com/u/Mai_Watanabe)\
**Post date:** [November 17, 2022, 2:05am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/1 "2022-11-17T02:05:22Z")

</div>

Is there a function to periodically check the value of tag and take action? I'm looking for a function that automatically changes the color of buttons, text, etc. when the value of tag exceeds a certain level.

---

<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:** [November 17, 2022, 2:26am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/2 "2022-11-17T02:26:03Z")

</div>

This is usually accomplished via binding tag values to component properties.

---

<div class="post-metadata">

**Author:** ![Mai\_Watanabe](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Mai\_Watanabe](https://forum.inductiveautomation.com/u/Mai_Watanabe)\
**Post date:** [November 17, 2022, 3:48am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/3 "2022-11-17T03:48:16Z")

</div>

Thank you. I want to write a script that uses the script editor of Property Change to change the color when the tag value is 0, and I wrote the following, but an error appears. I'm sorry about the basics of python, but if you know what the cause is, it would be helpful if you could tell me.

```auto
a=system.tag.readBlocking(["tag path"])[0]
values=a.value
if values == 0:

```

The error message is:  
Parse error for event handler "propertyChange" SyntaxError: ("mismatched input '\n' expecting INDENT", ('', 3, 15, 'if values == 0:\n'))

---

<div class="post-metadata">

**Author:** ![Mai\_Watanabe](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Mai\_Watanabe](https://forum.inductiveautomation.com/u/Mai_Watanabe)\
**Post date:** [November 17, 2022, 4:14am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/4 "2022-11-17T04:14:14Z")

</div>

Am I writing the script wrong in the first place? I want to write a script that changes the color of the text field every time the value of the tag changes, so I write it in the script editor of the property change of that text field.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 17, 2022, 7:25am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/5 "2022-11-17T07:25:38Z")

</div>

> [@Mai\_Watanabe](#):
>
> "mismatched input '\n' expecting **INDENT**"

Python relies on proper and consistent indenting after any control statement ending in a colon (:). For us to be able to help you need to post your code using the \</\> code formatting button to preserve code indentation and apply syntax highlighting. It's essential for Python and makes any code much easier to read. There's an edit button 🖉 below your post so you can fix it.  
i  
In any case, a better construction would be,

```python
if not values: # checks for values == 0.

```

But as explained by @witman, this can be done easily using an expression binding on the color property of a component.

[https://docs.inductiveautomation.com/display/DOC81/Expression+Bindings+in+Perspective](https://docs.inductiveautomation.com/display/DOC81/Expression+Bindings+in+Perspective)

Use the expression binding to get the controlling value. Then use a map transform in that binding to set the color.

[https://docs.inductiveautomation.com/display/DOC81/Map+Transform](https://docs.inductiveautomation.com/display/DOC81/Map+Transform)

---

<div class="post-metadata">

**Author:** ![Mai\_Watanabe](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Mai\_Watanabe](https://forum.inductiveautomation.com/u/Mai_Watanabe)\
**Post date:** [November 18, 2022, 5:41am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/6 "2022-11-18T05:41:28Z")

</div>

Thank you for your advice. I want to bound tag to background and set it so that the color changes when it reaches the specified value like a reference link, but I can't edit the color or value of property.

 ![スクリーンショット (145)](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/d/fd891becaba7655fac5805811e8d13298e380242.png)

---

<div class="post-metadata">

**Author:** ![Mai\_Watanabe](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Mai\_Watanabe](https://forum.inductiveautomation.com/u/Mai_Watanabe)\
**Post date:** [November 18, 2022, 5:48am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/7 "2022-11-18T05:48:05Z")

</div>

Also, I can edit it in the tag part, but I cannot enter a decimal point etc. in the Value part.

 ![スクリーンショット (147)](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/f/2f2d472e4d9941cca08d6e9fc0a486638956f7c7.png)

---

<div class="post-metadata">

**Author:** ![Mai\_Watanabe](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Mai\_Watanabe](https://forum.inductiveautomation.com/u/Mai_Watanabe)\
**Post date:** [November 18, 2022, 6:17am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/8 "2022-11-18T06:17:22Z")

</div>

As a result of various investigations, the method that I was told seems to be the method of doing it with "view". I use "vision", how do I do it with "vision"?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 18, 2022, 7:27am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/9 "2022-11-18T07:27:07Z")

</div>

> [@Mai\_Watanabe](#):
>
> I use "vision"

You can edit your original post to add the _Vision_ tag to avoid confusion with _Perspective_. This will help attract the experts.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 18, 2022, 7:39am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/10 "2022-11-18T07:39:39Z")

</div>

I would use an [expression binding](https://docs.inductiveautomation.com/display/DOC80/Expression+Overview+and+Syntax) for this.  
**Example:**  
`if ({[default]TestTags/FloatTag.value} > 1.5, '0,0,0', '255,255,255')`  
The if statements can be nested many times to create complex and dynamic bindings

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

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 18, 2022, 8:46am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/11 "2022-11-18T08:46:47Z")

</div>

> [@justinedwards.jle](#):
>
> The if statements can be nested many times to create complex and dynamic bindings

But don't nest `if`s if the conditions share the same 'data source', use `switch` or `case` instead.  
for example, don't right

```auto
if ({someTag} = 1, "one",
    if ({someTag} = 2, "two",
        if ({someTag} = 3, "three",
            "default"
        )
    )
)

```

do this instead:

```auto
case({someTag},
    1, "one",
    2, "two",
    3, "three",
    "default"
)

```

Obviously this doesn't work with completely/unrelated conditions, or with greater than/less than comparisons.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 18, 2022, 8:56am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/12 "2022-11-18T08:56:06Z")

</div>

> [@pascal.fragnoud](#):
>
> this doesn't work with [...] with greater than/less than comparisons.

Edit: It seems I didn't read your answer fully. Disregard this post.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 18, 2022, 8:57am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/13 "2022-11-18T08:57:35Z")

</div>

> [@justinedwards.jle](#):
>
> Can case or switch be used for comparative values such as `>= 1.5`, `>= 2.6`, `etc`?

No. Read the last line of Pascal's post again.

[https://docs.inductiveautomation.com/display/DOC81/switch](https://docs.inductiveautomation.com/display/DOC81/switch)

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 18, 2022, 8:59am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/14 "2022-11-18T08:59:42Z")

</div>

> [@Transistor](#):
>
> No. Read the last line of Pascal's post again.

I had already corrected myself before you posted this. 😅

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 18, 2022, 10:34am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/15 "2022-11-18T10:34:54Z")

</div>

I would bind the tag to a custom property, then use the style customizer.  
[https://docs.inductiveautomation.com/display/DOC81/Vision+Component+Customizers#VisionComponentCustomizers-StyleCustomizer](https://docs.inductiveautomation.com/display/DOC81/Vision+Component+Customizers#VisionComponentCustomizers-StyleCustomizer)

---

<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:** [November 18, 2022, 1:14pm UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/16 "2022-11-18T13:14:29Z")

</div>

Aside from the style customizer, which is a Vision thing, the key to the question is to use an expression binding to translate your tag values into a range of colors or indices for colors. Whether Vision or Perspective. I highly recommend you bind the source tag to a custom property (perhaps indirectly), and then use that property in your expressions or styling.

Note that one "pulls" the tag into the UI for evaluation--you don't "push" from the tag to the UI. That is, don't try to do this sort of thing with a tag event or in a context/scope outside the UI.

---

<div class="post-metadata">

**Author:** ![Mai\_Watanabe](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Mai\_Watanabe](https://forum.inductiveautomation.com/u/Mai_Watanabe)\
**Post date:** [November 21, 2022, 1:29am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/17 "2022-11-21T01:29:07Z")

</div>

Thank you all for your advice. If I used the style customizer, I could use a component that directly reflected the value of a tag such as display, but I could not change the color depending on the value of the tag with a label etc. I want to change the color of the tag value with conditions such as \< instead of =.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 21, 2022, 1:44am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/18 "2022-11-21T01:44:07Z")

</div>

> [@Mai\_Watanabe](#):
>
> I want to change the color of the tag value with conditions such as \< instead of =.

A simple expression binding on your background color property could accomplish this using a custom property bound to your tag:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/a/da21fcbb55e530fd5379c0882ed9c48e91f54ce1.png)

Using @pascal.fragnoud 's example as a template, your binding would look something like this:

```auto
if ({Root Container.Button.myCustomProp} < 1.5, '100,100,100',
    if ({Root Container.Button.myCustomProp} < 2.5, '200,200,200',
        if ({Root Container.Button.myCustomProp} < 3.5, '255,255,255',
            '0,0,0'
        )
    )
)

```

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

Here is the result when applied to the background color property of a button:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/1/f1b7688e3fa898da99e4d83d8ca4d128131cdd42.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/4/34df6d205280ecb070770e4da941500f6ac43af3.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/d/8d331fd837a777855c0b71de62f545d0fa678049.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/6/f6154ea6bcf28d717c7d32840b1226de16b55b08.png)

---

<div class="post-metadata">

**Author:** ![Mai\_Watanabe](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Mai\_Watanabe](https://forum.inductiveautomation.com/u/Mai_Watanabe)\
**Post date:** [November 21, 2022, 3:16am UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/19 "2022-11-21T03:16:05Z")

</div>

Done! Thank you so much! Thank you for all the advice!

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 21, 2022, 11:50pm UTC](https://forum.inductiveautomation.com/t/automatic-function/66619/20 "2022-11-21T23:50:45Z")

</div>

> [@justinedwards.jle](#):
>
> ```auto
> if ({Root Container.Button.myCustomProp} < 1.5, '100,100,100',
> if ({Root Container.Button.myCustomProp} < 2.5, '200,200,200',
> if ({Root Container.Button.myCustomProp} < 3.5, '255,255,255',
> '0,0,0'
> )
> )
> )
> 
> ```

Love it or hate it, I much prefer keeping the ifs on the same line to help with reading as well as horizontal space. It reads more like a case statement then as well which keeps it more consistent:

```auto
if ({Root Container.Button.myCustomProp} < 1.5, '100,100,100',
if ({Root Container.Button.myCustomProp} < 2.5, '200,200,200',
if ({Root Container.Button.myCustomProp} < 3.5, '255,255,255',
'0,0,0')))

```

🤷

[Next page](https://forum.inductiveautomation.com/t/automatic-function/66619.md?page=2)
