How to send information to Lovelace from automation (watchdog)?

Back in the days when I was programming complex industrial automation systems, an essential element was the watchdog functionality, which, depending on the controlling device, was built many ways, but typically e.g. just calling a function with some paramters like output, input etc)

The purpose of the watchdog was to monitor, that things happen as they should. E.g. when firing up a valve that moves a cylinder, it was clear to expect that the piston rod reaches the end sensor in few seconds and if it did not, there obviously was something wrong, which caused some actions to be made. The conditions did not need to be physical sensor, but any variables or “states”

Basic sh*t.

Now, how to easiest do the similar in HA? I have tried to set up an automation in graphical ui, which goes OK with setrting up e.g condition, but in the end when you have to set the action, there just is nothing suitable. In “Call servive” there seems to be no service that I could use. I cannot configure systen to fire an event without warning message, nor a device or anything else. There seems to be “notify” service, but I have no idea, what should be a target where to send the notifications.

If the case is, like mine is to monitor that e.g. some sensor is in “on” state for too long, it throws a message to UI, is there a SIMPLE way just e.g. use an event, that you soecify there on the fly and use it later as you need? E.g i have the following custom panel the visibility is controlled via saensor value, but what i need it to be is some variable etc.

      - background_color: '#A81419'
        entity: binary_sensor.xxx_door_sensor
        font_color: '#fff'
        hide_condition: |
          [[[ return entity.state === "off" ]]]            
        icon: mdi:door-open
        large: false
        title: XXX door open!
        type: custom:button-text-card

Or do we always need to go specifying some templating in configuration.yaml, use automations, perhaps together with scripts etc, which is very work-intensive to say the least for this kind of basic automation task.

To ask a concrete question, what is the easisest way of monitoring a sensor (or any else “variable” or “state”) and if it stays in monitored state a specified time, it throws a message to UI?

To make a more concrete example and question:

  1. I monitor a binary sensor
  2. Timer starts when it is in defined state
  3. After timer has elapsed, I need it to throw a message to UI

In the next sample, the triggering should happen after 59 minutes and actions are to be run.

alias: Output on too long
description: ''
trigger:
  - type: closed
    platform: device
    device_id: b30e53fa81a015fec7116bd45d369060
    entity_id: binary_sensor.output_x
    domain: binary_sensor
    for:
      hours: 0
      minutes: 59
      seconds: 0
condition: []
action:
  - WHAT DO I WRITE HERE TO GET A MESSAGE ON UI?
     BECAUSE IN THE AUTOMATION GRAPHICAL UI I COULD NOT FIND A SUITABLE SOLUTION
mode: single

…and preferably I would like to use custom card on lovelace:

    - background_color: '#A81419'
        entity: SOME VARIABLE PERHAPS???
        font_color: '#fff'
        hide_condition: |
          [[[ return entity.state === "off" ]]]            
        icon: mdi:something
        large: false
        title: Some warning text !
        type: custom:button-text-card

Preferably without needing to write any extra lines to configuration.yaml, making helping scripts etc

And if the approach is wrong, how do you recommend I should handle this?

You’re doing it wrong then. This is how you fire any custom event,

- event: watchdog
  event_data:
    ... add whatever you want here...

if you want notifications in the UI, you can use persistent_notification.

That will create a notification in the UI. You can also name the notification and use it in your cards.

You’re doing it wrong then. This is how you fire any custom event,

- event: watchdog
  event_data:
    ... add whatever you want here...

And this the result, and the error i was talking about

Message malformed: expected dict for dictionary value @ data[‘action’][0][‘event_data’]

image

I’m not very familiar with HA coding, but as far as I can see, the page talks about creating notifications, not how to display them?

If you’re adding event data, it expects a field

event_data:
  something: 4

It’s not coding, it’ll create a notification in the ui. Just try it.

OK @petro , thanks for your advice. I managed to solve it by using persistive notice as an entity in the custom card I presented earlier. It was just testing, because I found no mention in the instructions that the automation sets such entity when conditions and triggers are met.

The only problem in the beginning was that that entity does not exist before the action is run in the automation, but when it did, I noticed the entity in developer tools… The entity also disappears as soon as the notification is dismissed.

What comes to firing events, I do not have a need anymore for it in this, but will save it later :slight_smile:

Hmmm… There is a problem using persistent notifications. For examplde, I would liketo draw a button etc. that comes visible, when peristent notification fires AND I wish to use the same button with different colors/ texts when it is not on.

In general these pressed/depressed buttons works nicely inside lovelace vertical stack card, you just define 2 buttons of same size with different colors/ texts and use the visibilty controlling entity in opposite states, the other button is activated whille off and the other while on. Lovelace will draw the button on exactly the same location, because only one of the two can be active at the time.

It works OK with sensors etc. However, the problem with persistent notifications is that they exist only when they are active; when deactivated the entity does not have any state, because it does not exist. Thus, I cannot use it to control the button visibility in depressed state.

Is there any way to circumvent this?

The next structure does not work because of the the abovementioned reason. There might be some cards or like, that do, but I do not know any. Als, judging by the triple brackets, the hide condition below is javascript, not jinja. Is it possible testing is the entity defined or not and using the result to show up the card? Sadly I do not know javascript…

      - background_color: '#60B20D'
        entity: persistent_notification.xxx.yyy
        font_color: '#fff'
        hide_condition: |
          [[[ return entity.state === "on" ]]]            
        icon: mdi:door-closed
        large: false
        title: XXX door closed
        type: custom:button-text-card

Any ideas?

I use an input_boolean as the main indicator of an issue.
You can then do any kind of automation based upon its state, including creating and dismissing persistent notifications when you “acknowledge” that issue.

Sorry for the delay, been quite busy…

Since my day-job is with totally different things and I’m not a coding professional, could youl please provide some example of the strucuture you mean?