I do not think that we should implement it as a blueprint - I think it may be a usual automation.
I am also a newbie and it would be great to get an opinion of some expert.
You are correct. Ideally, the automation should use a State Trigger that looks like this where entity_id
is given a list of entities:
trigger:
- platform: state
entity_id:
- sensor.one
- sensor.two
- sensor.three
Unfortunately, a blueprint’s selectors cannot be inserted into a list like that.
Neither of the following two examples work:
trigger:
- platform: state
entity_id:
- !input first_sensor
- !input second_sensor
- !input third_sensor
trigger:
- platform: state
entity_id: !input first_sensor, !input second_sensor, !input third_sensor
That’s why you see the State Trigger used this way in a blueprint:
trigger:
- platform: state
entity_id: !input first_sensor
- platform: state
entity_id: !input second_sensor
- platform: state
entity_id: !input third_sensor
My personal opinion is that if someone is capable of composing an automation, the end-result will be more compact than an automation adapted for use as a blueprint. Future versions of the blueprint feature may change that but, for now, that’s the situation.
Well , that means that for using this blueprint you have to specify a “blueprint call” as long as the very blueprint:
- alias: "Check all my batteries"
description: ''
use_blueprint:
path: check_batteries.yaml
input:
first_sensor: sensor.one
second_sensor: sensor.two
third_sensor: sensor.three
..
tenth_sensor: sensor.ten
So my point - there is no need to create a blueprint, use a usual automation:
trigger:
- platform: state
entity_id:
- sensor.one
- sensor.two
...
- sensor.ten
I do agree that the blueprint in this thread is very useful for study blueprints but will my all respect to the author I think that a usual automation (not a blueprint) is simpler.
I agree. In most cases, it will be simpler, shorter, and possibly more efficient as well.
However, there are users who, for whatever reason, are unable to create their own automations (even with the Automation Editor). Blueprints allow them to use other people’s automations.
Of course, it’s always been possible to use someone else’s automation. However, you had to change all the entities in their automation to make it work on your system. That process involved editing the automation’s text (YAML).
Blueprints let the user select the entities from lists in the UI so they never have to see or edit the actual automation. This is an advantage for new users. However, it means more work for the automation’s author because they have to convert it to a blueprint (and that process might require making the automation larger and more complicated).
Yes, it would be a simple automation. I used it to be able to easily duplicate it across multiple battery devices and then if I later need to update notification, a change in one place would change them all. Hopefully in the future blueprints will allow multiple selections in a list of a trigger similar to a target, then it would be much more helpful.
Personally, I find an automation only works well for this particular problem if the device you’re getting an alert for is your phone. Due to their power draw and usage phone battery level goes up and down quickly. Generally if you get an notification about your phone being at 15-20% or less you’re gonna go plug it in right away.
But for all the other IOT devices around my house, a low battery alert most likely isn’t urgent. I know I have to replace it but I’m not going to drop what I’m doing to go do so. Most of these devices take months or more to deplete the battery. So I prefer an alert since that will continue to bug me until I solve the problem.
For anyone interested, I did a quick write up of my own solution and shared it as a package here (didn’t want to clog up this thread with it). Can’t make it a blueprint unfortunately since its not an automation.
I had a quick look at the multiple inputs and found the below solution to work. This was for an Alexa notification, but should also work in your case.
blueprint:
name: Multiple test
description: 'Test for multiple selections.'
domain: automation
input:
in1:
name: Input1
selector:
entity:
domain: media_player
in2:
name: Input2
selector:
entity:
domain: media_player
in3:
name: Input3
selector:
entity:
domain: media_player
in4:
name: Input4
selector:
entity:
domain: media_player
mode: single
variables:
input1: !input in1
input2: !input in2
input3: !input in3
input4: !input in4
inputs: " {{ input1 }}, {{ input2 }}, {{ input3 }}, {{ input4 }}"
trigger:
- platform: state
entity_id: !input 'in1'
from: "off"
to: "on"
action:
- service: persistent_notification.create
data:
message: "{{ inputs }}"
title: "Test"
- service: notify.alexa_media
data:
target: "{{ inputs }}"
message: test, test, test
data:
type: tts
Also if you add Default: “” to your inputs it allows you to put in less than the maximum number.
echo_device2:
name: Second Alexa
description: The Second Alexa device to make the announcement on. Make a comma seperated list to announce on multiple devices.
selector:
entity:
domain: media_player
default: ""
All good till someone comes around needing 1 more device than you have inputs available in the blueprint Hopefully in the future there is a selector solution for inputs that would solve this
@CentralCommand Everyone will have different preferences, let’s not lose sight that the blueprints are a tool to share your automations with someone else that may want to do the same thing. You could go through every one and decide it doesn’t work for you or you prefer it to be another way due to the large flexibility available for each scenario.
Great Job! saved me a lot of work figuring something ou myself.
BTW, for myself I decided not to use MobileApp notifications at all - everything goes to Telegram to different chats:
I have different chats with names like LIfe360, Net, Sys etc.
It is possible to see all messages’ history if required, cleaning chats,…
I’m trying to use this, but i get:
“Error rendering variables: TemplateError: str: Invalid domain name ‘’”
What is the issue herE?
I’m sending a notification to an iPhone with the HA app
What inputs did you pass?
My automation look like this:
alias: Battery Level Notification
description: ''
use_blueprint:
path: jazakrzewski/send-notification-for-battery-level.yaml
input:
message: ' {{ entity_name }} battery has dropped to {{ battery_level }}% '
battery_entity: sensor.achterdeur_battery_level
notify_device: 621869ba5dd715a0989efa6d994c05e3
The battery entity is a door-sensor, available from the dropdown. Same goes for the device, it’s a HA mobile application on iOS.
Please give your full error.
To be complete:
Logger: homeassistant.components.automation.battery_level_notification
Source: components/automation/__init__.py:452
Integration: Automation (documentation, issues)
First occurred: April 19, 2021, 10:13:03 AM (4 occurrences)
Last logged: 8:30:21 AM
Error rendering variables: TemplateError: str: Invalid domain name ''
Automation:
alias: Battery Level Notification
description: ''
use_blueprint:
path: jazakrzewski/send-notification-for-battery-level.yaml
input:
message: ' {{ entity_name }} battery has dropped to {{ battery_level }}% '
battery_entity: sensor.achterdeur_battery_level
notify_device: 621869ba5dd715a0989efa6d994c05e3
The full blueprint, which is the same as in the OP:
blueprint:
name: Battery Level Notification
description: Send a notification to a device when battery drops below a specified
value
domain: automation
input:
battery_entity:
name: Entity
selector:
entity:
domain: sensor
device_class: battery
battery_level:
name: Battery level
description: What level the device should be to trigger the notification.
default: 50
selector:
number:
min: 1.0
max: 100.0
unit_of_measurement: '%'
step: 1.0
mode: slider
notify_device:
name: Device to notify
description: Device needs to run the official Home Assistant app to receive
notifications.
selector:
device:
integration: mobile_app
message:
name: Message
description: 'Default: " {{ entity_name }} battery has dropped to {{ battery_level
}}% "'
default: ' {{ entity_name }} battery has dropped to {{ battery_level }}% '
source_url: https://community.home-assistant.io/t/send-notification-for-battery-level/255733
trigger:
- platform: numeric_state
entity_id: !input 'battery_entity'
below: !input 'battery_level'
variables:
entity_name: '{{ states[trigger.entity_id].name }}'
battery_level: '{{ states(trigger.entity_id) }}'
action:
domain: mobile_app
type: notify
device_id: !input 'notify_device'
message: !input 'message'
Is there really nothing else, like which line it’s on? I can’t figure it out. Maybe the OP might know.
it’s possible to add an action field for service calling? i want to be able to select multiple devices or send a message to telegram
I am getting the same
Error rendering variables: TemplateError: str: Invalid domain name ''
error, and I am also getting the warning:
Template variable warning: 'dict object' has no attribute 'entity_id' when rendering '{{ states[trigger.entity_id].name }}'