I’m trying to use the “modern configuration” for a template sensor for the first time (according to https://www.home-assistant.io/integrations/template/#configuration-variables).
What I have:
template:
- sensor:
- name: Statistik Entitäten gesamt
unique_id: statistics_entities_total
state_class: total
icon: mdi:numeric
state: "{{ states | list | length }}"
What I got:
1. How do I set the entity_id?
I thought the value set for unique_id
would be used for this. I don’t want (initially!) the entity_id to be based on the entity name. That has a few downsides like trash being sent to the InfluxDB, additional manual steps etc. etc…
What I found (and couldn’t imagine this really is the “new and recommended way” - really guys?!?):
I need to do this manually after creating the sensor using customization.yaml or the UI. That’s a big step back dear devs. Almost doubles the work… I tend to switch back to the old format, same situation like Mutt in https://community.home-assistant.io/t/use-of-new-template-sensor-binary-sensor-format/355958/13.
2. How to set the availability?
If - for whatever reason - the sensor value can’t be calculated (or is negative/below zero), I want the sensor to be unavailable. This is not based on another sensor value like we typically use for availability, but the sensor value itself. Do I need to repeat the state
content or is there some kind of “self-reference”?
In other words: in the above example, do I need to use this or is there a smarter, less repeating way?
availability: "{{ (states | list | length) | int(0) > -1 }}"
1 post - 1 participant