Show triggering sensor in notification?

Hi,

I’m looking to have the “triggering” sensor shown in the sent notification, but having trouble setting it up.

Ideally, Home Assistant would shoot off a notification to me, whenever one of my humidity sensors reaches a certain threshold and have that notification contain the sensor in question.

I’ve tried fiddling around with automation templating, but haven’t been able to do what I want.

Any help or pointers in the right direction would be appreaciated.

Cheers,

You should be able to use:

trigger.from_state.attributes.friendly_name

See this thread with examples:

My code is like this:

- id: 'test2'
  alias: Humidity - notify when past 50%
  description: Sends notification when humidity exceeds 50% inside.
  trigger:
  - above: '50'
    entity_id: sensor.humidity
    platform: numeric_state
  condition: []
  action:
  - data:
      message: Sensor {{ trigger.from_state.attributes.friendly }}
    service: notify.telegram

I seem to be doing something wrong, because nothing happens when its triggered?

You asking for a numeric_state above ‘50’ HA see this as a string not a number as you have a ’ around it

we all been there and done this.

just take the quote off it.

  trigger:
  - above: 50
    entity_id: sensor.humidity
    platform: numeric_state

Just tried changing it - HA keeps putting the ’ around my number.

And it works if I just set the notification to a message without my message:

'Sensor {{ trigger.from_state.attributes.friendly }}'

Am I writing the above correctly?

You need also to use data_template:

action:
  - data_template:
      message: "Sensor {{ trigger.from_state.attributes.friendly }}"
    service: notify.telegram

2 Likes

Good Spotting Bro didnt see that one

Still no success. I’m confused :smiley:
This is the full automation.

- id: 'humidity'
  alias: Humidity - notify when past 50%
  description: Sends notification when humidity exceeds 50% inside.
  trigger:
  - above: '50'
    entity_id: sensor.humidity
    platform: numeric_state
  condition: []
  action:
  - data:
      data_template:
        message: Sensor {{ trigger.from_state.attributes.friendly_name }}
    service: notify.telegram

Just tried putting my above code in the template editor. Getting an UndefinedError stating that ‘trigger’ is undefined.

And with this code:


- id: 'humidity'
  alias: Humidity - notify when past 50%
  description: Sends notification when humidity exceeds 50% inside.
  trigger:
  - above: '50'
    entity_id: sensor.humidity
    platform: numeric_state
  condition: []
  action:
  - data_template:
      message: "Sensor {{ trigger.from_state.attributes.friendly_name }}"
    service: notify.telegram

You can’t test this in the template editor as the automation is not triggered and so trigger is not defined

Still nothing. I’m running the sensor via Deconz, which I forgot about until yesterday. Does this change anything?

I might just have reached a point where I’ll settle with just getting a notification with all my humidity sensors if one of them breaks past 50%. Not as smooth or cool, but it useful.

Just to summarize: automation is triggering, you get the notification if you don’t try to get the sensor’s name in the message?
And your goal is to put all humidity sensors in this automation and get the one that pass above 50%?

Issue seems to be telegram. Could you try with persistent notification instead of telegram?

See this thread:

Yes, the problem is the service: notify. …
Follow the above link to fix your issue

Your summation is correct. If I just use “message” I get the notification via Telegram.

Goal is to have all my humidity sensors as triggers and then have the notification only show the only that triggered.

Will try with your suggestion from the other thread, thanks!

Edit:
It worked one time, but no more than that. Weird, since I haven’t changed the code.

- id: 'humidity'
  alias: Humidity - notify when past 50%
  description: Sends notification when humidity exceeds 50% inside.
  trigger:
  - above: '50'
    entity_id: sensor.humidity
    platform: numeric_state
  condition: []
  action:
  - data_template:
      message: 'Sensor {{ trigger.from_state.attributes.friendly_name }}'
      parse_mode: html
      target: *my telegram target id*
    service: telegram_bot.send_message

It works! Thank you!

Seems my issue was that I can’t “execute” the automation to test it, I had to get the sensor above the set point and then it would fire.

Just tried it out with my office and living room sensor - the notification correctly names the triggering sensor.

Thank you again! :smiley: