You have a few issues in your if and elif statements. You seem to have combined two different methods… and you are missing quote marks around the names of your sources.
Method 1: Use is_state_attr(). This is the preferred method
{% if is_state_attr('device_tracker.02b8b6be_e768_4cf3_9006_2e9c0463815c_100_1', 'source', 'esp32-bluetooth-proxy-5e9b38') %}
Method 2: Use a == comparison
{% if state_attr('device_tracker.02b8b6be_e768_4cf3_9006_2e9c0463815c_100_1', 'source') == 'esp32-bluetooth-proxy-5e9b38' %}
Either will work, but you can’t mix them up and both need quotes around the source.
There are also other methods that can produce the same results:
Using a Dictionary method
# Updated to current format
template:
- sensor:
name: "Room Presence"
state: >-
{% set source = state_attr('device_tracker.02b8b6be_e768_4cf3_9006_2e9c0463815c_100_1', 'source') %}
{% set mapper = {
'esp32-bluetooth-proxy-5e9b38': 'Basement Family Room',
'esp32-bluetooth-proxy-299fcc': 'Family Room',
'esp32-bluetooth-proxy-5a63a8': 'Bonus Room',
'esp32-bluetooth-proxy-5f189c': 'Master Bedroom' } %}
{{ iif( source in mapper.keys(), mapper.get(source), 'Not Home', 'unknown' ) }}
You’re trying to add a Template Sensor defined in legacy format into a file (templates.yaml) containing Template Sensors defined in modern format. You can’t combine the two formats in the same file (new style is in the template: domain whereas old style is in the sensor: domain).
Was this a recent change? I don’t know what I’m having a brain freeze for such a trivial thing, I have two files (three if you include the config.yaml, but I don’t put sensors in there):
templates.yaml- first line in this file is - sensor:
sensors.yaml - each sensor begins with - platform:
when I do a check configuration, it fails all the time when I try to put this new sensor in there. The syntax is fine.
It’s more than that. The new format doesn’t accept friendly_name. It uses name which is used for both the friendly name and the entity_id. Plus the YAML structure is different.
Which means it won’t be the entity’s actual friendly_name.
Here’s a simple example:
The following configuration will produce sensor.example_sensor. However, the entity’s friendly_name will not be “This is an example sensor”. The entity’s friendly_name is the value specified in name.
- sensor:
- name: Example Sensor
state: '{{ true }}'
attributes:
friendly_name: 'This is an example sensor'