Popup message function for easy debugging

A simply popup message box that can be triggered during coding or debugging, that can contain basic details such as the contents of a variable at that moment in time, or a message to allow the user to know that a particular even has been triggered.

Similar to this Message Box function

For example, if you are writing a script containing multiple conditions, a message box can be triggered to show condition has been triggered, and what the various variables are at that exact moment in time.

If X=>1
Then MSGBox('The value of X is " & X)
Else
… whatever

For use in the bowser interface or app, rather than at automation runtime.

For debugging an automation or script, a trace is available.

Automations - Troubleshooting

If you prefer to have messages appear in the UI during execution, you can uses Persistent Notifications.

- if: '{{ foo > 1 }}'
  then:
    - service: notify.persistent_notification
      data:
        message: 'The value of foo is {{ foo }}'
  else:
    .. whatever ...

I’ve added the following code to an Automation, and then manually run it using the context menu and the triangular Run\play command.

service: notify.persistent_notification
data:
  message: This is a persistant notification
  title: Notification

A small message comes up in the bottom left hand corner of my browser saying

Action Run successfully

But nothing else. I’m using Microsoft Edge on Window 10.

The bell icon in the lower left corner should display an orange dot containing the number of existing persistent notifications.

image

I repeated your test, clicked the bell icon and it displayed this:

image

The test was performed using MS Edge on a PC running Windows 10.

OK, I was expecting a popup message. I’d still like a popup message that must be cleared to proceed as an addition.

What you’re asking for, frontend control over the backend’s execution progress, involves substantial architectural considerations. I suggest you become comfortable with Persistent Notifications because implementing your FR is non-trivial.

Maybe, you can add a wait_for event for notification acknowledgement so automation will hang in the step until notification acknowledged.

If i am not mistaken, you can wait for notification dismiss/acknowledge service call event.

1 Like

That I didn’t know.

Again, this is a general thing for any event and dismissing/acknowledging a notification should generate the event. Please give it a try, i haven’t tested myself

More info about events Events - Home Assistant

Example trigger to be used as wait for trigger: Dismiss of a persistent notification as trigger for automations - #2 by 123

Be advised that the suggested Event Trigger (such as the one in that dusty old example of mine from September 2019) doesn’t know which persistent notification is being dismissed. Any dismissed persistent notification will trigger it.

To be more selective, I suggest you use the persistent_notification.create service call to create the notification because it lets you specify a value for notification_id. Then when you dismiss the notification, your Event Trigger should listen for the dismissal of a notification bearing the same value of notification_id. This way it will trigger only for the dismissal of the one desired notification.

To be clear, this still won’t give you a ‘popup’ but, like fuatakgun explained, it will give you a modicum of control over the pace of execution.

Be advised that the complete solution for creating notifications and listening for their dismissal will consist of far more lines of YAML then you may have anticipated. You may wish to consider building it as a script (that accepts passed variables) in order to simplify its use within your automation. Otherwise you’ll have to duplicate all those lines of code each time you want to display something from within your automation.

Let us know if you need help creating the script.

1 Like

This is listed triggers page; Automation Trigger - Home Assistant