hello everyone,
I have an "image" component where I want it to be shown when some values change, but it is not being executed.
# Read custom property values
sp_p = event.source.SP_P
active_power = event.source.Active_Power
timer_value = event.source.timer
# Calculate the condition
#condition_met = (abs((sp_p - active_power) / active_power) * 100 > 115) and (sp_p_2 > 0.25)
condition_met = sp_p > active_power
if condition_met:
timer_value += 1
else:
timer_value = 0
# Updating the timer
event.source.timer = timer_value
what am I doing wrong?
You aren't checking the property name. You won't make much progress until you indent everything and put if event.propertyName == 'something':
ahead of it. In Vision, property change scripts run for every property that fires changes. You must filter for the properties of interest.
1 Like
Thanks, Phil. Initially, it worked for me by adding the condition:
if event.propertyName == 'something'
and that 'something' would be a custom property. It ended up like this:
sp_p = event.source.SP_P
active_power = event.source.active_power
timer_value = event.source.timer
counter = event.source.counter
if event.propertyName == "counter":
if sp_p >= active_power:
timer_value += 1
else:
timer_value = 0
event.source.timer = timer_value
the counter is incrementing every second, I did this from the gateway event script.
What I wanted was for the component to be visible only if the condition is met for more than 10 seconds; otherwise, it should not be shown. By doing this and adding a visible expression, it worked:
{[PROJECT]System/TEST/Temp_condition_Timer/Condition_Timer_2_2_1} >= 10
thanks again.
Note that even your other property accesses should be inside the if
, for best performance of all the events that you don't process.
2 Likes