So I have made an Automation that sends a Telegram message when one of my battery powered devices report a low battery.
how can I make the message say which device exactly triggered it?
That’s what I have right now:
- id: 'batteriealarm'
alias: Batteriealarm
trigger:
- platform: numeric_state
entity_id:
- sensor.aqara_thp_01_battery
- sensor.aqara_thp_02_battery
- sensor.door_contact_01_battery
- sensor.door_contact_02_battery
- sensor.aqara_wandschalter_01_battery
- sensor.aqara_wandschalter_02_battery
- sensor.aqara_wandschalter_03_battery
- sensor.aqara_wandschalter_04_battery
- sensor.aqara_wandschalter_05_battery
- sensor.aqara_wandschalter_06_battery
- sensor.aqara_button_01_battery
- sensor.aqara_button_02_battery
below: 80
action:
- service: telegram_bot.send_message
data:
disable_notification: false
target: mytelegramid
message: '*Battery empty: xxx*' #replace xxx with entity_id that triggered the Automation
So if for example ‘sensor.aqara_button_02_battery’ reports 74, the message should say “Battery empty: sensor.aqara_button_02_battery ”
Is there a simple way to do that?
Additionally it would be cool if it also adds the percentage (74% in this case)
1 Like
I was just looking at another thread yesterday, for telegram automations, and I think I saw the kind of thing you are looking for.
In the threads linked below, they have multiple entity IDs triggering a single automation, but want to say in a notification the name of the entity that triggered it. They used the template {{trigger.entity_id}}
to specify this.
I haven’t tried it myself, but I think this might point you in the right direction.
I have this configuration:
################## CAMERA RECORDING ################
- alias: 'Camera state recording -> send pic'
hide_entity: True
trigger:
platform: state
entity_id: camera.entrance, camera.garden, camera.parking
to: recording
action:
- service: telegram_bot.send_message
data_template:
message: '{{ trigger.to_state.attributes.friendly_name }} : {{ trigger.from_state.state }} to {{ trigger.to_state.state }}'
- service: camera.snapshot
d…
(And another thread, also with notification based on the trigger’s entity ID)
Hi all,
I just wanted to post my setup using Telegram to send notifications about calendar events and general home information.
The samples below show notifications about:
Home Assistant has booted up,
Nobody detected at home, but some devices are left on,
Notify of an upcoming calendar event (before it happens),
Calendar reminder with actionable “remind me in X minutes”.
Example from below with remind me later buttons:
[Screenshot_20180413-130053~2]
To start with, we define a telegram b…
1 Like
this was exactly what I needed!
Thanks
The action now looks like this and works as expected
action:
- service: telegram_bot.send_message
data_template:
target: 'mytelegramid'
message: '*Battery empty: {{trigger.entity_id}}*'
An additional question - is there a way to not write out the entity_id, but the name of that entity?
So it doesn’t say: “ Battery empty: sensor.aqara_button_02_battery ” but “ Battery empty: Doorbell ”
1 Like
tom_l
May 18, 2019, 9:22am
4
{{ trigger.to_state.attributes.friendly_name }}
3 Likes
this just gives out the entity_id
2 Likes
tom_l
May 18, 2019, 9:35am
6
Does your entity have a friendly_name set?
oh - of course… I’m an idiot… the button does have a friendly name, but the “battery entity” did not
Now it works
1 Like
tom_l
May 18, 2019, 9:44am
8
I just set my smoke alarms off to make sure
4 Likes
123
(Taras)
May 18, 2019, 1:12pm
9
trigger.to_state.name
The State Object has several properties including name
Name of the entity. Based on friendly_name
attribute with fall back to object ID. Example: Kitchen Ceiling
.
Notice that if the entity has no friendly_name
attribute, it falls back to using the object ID.
climate_hall_heat_on: Error executing script. Error rendering template for call_service at pos 6: UndefinedError: 'trigger' is undefined
trigger:
- platform: numeric_state
entity_id: sensor.temperature_158d00019cf466
below: 22
- platform: numeric_state
entity_id: sensor.savednipro_temperature
below: 17
- platform: state
entity_id: input_boolean.heat_hall
to: 'on'
- service: notify.mobile_app_motorola_one_action
data:
title: "Home Assistant"
message: "Запущено {{trigger.to_state.name}}"
1 Like