New sensor Template configuration format in sensor.yaml, is it working?

Yeah, I’ve also read all your other non working examples and guesswork fixes, so I guess I wanted to double check.

You mean that one single non-working post based on an assumption on how the all the other fields in home assistant work? The template field is a special case, I’m sorry that single post ruined your evening.

FWIW, I just re-organized my Template entities using what I had suggested earlier and can confirm it works (as expected).

I created a sub-directory called templates and moved all of my existing Template entities (58 in total and all are defined using the new format) into separate files, organized by the entity’s type. There are five files within the templates directory:

Screenshot from 2021-11-03 14-39-37

The configuration.yaml file now contains this:

template: !include_dir_merge_list templates/

It passes Check Configuration and, after restarting Home Assistant, all 58 Template entities are properly generated.

Yes, that’s what I use in my config

So I wasn’t completely wrong. I just added a stray “_” in my suggestion. :wink:

It really doesn’t work the same as the rest.

Ya. I think this all stems from how bad this stuff was hamfisted into HA back in the day. Still hasn’t been refactored

Petro you helped me understand this splitting issue in another thread a couple of years ago. I believe there was 4 or 5 messages back and forth that I finally understood. Maybe if you have time you can add many of the pictures you posted to the docs?

you got a link to that convo?

Sorry I didn’t link it before ( I was on the my phone and it wasn’t easy to find).

https://community.home-assistant.io/t/lovelace-button-card/65981/3285

We had several messages back and forth for me to (almost) understand. I still make mistakes sometimes.
You took a lot of time walking me through this with pictures and it was very helpful.

Ah, ok, I forgot about that

Ok so now I’m playing around with a very simple template…
This is my template called presence.yaml that I put in my sensor folder [and my sensor folder is included in my config.yaml].

- platform: template
  sensors:
    john_presence:
      friendly_name: John presence
      value_template: >-
        {% if is_state (device_tracker.sm_f926u1, away) %} 
            John's Out {% else %} 
            John's In {% endif %}

to that end I put this in my lovelace.yaml:

##################################################################
#                Bathroom  INFO                                  #
##################################################################

  - title: Bathroom
    icon: mdi:paper-roll
    cards:

      - type: horizontal-stack
        cards:
        - <<: *cb_spacer_10px        
        - type: entities
          entities:
            - sensor.john_presence   

I get back:

John’s presence unavailble

Where did I go wrong? or what did I not do :slight_smile:

Always consult the under the hood state in the developer tools → states page. There, you’ll see that away is not a state used by device_trackers.

Secondly, you’re missing quotes around all your strings.

{% if is_state('device_tracker.sm_f926u1', 'not_home') %}
1 Like

Ok that makes sense! NOW to figure out how to show pictures instead :slight_smile: