Trash collection - 4 automations --> 1 automation

I’m trying to declutter my automations and I’ve been pretty successful with most of them and decreasing the number of content similar automation.

But not this one…

I have 4 different trash sensors optimised to my needs and 4 different automations that are almost the same despite the sensor, message, title and some indivdual data.

What I want to achieve is only 1 automation where I can nest in all 4 actions at once.

I’ve tried with trigger IDs and choose but want to get 4 messages and not only 1 when all 4 sensors have the wished state. And of course with choose I only get the first notification.

Every automations looks like this right now.

alias: 'Trash: Bio'
description: ''
trigger:
  - platform: time
    at: '18:30'
condition:
  - condition: state
    entity_id: sensor.trashbio
    state: morgen
action:
  - service: notify.all_mobile_phones
    data:
      message: Please put the trashbag out!
      title: ⏰ Bio trash is due tomorrow
      data:
        icon_url: /local/Icons/bio.png
        notification_icon: mdi:delete-clock
        tag: biom
mode: single

Would be thankful for years if anybody could give me a hand or and idea.

Just add all conditions as or. And then 4 if or choose actions with the notify action inside. Done.

Could you please go the long way somehow for me?

trigger: set time
condition: or
  condition 1
  condition 2
  condition 3
  condition 4
action:
 AND NOW WHAT?

Post all four automations so we can see the four conditions and messages.

Here it is. Let me know if I should translate anything.

alias: 'Müll: Bio'
description: ''
trigger:
  - platform: time
    at: '18:30'
condition:
  - condition: state
    entity_id: sensor.abfallbiomuell
    state: morgen
action:
  - service: notify.alle_pixel
    data:
      message: Stell bitte den Sack an die Straße!
      title: ⏰ Biomüll wird morgen abgeholt
      data:
        icon_url: /local/Icons/bio.png
        notification_icon: mdi:delete-clock
        tag: biom
mode: single

alias: 'Müll: Gelber Sack'
description: ''
trigger:
  - platform: time
    at: '18:30'
condition:
  - condition: state
    entity_id: sensor.abfallgelbersack
    state: morgen
action:
  - service: notify.alle_pixel
    data:
      message: Stell bitte die Säcke an die Straße!
      title: ⏰ Gelbe Säcke werden morgen abgeholt
      data:
        icon_url: /local/Icons/gelbersack.png
        notification_icon: mdi:delete-clock
        tag: gelberm
mode: single

alias: 'Müll: Papier'
description: ''
trigger:
  - platform: time
    at: '18:30'
condition:
  - condition: state
    entity_id: sensor.abfallpapiermuell
    state: morgen
action:
  - service: notify.alle_pixel
    data:
      message: Stell bitte die Tonne an die Straße!
      title: ⏰ Papiermüll wird morgen abgeholt
      data:
        icon_url: /local/Icons/papier.png
        notification_icon: mdi:delete-clock
        tag: papierm
mode: single

alias: 'Müll: Rest'
description: ''
trigger:
  - platform: time
    at: '18:30'
condition:
  - condition: state
    entity_id: sensor.abfallrestmuell
    state: morgen
action:
  - service: notify.alle_pixel
    data:
      message: Stell bitte die Tonne an die Straße!
      title: ⏰ Restmüll wird morgen abgeholt
      data:
        icon_url: /local/Icons/rest.png
        notification_icon: mdi:delete-clock
        tag: restm
mode: single

Here’s what I suggest:

alias: consolidated example
description: ''
variables:
  sensors: >
    {{ expand('sensor.abfallbiomuell', 'sensor.abfallgelbersack', 'sensor.abfallpapiermuell', 'sensor.abfallrestmuell')
      | selectattr('state', 'eq', 'morgen') | map(attribute='object_id') | list }}
trigger:
  - platform: time
    at: '18:30'
condition: "{{ sensors | count > 0 }}"
action:
  - variables:
      values:
        abfallbiomuell:
          message: 'den Sack'
          title: 'Biomüll wird'
          icon: bio
          tag: biom
        abfallgelbersack:
          message: 'die Säcke'
          title: 'Gelbe Säcke werden'
          icon: gelbersack
          tag: gelberm
        abfallpapiermuell:
          message: 'die Tonne'
          title: 'Papiermüll wird'
          icon: papier
          tag: papierm
        abfallrestmuell:
          message: 'die Tonne'
          title: 'Restmüll wird'
          icon: rest
          tag: restm
      unknown:
        message: Unknown
        title: Unknown
        icon: help-circle
        tag: unknown
  - repeat:
      for_each: "{{ sensors }}"
      sequence:
        - variables:
            x: "{{ values.get(repeat.item, unknown) }}"
        - service: notify.alle_pixel
          data:
            message: "Stell bitte {{ x.message }} an die Straße!"
            title: "⏰ {{ x.title }} morgen abgeholt"
            data:
              icon_url: "/local/Icons/{{ x.icon }}.png"
              notification_icon: mdi:delete-clock
              tag: "{{ x.tag }}"
        - delay:
            seconds: 2
mode: single

This one is good. I would combine the text in one message as well, like my window alert

      {{ fenster | join('-, ') | regex_replace(find=',([^,]*)$', replace=' und\\1', ignorecase=False) }}fenster immer noch lange auf

But the initial post at least seams, that the RodgerDoger is not yet that familiar with all the stuff, so I would start with something like.

alias: 'Trash: Bio'
description: ''
trigger:
  - platform: time
    at: '18:30'
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: sensor.trashbio
        state: morgen
      - condition: state
        entity_id: sensor.bla
        state: morgen
      - condition: state
        entity_id: sensor.blub
        state: morgen
action:
  - if:
      - condition: state
        entity_id: sensor.trashbio
        state: morgen
    then:
      - service: notify.all_mobile_phones
        data:
          message: Please put the trashbag out!
          title: ⏰ Bio trash is due tomorrow
          data:
            icon_url: /local/Icons/bio.png
            notification_icon: mdi:delete-clock
            tag: biom
  - if:
      - condition: state
        entity_id: sensor.bla
        state: morgen
    then:
      - service: notify.all_mobile_phones
        data:
          message: Please put the trashbag out!
          title: ⏰ Bio trash is due tomorrow
          data:
            icon_url: /local/Icons/bio.png
            notification_icon: mdi:delete-clock
            tag: biom
  - if:
      - condition: state
        entity_id: sensor.blub
        state: morgen
    then:
      - service: notify.all_mobile_phones
        data:
          message: Please put the trashbag out!
          title: ⏰ Bio trash is due tomorrow
          data:
            icon_url: /local/Icons/bio.png
            notification_icon: mdi:delete-clock
            tag: biom
mode: single

But of course, you can learn more if you try the understand, what Taras proposed. And yes, this example has a lot of spots for improvements, but brings you at least in if-the, conditions, or, etc.

1 Like

FWIW, I had intended to do that but I don’t know enough German to ensure the resulting message’s grammar is correct (gender; singular vs plural). So I left it as separate notifications using the original phrases RodgerDodger created. Plus it preserves the unique icon and tag that has been defined for each trash collection type. However, yes, it’s possible to consolidate multiple trash collection types into a single notification.

@arganto & @123 Thank you guys very much for the extensive replys and different perspectives to solve my “problem”.

Both automation look like something I could use and supplementary I can expand horizon on. I will mark 123s post as the solution as he needs it the most but argantos will be useful for me and hopefully anybody who stumbles into this thread.

Have a nice weekend!

1 Like