hapim
(Pim)
February 25, 2024, 7:16pm
1
I’m trying to understand the new template feature.
It seems very powerfull (as the read complexity of the documentation also implies).
For those looking for an example on the new template feature, this is a sensor that shows the last item played by one of the listed media players.
As you can see the new templates are close to what automations provide (templates can have actions as well).
What a template doesn’t seem to support are conditions.
In this example a condition might be the type of source selected and depending on that type decide whether or not to update the sensor values.
Alternatively, I read something about self referencing support (i.e. a variable this referencing to the current state of the sensor).
I guess that could also be a way to preserve the old state when conditions aren’t met?
#configuration.yaml
template: !include templates.yaml
#templates.yaml
- trigger:
- platform: state
entity_id:
- media_player.woonkamer
- media_player.badkamer
- media_player.slaapkamer
- media_player.werkkamer
- media_player.opbouw
to: "playing"
unique_id: bc528955-ebb4-42d4-a9d3-6fdfdd147807
sensor:
- name: "DJ MiCasa"
unique_id: "dj_micasa"
state: >
{{ trigger.to_state.state }}
attributes:
media_channel: "{{ trigger.to_state.attributes.media_channel }}"
media_content_id: "{{ trigger.to_state.attributes.media_content_id }}"
media_content_type: "{{ trigger.to_state.attributes.media_content_type }}"
entity_picture: "{{ trigger.to_state.attributes.entity_picture }}"
123
(Taras)
February 25, 2024, 10:04pm
2
What is “new” about the “new template feature” you are demonstrating?
Your example is a Trigger-based Template Sensor which is a feature created nearly 3 years ago (2021.4.0).
hapim
(Pim)
February 26, 2024, 10:18pm
3
@123 I guess I misinterpreted the many blogs and posts stating the new way was introduced around 2023.
I had some trouble understanding without a complete example and thus figured my learnings would help others.
No pun intended!
123
(Taras)
February 26, 2024, 10:44pm
4
Can you share links to a few of these “many blogs and posts” from 2023? I’m curious to see what they say exactly.
hapim
(Pim)
February 26, 2024, 11:03pm
5
I’ve been al over the internet for this
What I could condensate from my browser history:
I’m trying to migrate my old template entities to the new format but notice that not only do all the old template entities remain (after restarts, reloads, etc) but they cannot be removed because they don’t have a the unique ID.
So this is to say that this old style:
switch:
- platform: template
switches:
my_switch:
...
Sticks around, even though I’m now using an entirely different file and the new template style. How do I get rid of these old templated devices?
I’ve added a sensor into my configuration.yaml as such:
sensor:
- platform: template
sensors:
gas_meter_counter_m3:
value_template: "{{ ((states.counter.gas_meter_counter.state | float) / 100) }}"
unit_of_measurement: "m³"
device_class: "gas"
but as soon as I add state_class: "total_increasing" beneath the device_class line, the sensor disappears from Home Assistant (doesn’t show up in developer tools or anything either)
What am I doing wrong?
Did you find solution yet?
I’m trying the create a template image entity.
Because documentation on how to create these is hard to understand, and now I also have an bunch of entities which I can seem to remove.
The delete button is greyed out.
I wish these kind of things were more intuitive in HA or at least that the documentation would provide complete(!) yaml examples.
Playing with templates. (not the legacy way, but the “new” way) See docs…
In tht “state” part of the template, I can reference an attribute like “this.attriibutes.myattributename”
Isn’t is possible in the “attributes part”, to reference to another attribute?
I get errors in the logging that it doesn’t “know” the referenced attribute.
Someone had a problem with this too? Or, isn’t it possible.
https://www.reddit.com/r/homeassistant/comments/pysnxa/how_do_template_triggers_work/?rdt=36584
https://www.reddit.com/r/homeassistant/comments/pysnxa/how_do_template_triggers_work/
Hi!
I want to make an automation which triggers with a template, but I don’t know what I’m wrong… I want to do some actions, if timestamp is lower than 1 (which is not). But everytime I run the automation, I will still receive the message…
I have this code till now
alias: test
description: ''
trigger:
- platform: template
value_template: '{{ as_timestamp(now())|int < 1 }}'
condition: []
action:
- service: notify.persistent_notification
data:
message: ok
mode: single
I would like to use templates for two use cases:
(1) I would like to have a single battery sensor which state shows the lowest battery value of any battery operated device in Home Assistant. Is it possible to iterate through all battery operated devices, e.g. I don’t want to explicitly to refer to the devices. I should not have to update the template sensor if I add a new device.
(2) I would like to create a template sensor (template trigger) which would trigger any of sensors in that template…
Hi,
I start playing with the “picture-elements”.
I would like to change dynamically the background-color when the “humidity” of one sensor is above 50% (visual feedback, kind of alerting).
I am back to even a more basic question: is templating supported in this card ?
As an example below, I simply try to have the “Title” being displayed dynamically without success
But when reopening the editor (in lovelace), the row
{{ states(‘counter.presence_hall’)}}
has been replaced by
’[object Objec…
For my frontdoor I’m working on a way to see who rang the doorbell. First I set an input_datetime and use this to store the image and to display the image.
service: input_datetime.set_datetime
target:
entity_id: input_datetime.deurbel_history_1
data:
timestamp: '{{ now().timestamp()|int }}'
service: camera.snapshot
target:
entity_id: camera.voordeur
data:
filename: >-
/config/www/camera_voordeur/voordeur_{{
(state_attr("input_datetime.deurbel_history_1","timestamp")) }}.jpg
Im…
have a sensor that I convert from hours to percent, that works as far as all goes well.
But I would like to have different icons for the states.
and I would need something that I the sensor value of 1 percent to 5 percent indicates an icon, etc …
Pellets Aschelade 800h Brenndauer ist wenn Aschelade LEER!
platform: template
sensors:
asche_sensor:
entity_id: sensor.asche_sensor
value_template: ‘{{100-((states. sensor.verbleibende_heizstunden_bis_zur_asche_entleeren_warnung.state | int) / 8…
If it didn’t have an id all you have to do is delete the yaml config and restart.
If it did have an id you should be able to delete it from the configuration entities list after deleting the yaml and restarting.
You don’t get a pop up box when you click on the entity that says something like “this is an orphan…” with an option to remove the entity?
If not then you may have to edit the .storage files manually to delete them.
Hello,
I’m trying to setup a series of simple entities that reflect the direction/vector across any two motion sensors, and from there build some clever automations that watch those entities.
I have a template with two test sensors working, but I can’t seem to get the “unique_id” property to reflect in HA’s interface.
The below just gives me an entity named “sensor.test_a”:
- unique_id: asdf
- sensor:
name: a_to_b
state: >
{{ is_state("binary_sensor.roomA_sensor_motion", "on")…
I am using an Elgato stream deck, and I can display multi-line output for a single button… but only if the data comes from the attributes of a single sensor. This works with yahoofinance and rest platform entities, but I can’t figure out how to do it with a template platform entity. This code creates four separate entities:
- platform: template
sensors:
pge:
friendly_name: "PG&E"
value_template: >-
{{ states('sensor.eagle_200_meter_power_demand') | int }}…
123
(Taras)
February 26, 2024, 11:27pm
6
Your very first link leads to a topic created in 2021.
The second link leads to a topic created this year but the user is still using the legacy method of defining a Template Sensor which was deprecated years ago.
The third link leads to one of your own posts created this year where you report your inability to understand the documentation for creating a Template Sensor.
The fourth link leads to a topic created nearly 2 years ago.
The links to YouTube tutorials explain features that have existed in Home Assistant well before the tutorials were created.
I stopped reviewing the remaining links because it’s clear that nothing posted recently can legitimately claim a Trigger-based Template Sensor is a new feature. It was introduced years ago, shortly after a new configuration style was adopted for Template entities.
Perhaps the only thing new about it is that you recently discovered it and so it’s new for you.
1 Like
hapim
(Pim)
February 27, 2024, 7:04pm
7
@123 you’re right I’m new and was struggling.
I’m happy I figured it out and going to stay happy (not addressing hospitality) closing this thread.
1 Like