Blueprints for template entities #1027
-
PR here home-assistant/core#126971 ContextTemplate entities (especially
ProposalAllow blueprints for template entities, which can be shared using the same mechanism as blueprints for automations and scripts. These blueprints could then be instantiated by populating input fields, each instance creating an entity. Blueprints could be shared among users just as automation or script blueprints and they could be instantiated multiple times in a HA server. More over, the re-import blueprint functionality should work out of the box for these blueprints, with the same caveats as for other types of blueprints (i.e. potential breaking changes could be fetched upon re-import). Example config#/config/blueprints/template/simple_invert.yaml
blueprint:
name: Invert a binary sensor
description: Creates a binary_sensor which holds the inverted value of a reference binary_sensor
domain: template
source_url: http://example.com # used for updates
input:
original_entity:
name: Binary sensor to be inverted
description: The binary_sensor which needs to have its value inverted
selector:
entity:
domain: binary_sensor
variables:
original_entity: !input original_entity
binary_sensor:
state: >
{% if states(original_entity) == 'on' %}
off
{% elif states(original_entity) == 'off' %}
on
{% else %}
{{ states(original_entity) }}
{% endif %}
# delay_on: not_used in this example
# delay_off: not_used in this example
# auto_off: not_used in this example
availability: "{{ states(original_entity) not in ('unknown', 'unavailable') }}" #/config/configuration.yaml
...
template:
- use_blueprint:
path: simple_invert.yaml
input:
original_entity: binary_sensor.foo
name: Inverted foo
unique_id: inverted_binary_sensor_foo
- use_blueprint:
path: simple_invert.yaml
input:
original_entity: binary_sensor.bar
name: Inverted bar
unique_id: inverted_binary_sensor_bar |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 11 replies
-
I certainly have a bunch of template sensors that would benefit from something like this. I guess they'd fall under occupancy logic. I need to create one timer and 2 sensors per instance of this logic, and a couple of automations on top. |
Beta Was this translation helpful? Give feedback.
-
I like the idea a lot. Templates are quite intense and scary for the gui people we are attracting now, and I would love to be able to help people with this in a meaningful way. |
Beta Was this translation helpful? Give feedback.
-
People are afraid of Templates. They can be daunting for sure. I would love to be able to provide canned examples for people to just use or as happens now with blueprints, to copy and tweak to their own uses. |
Beta Was this translation helpful? Give feedback.
-
This would be ideal for the project I am working on. I am creating a template sensor per visual satellite device. I can see this being intimidating for new users so I've started to look at creating an extension just to create these devices. This proposed blueprint would make creating these really easy. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
We've discussed this proposal in the Core team, and decided to approve it. @tetele I'll review the PR when it's up. 👍 |
Beta Was this translation helpful? Give feedback.
-
Does anyone want to help out with the frontend for this? Should that be a separate architectural discussion? I'm thinking including the template blueprints in https://my.home-assistant.io/redirect/blueprints/ (and possibly moving that section separately, since it would no longer pertain only to automations and scripts), adding the "filter by blueprint" functionality in the helpers dashboard and whatever else I couldn't think of atm. Not sure if the config flow for setting up new blueprint-based template entities in the UI needs any frontend work, but that would need to be tackled as well, if it is indeed needed. |
Beta Was this translation helpful? Give feedback.
-
It's a great work! I'm waiting when this feature will go from RC to release. Meanwhile I try to understand how to make the sample blueprint work in case when my configuration is split into multiple files. I see that in the sample blueprint yaml the blueprint and the binary_sensor sections are on the same level. It's not a mistake? It means I should split them into multiple files? |
Beta Was this translation helpful? Give feedback.
-
Looks like switch is still using the 'platform: template' syntax, and thus not supported by this PR? |
Beta Was this translation helpful? Give feedback.
We've discussed this proposal in the Core team, and decided to approve it. @tetele I'll review the PR when it's up. 👍