Trigger from scrape-sensor does not have friendly_name or entity_id

Hi together,

I am running Home Assistant 2022.3.8 on RaspberryPI (Version core-2022.3.8;|Installation Type: Home Assistant OS) and encountered the following issue:

I created multiple scrape sensors like this:

sensor:
 - platform: scrape
    resource: https://www.xyz.com
    select: ".XYZ"
    index: 2
    value_template: '{{ ((value.strip())| replace ("\n", " ")) }}'
    scan_interval: 600  
    name: scrape_name_1
  - platform: scrape
    resource: https://www.xyz.com
    select: ".XYZ"
    index: 3
    value_template: '{{ ((value.strip())| replace ("\n", " ")) }}'
    scan_interval: 600  
    name: scrape_name_2

and an automation like this:

- id: '1234567'
  alias: Notify_test
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.scrape_name_1
  - platform: state
    entity_id: sensor.scrape_name_2
  condition: []
  action:
  - service: notify.telegramNotify
    data:
      message: >-
    {{ trigger.to_state.attributes.friendly_name }} changed from "{{
    trigger.from_state.state }}" to "{{ trigger.to_state.state }}"
  mode: queued

The problem lies with the first part of the message, where I want to get the name of the trigger. If I remove this, all works fine. If I leave it in, no message gets send. When I use

{{ trigger.id }}

I get the index of the trigger (0 or 1), but eg.

{{ trigger.entity_id }}

already does not work.

I already tried a bunch of options, but nothing seems to work. Does the scrape-sensor as a trigger not provide its friendly_name?

Thank you for any advice!

Best,
Johannes

You can probably use

- id: '1234567'
  alias: Notify_test
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.scrape_name_1
    id: "friendly name 1"
  - platform: state
    entity_id: sensor.scrape_name_2
    id: "friendly name 2"
  condition: []
  action:
  - service: notify.telegramNotify
    data:
      message: >-
    {{ trigger.id }} changed from "{{
    trigger.from_state.state }}" to "{{ trigger.to_state.state }}"
  mode: queued
1 Like

Thank you @Hellis81!
That does work, but it seems a bit like a workaround, as I would then have to assign the id in each automation for all triggers, instead of once per sensor in the configuration.
Is there a reason that the friendly_name or entity_id are not passed along in this case?

Correct.
It’s a workaround and I’m not sure if there is a proper way to get the friendly name.