Automation/Entity Status to Trigger Widget

Hi all,

Is it possible to use an HA automation or entity status to trigger a widget on a specific dashboard? My goal is to trigger the alarm panel widget, if the alarm is triggered.

Thank you!

I’m not sure I understand what you want to do here. Would you like an alarm widget to open (as if we simulated a click on the widget) when an event or state change occurs in HA? That would be possible by modifying the alarm widget to act on the state change of the alarm entity. Since the alarm widget already listens for state change for an alarm entity, the changes in the widget is pretty simple, but you would need to understand how to copy the alarm widget and make a custom alarm widget and where to put the files etc.

In the alarm widget, the OnStateUpdate function would need to check if the new state is either “pending” or “triggered” and then just call the OnButtonClick function which opens the alarm panel.

1 Like

@tjntomas Yes, we’re on the same page! Is there any documentation on where the base widget is located? I will attempt to make a custom widget to work off that widget.

Also, is it possible to capture specific click events per dashboard?

Example: I click a light on the Kitchen dashboard, that event is capture in HA (light triggered from kitchen tablet), then I set an automation based on that in HA. If the same light were clicked on the Front Door dashboard, it would not trigger that automation.

Thank you so much for your reply!

The widget files are here: https://github.com/AppDaemon/appdaemon/tree/dev/appdaemon/widgets

Per-dashboard clicks is more difficult. An obvious solution is to create a few input_booleans in HA and use them as switches in your dashboard,s meaning one input_boolean for the kitchen dashboard and another one for the front door dashboard. Then use either automations in HA or write an appdeamon app to react as preferred when the input_booleans are clicked. An appdaemon app will likely be way easier than HA automations.

1 Like

Thanks to @tjntomas for walking me through this request.

Following his instruction, I copied the basealarm folder and alarm.yaml file into custom_widgets.

I then modified the following in basealarm.js (in custom_widget) from:

function OnStateUpdate(self, state)
{
    self.set_field(self, "state", self.map_state(self, state.state))
}

To:

function OnStateUpdate(self, state)
{
    self.set_field(self, "state", self.map_state(self, state.state))
    if  (state.state == "triggered"){ 
    self.OnButtonClick(self)   // Opens alarm panel
    }
       if  (state.state == "disarmed"){ 
        self.OnCloseClick(self)   // Closes alarm panel
    }
            if  (state.state == "armed_away"){ 
            self.OnCloseClick(self)   // Closes alarm panel
    }
                if  (state.state == "armed_home"){ 
                self.OnCloseClick(self)   // Closes alarm panel
    }
}

Good that you got it working. If you like to do it in a more structured way, you can try:

// Define these triggers at the begging of the code where it says "Initialization"
this.OPEN_PANEL_TRIGGERS = ['triggered']
this.CLOSE_PANEL_TRIGGERS = ['disarmed', 'armed_away', 'armed_home']
// Its good practise to define all parameters in the beginning of a class or function,
// and referring to the parameters instead of the actual values in the code 
// since it makes the code more readable and easier to maintain.

// And in the OnStateUpdate function:
function OnStateUpdate(self, state)
{
    self.set_field(self, "state", self.map_state(self, state.state))

    if (this.OPEN_PANEL_TRIGGERS.includes(state.state)) {
        self.OnButtonClick(self)
    }
    if (this.CLOSE_PANEL_TRIGGERS.includes(state.state)) {
        self.OnCloseClick(self)
    }
}
1 Like

Much cleaner, thank you!!

**Updated: ** Tested this but it does not seem to work.

Please post the code and I will have a look. I wrote this from the top of my head, so I might have made a mistake. You can post it on https://hastebin.com/ and post the link if its to long.

My mistake. Andrew who is the creator of appdaemon uses “self” instead of “this” for storing the context, so everywhere I wrote “this”, should be replaced with “self”.

// Define these triggers at the begging of the code where it says "Initialization"
self.OPEN_PANEL_TRIGGERS = ['triggered']
self.CLOSE_PANEL_TRIGGERS = ['disarmed', 'armed_away', 'armed_home']
// Its good practise to define all parameters in the beginning of a class or function,
// and referring to the parameters instead of the actual values in the code 
// since it makes the code more readable and easier to maintain.

// And in the OnStateUpdate function:
function OnStateUpdate(self, state)
{
    self.set_field(self, "state", self.map_state(self, state.state))

    if (self.OPEN_PANEL_TRIGGERS.includes(state.state)) {
        self.OnButtonClick(self)
    }
    if (self.CLOSE_PANEL_TRIGGERS.includes(state.state)) {
        self.OnCloseClick(self)
    }
}
1 Like

Confirmed working!

1 Like