Variable notification

Hi all,

I build a (actionable) notification that telle me that a light is on when I’m not home. Now the notification says something like: “There is still a light on”. Would it be possible to make this a variable message that tells me which lamp is on?

This is my config now:

- id: '0000000000010'
  alias: Action Push Message
  initial_state: 'on'
  trigger:
  - platform: state
    entity_id: group.verlichting
    to: 'on'
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: device_tracker.iphone_van_r
      state: not_home
  action:
    service: notify.ios_iphone_van_r
    data:
      message: Er staat nog verlichting aan!
      data:
        push:
          badge: 0
          category: lights
        action_data:
          entity_id: group.verlichting
{{ states
   |selectattr('entity_id','in',state_attr('group.verlichting','entity_id'))
   |selectattr('state','eq','on')|map(attribute='name')|join(', ') }}

Will return a comma separated list of names of entities in the group that are on.

1 Like

Thanks. I get some errors, must be something simple with comma or quote or something, but I can’t find it.

Error loading /home/homeassistant/.homeassistant/configuration.yaml: while parsing a flow mapping in "/home/homeassistant/.homeassistant/automations.yaml", line 188, column 17 expected ',' or '}', but got '<scalar>' in "/home/homeassistant/.homeassistant/automations.yaml", line 189, column 75

What is at line 189, column 75 of automations.yaml? Not sure how that error message has anything to do with the template I suggested since there are no less than or greater than symbols, or numbers, in it.

Sorry for the misunderstanding.

This is line 189:
|selectattr('entity_id','in',state_attr('group.verlichting','entity_id'))

I counted the columms and it seems to be the { and } signs. I re-typed them but without any luck.

I’m guessing you aren’t using the multiline notation.

    service: notify.ios_iphone_van_r
    data_template:
      message: > #THIS IS MULTILINE NOTATION
        Er staat nog verlichting aan! {{ states |selectattr('entity_id','in',state_attr('group.verlichting','entity_id'))
            |selectattr('state','eq','on')|map(attribute='name')|join(', ') }}
      data:
        push:
          badge: 0
          category: lights
        action_data:
          entity_id: group.verlichting
1 Like

There are no less than or greater than symbols on that line. Why don’t you post the entire automation?

1 Like

I tried both single line and multi line. But this works perfectly. Thank you so much both!

1 Like

Just for your own edification, the only things I changed were:

  1. Changed data line to data_template. This is required for templating. I.E. {{ }} and {% %}.
  2. Added multi-line character after message.
  3. Copied @pnbruckner’s template at the end of your message.

I’m guesssing you may have been missing one of those steps.

1 Like

since I use almost the same notification but without the action_data: group.verlichting, I wonder why you use that?
I get correct notifications without …

That just adds the entity_id to the action_data in a event that gets fired after the notification. Has no bearing on the actual message.

1 Like