Can a Expression Tag Reference itself

I have a tag1 and a tag_result.

I only want to save the first positive value that I encounter from tag1.
Like this:

tag1 tag_result
-100 0
-200 0
100 100
200 100
-100 0
200 200
300 200
200 200
100 200
-200 0

I tried to do this:

1 if(
2 	{[.]tag1} < 0,
3 	0,
4 	if(
5 		{[.]tag_result} > 0,  # already a value saved
6 		{[.]tag_result},  # no change
7 		{[.]tag1}
8 	)
9 )

However, line 6 is given a error_confg.
Any idea of why this could be?
As a temporal solution I'm using a script when ValueChanged in tag1

Thanks in advance!

Maybe try

{
    if (
        self < 0,  # Use 'self' instead of tag1
        0,
        if (
            {[.]tag_result} > 0,  # Already a value saved
            {[.]tag_result},  # No change
            self  # Use 'self' instead of tag1
        )
    )
}

Doesn't work. We are at expression language so is not the same as python sadly

1 Like

Expression can't write to istelf. Your tag script is the best solution.

If you have a lot of those, however, consider using a gateway tag change script.