Automation won't finish the job

this automation works fine by creating the persistent notification when espresso needs refilling. I was hoping it would continue to run until the next condition was met: numeric state back up again (which happens when I refill…) and then dismis the persistent notification, and finish.

Any reason this won’t happen?
There’s no errors anywhere…

   - alias: Espresso bijvullen
      id: '1511601478447'
      trigger:
        platform: numeric_state
        entity_id: sensor.espresso_keuken_actueel
        above: 0
        below: 1
        for:
          minutes: 1
      condition: []
      action:
        - service: notify.notify
          data:
            title: 'Espresso bijvullen:'
            message: Espresso staat aan maar heeft geen water meer!
        - service: notify.notify #ios_telefoonmhb
          data:
            message: Espresso needs refilling.
        - service: persistent_notification.create
          data:
            message :
              "Espresso staat aan maar heeft geen water meer!"
            title: Espresso bijvullen
            notification_id: "espresso notification"
        - condition: numeric_state
          entity_id: sensor.espresso_keuken_actueel
          above: 10
        - service: persistent_notification.dismiss
          data:
            notification_id: "espresso notification"
        - service: notify.notify
          data:
            title: "Espresso refilled."
            message: "Enjoy!"

Once your trigger has fired and the action has been kicked off it’s done.

You will need to create another automation that has

trigger:
  numeric_state
  entity_id: sensor.espresso_keuken_actueel
  above: 10

and then carry out your other actions, i.e. notification and removing the persistent notification.

ok thanks, will do. thought the extra condition in the action would keep the automation alive… use that in other situations too.

creating a second one is easier and better maintainable also, thanks!

shouldn’t the existence of the persistent notification be a trigger though? otherwise the automation will fire always when on…

If the automation reaches a condition that evaluates to False then the automation stops (and ends) at that point.

You could use a wait instead, but a second automation is probably a better solution.

thanks, have no automatons with a wait yet, what would be the best use for that?

for the second automation,would this be sufficient? Shouldn’t there be a condition of a persistent notification being there at all? :How would that be formatted?

 - alias: Espresso bijgevuld
  id: '1511601478448'
  trigger:
    platform: numeric_state
    entity_id: sensor.espresso_keuken_actueel
    above: 10
  condition: ???
  action:
    - service: persistent_notification.dismiss
      data:
        notification_id: espresso-notification
    - service: notify.notify
      data:
        title: "Espresso refilled."
        message: "Enjoy!"

Don’t think you want/need a condition there.

I assume that all you want is a notification that the espresso thingie has been refilled - doesn’t really matter if you dismissed the notification or not.

What you’re doing at the moment will result in you only receiving a message if the notification has NOT been dismissed.

The most natural thing for me to do would be:

  1. Receive the notification
  2. If the HA Dashboard is open, I’d dismiss it
  3. Get up and refill the machine
  4. Receive the notification that it’s been refilled

Even if 2. doesn’t happen, the notification would still be gone when I open the dashboard next time - which is good thinking, if you ask me :wink:

lol, no, I know its refilled, when I have refilled it :wink:

Id just like the notification to be dismissed automatically, a bit like in the Battery package by @NotoriousBDG:

 - alias: battery_alert_clear
  trigger:
    - platform: time
      minutes: '/30'
      seconds: 00
  condition:
    - condition: template
      value_template: >
          {% macro battery_level() %}
          {%- set threshold = 40 -%}
          {% set domains = ['light', 'switch', 'sensor', 'zwave', 'lock'] %}
          {% for domain in domains -%}
          {% for item in states[domain] if ((item.attributes.battery_level is defined and item.attributes['battery_level'] | int < threshold) or ("battery" in item.name | lower and ((item.state | int < threshold and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown"))) -%}
          {% if (item.attributes.battery_level is defined and item.attributes['battery_level'] | int < threshold) -%}
          {{ item.name }} ({{ item.attributes['battery_level'] }}){%- if not loop.last %}, {% endif -%}{% endif -%}
          {% if "battery" in item.name | lower and ((item.state | int < threshold and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown") -%}
          {{ item.name }} ({{ item.state }}){% if not loop.last %}, {%- endif %} {% endif -%}
          {% endfor %}
          {%- endfor %}
          {% endmacro %}
          {{ battery_level() |trim == "" }}
  action:
    - service: persistent_notification.dismiss
      data:
        notification_id: low-battery-alert

its just that i don’t know what should be the condition or trigger. Of course the sensor being >10 again, but only after it has been 0, and not off… or condition the existence of the persistent notification in the first place. But how to configure that as condition?

{{states.persistent_notification.espresso-notification == notifying}} ??

making it:

- alias: Espresso bijgevuld
  id: '1511601478448'
  trigger:
    platform: numeric_state
    entity_id: sensor.espresso_keuken_actueel
    above: 10
    for:
      seconds: 10
  condition:
    - condition: template
      value_template: '{{ (states.persistent_notification.espresso-notification) == notifying }}'
  action:
    - service: persistent_notification.dismiss
      data:
        notification_id: espresso-notification
    - service: notify.notify
      data:
        title: "Espresso refilled."
        message: "Enjoy!"

You don’t need the condition for it to dismiss it.

Without the condition, I understand that it will dismiss it when the notification is there and do nothing if i isn’t.

With the condition you will not get a notification that it’s been refilled after the notification has been dismissed manually before.

And in case the machine got refilled before it was low you would still get a notification about it :wink:

thats interesting… so the mere existence of the persistent notification suffices for it to trigger. Cool. Would have thought in that case, the automation would always run, when sensor >10, without any use. And take resources…

thanks, Ill experiment with that
Cheers

That’s what the trigger is for.
As I understand it, only if the trigger takes place the condition is evaluated

Example:

  • you put in sunrise as the trigger, you being home as the condition, and turning the light on as the action
  • sunrise triggers the evaluation of the condition
  • and only if the condition is met (i.e. you’re home at that time) the light will turn on
  • during the rest of the day it doesn’t matter for this automation if you’re home or not, no evaluation of the condition takes place

In your case the trigger is that the value moves above 10.
If it’s already above 10, moves from 11 to 12, or even from 12 to 11 doesn’t matter.

I think you don’t even need the

    for:
      seconds: 10

unless the level you’re measuring is volatile, e.g. you shake the machine or an earthquake moves it, and the value spikes for less than 10 seconds above 10.

1 Like

you’re right, took that out. no reason to wait.

had to change the condition though:

"{{states.persistent_notification.espressonotification.state == 'notifying'}}"

which is to be noted, since the notification is created with this id: notification_id: espresso-notification
will also check without, but if used, it should be correct :wink:

Thanks!
Marius