How to Highlight Navigation Buttons Based on Active Alarms in Ignition

Hello everyone,

I'm working on a project where I need to highlight navigation buttons if there is an active alarm on the corresponding screen. For example, if there is an active alarm on Screen 3, the button that navigates to Screen 3 should be highlighted.

The tags and folders are organized by screen, so I plan to highlight the buttons by checking all the alarms in the respective folders.

I have experience with Python, but I'm relatively new to scripting in Ignition. So far, I've only worked with alarm filters and simple display logic.

Here’s a sample code snippet I came up with (note: I haven't tested this yet). I'm not sure if I should add this script to each button individually or in the script console. Could you please advise on the necessary changes and where to implement this code?

# Function to check for active alarms in a specific screen
def check_active_alarms(screen_folder):
    alarms = system.alarm.queryStatus(path=["*[default]Sensors/*"])
    return len(alarms) > 0

# Function to update button style
def update_button_style(button, active):
    if active:
        button.background = "red"
    else:
        button.background = "default" 

# Function to update all navigation buttons
def update_navigation_buttons():
    screen_buttons = {
        "Screen1": screen1_button,
        "Screen2": screen2_button,
        "Screen3": screen3_button,
    }

    # Check alarms and update button styles
    for screen_folder, button in screen_buttons.items():
        alarms_active = check_active_alarms(screen_folder)
        update_button_style(button, alarms_active)

update_navigation_buttons()

Should I use this script in the Script Console or on each individual button? Are there any improvements or best practices I should follow?

Thank you in advance for your help!

Broadly speaking, store the results of check_active_alarms somewhere that's globally accessible, then bind your buttons' styles to that.

In more details, I'd probably have a single dataset tag to store that information, and I'd write to that tag with a timer script. The time step depends entirely on your accuracy needs.
Then a simple expression using lookup on that dataset tag will tell you whether there are active alarms for a particular entry.

note that as it is, your check_active_alarms function doesn't use the screen_folder parameter, so you'll get the same result for each button, which is probably not what you want.

Thanks for the response!

What do you mean by a single dataset and to write to a tag with a timer script?

Thanks for the note!

Is there an easier way to do it?

I discovered that I can use isAlarmActive('[default]Path/To/UDT*') , but is there a way to specify only the path and not a specific tag? I want to work with all the tags in a folder, not just a single tag.

I did the following code. It is not working, and I can't figure out why.

pathValue = "prov:default:/tag:Sensors/*"  # Folder path
alarms = system.alarm.queryStatus(source=pathValue, state=[2, 3]) 

for alarm in alarms:
    if alarm.state in [2, 3]:  # Check for ActiveUnacked or ActiveAcked
        event.source.buttonBG = 255,0,0
        break  

I’m not sure how it happened, but it appears that your post was deleted.

Here’s your original comment:

" I can't say its the answer to all of your questions but I don't think this works:

event.source.buttonBG = 255,0,0

Try something like this instead:

event.source.backgroundColor = "#FF0000"

Since you are querying for only status 2,3, your if statement is redundant."

Am I declaring the function in the right place? I created a custom function in the component script.

I tried in different places, but it didn't work.

I deleted it because I failed to notice you tagged this with vision, my brain defaulted to perspective. event.source.buttonBG = 255,0,0 should work in vision, so something else is going on.