Notification Message Spaces

I use the below automation to advise me if windows are still open when either I leave the house or window blinds close.

However, for some reason, a space is being placed in front of the comma. I can’t figure out why so if anyone could maybe please point out what may be wrong with the automation that’s causing this?

Ideally, I’d prefer each window name to be on a separate line but I’ve added \n, as you can see, and that doesn’t appear to work.

automation action

  action:
  - service: notify.mobile_app_iphone_m
    data:
      title: Windows are OPEN!!
      message: "{{ expand('binary_sensor.windows')\n  |selectattr('state', 'eq',
        'on')\n  |map(attribute='name')\n |list \n  |replace(\"[\",\"\")\n  |replace(\"]\",\"
        \")\n  |replace(\"\\x27\",\"\")\n  |replace(\"\\x22\",\"\")\n  |replace(\"Window\",\"\")
        \n |replace(\"Sensor\",\"\")\n}}\n"

try this template approach. it cleans up a lot of what you have, and i think makes it much easier to read. you should take advantage of the > and | to not have to do all the \ escaping you’re doing.

  action:
  - service: notify.mobile_app_iphone_m
    data:
      title: Windows are OPEN!!
      message: >
        {{ expand('binary_sensor.windows') | selectattr('state', 'eq', 'on') | 
           map(attribute='name') | list | join(',\n') }}

i’m not sure if this removes the extra space tho. i am guessing that you have something like

“Kitchen Window”. or “Kitchen Sensor”. so when you repalce “Sensor” and “Window” with “” you end up with "Kitchen ". if my guess is right, then you need to also replace that space before Sensor and Window. try this:

  action:
  - service: notify.mobile_app_iphone_m
    data:
      title: Windows are OPEN!!
      message: >
        {{ expand('binary_sensor.windows') | selectattr('state', 'eq', 'on') | 
           map(attribute='name') | list | join(',\n') | replace (' Sensor', '') | replace(' Window','') }}
1 Like

I’ve used your second example, just removing the comma in join(',\n') and it works exactly as I was wanting.

Perfect :smiley: thank you for your help.