Is there an expression to display the may value of a tag during a given condition without using a SQL query. i just want to show the max value while a condition is true.
You can do this with my objectScript() expression function, thanks to its built-in state dictionary. Something like this:
objectScript("args[0] if not args[1] or state['mx'] is None or args[0] > state['mx'] else state.mx\nstate['mx'] = __retv",
{path/to/value/to/track}, {path/to/condition/boolean})
Note the buried new-line code that ends the expression and provides an opportunity to execute the assignment into the state
dictionary.
The above passes the value through when the condition is false, then captures max while true.
This is a nice function but is it normal for the tag quality of the tag to turn bad during evaluation?
Unable to execute object script. I will read through your docs
Uhm, did you install my (free) module?
Yes, I did. The pass through works, but when i enable the condition boolean it errors out.
I can see now that as long as the value to track is above mx the expression evaluates but as soon as it drops below the max value the expression no longer evaluates, The max value is there it just has an overlay.
Thank you for a new path to work on, i’ll keep on it.
I used property notation instead of key access right after the ‘else’. Replace state.mx
with state['mx']
. Sorry about that.
You have nothing to apologize for, I have been learning alot from your input on the forums. This gives me something else to learn from.
Thank You
To future readers, note that in the version as of the date of my post, using key access with brackets i.e. state['max']
results in an Error_ExpressionEval
, likely because the non-existent key at the initialization of the expression will throw a KeyError
. Fortunately, using state.get('max')
nicely sidesteps this by just returning None
instead as desired.
I normally use the dictionary's .setdefault()
method to ensure an initial value is present.