steadi
(Peter)
June 22, 2020, 8:14pm
1
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,
makai
June 22, 2020, 8:27pm
2
You should be able to use:
trigger.from_state.attributes.friendly_name
See this thread with examples:
How do I get the names of what devices triggered an alarm in an automation?
I’m just using the basic manual alarm and I’ve confirmed that everything works well for arming/disarming and triggering. I get a basic notification right now that the alarm was triggered, but I can’t figure out how to tell which device triggered the alert…
Is there a simple way to add a template to a notification for which sensor(s) tripped the alarm?
steadi
(Peter)
June 22, 2020, 8:47pm
3
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?
myle
(StePhan McKillen (Other kiwi Here))
June 23, 2020, 3:35am
4
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
steadi
(Peter)
June 23, 2020, 6:05am
5
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?
makai
June 23, 2020, 6:07am
6
You need also to use data_template:
action:
- data_template:
message: "Sensor {{ trigger.from_state.attributes.friendly }}"
service: notify.telegram
2 Likes
myle
(StePhan McKillen (Other kiwi Here))
June 23, 2020, 6:31am
7
Good Spotting Bro didnt see that one
steadi
(Peter)
June 23, 2020, 7:09am
8
Still no success. I’m confused
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
steadi
(Peter)
June 23, 2020, 10:20am
9
Just tried putting my above code in the template editor. Getting an UndefinedError stating that ‘trigger’ is undefined.
makai
June 23, 2020, 3:57pm
10
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
steadi
(Peter)
June 24, 2020, 5:45am
11
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.
makai
June 24, 2020, 6:12am
12
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:
Hi there, I am trying to create an automation to notify the start of irrigation
- alias: 'Sprinkler notification'
trigger:
- platform: state
entity_id:
- switch.zone_4
- switch.zone_3
- switch.zone_2
- switch.zone_1
to: 'on'
action:
service: notify.home
data_template:
message: '{{ trigger.entity_id }}'
unfortunately it works with
data:
message: "Sprinkler on"
but it doesn’t work with data_template to select an entity_id.
thanks…
Yes, the problem is the service: notify. …
Follow the above link to fix your issue
steadi
(Peter)
June 24, 2020, 6:53am
14
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
steadi
(Peter)
June 24, 2020, 8:11am
15
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!