Template returns error when no trigger is specified

I’m trying to convert my old templates from the old format:

sensor:
  platform: template

to the new one:

template: 
  - sensor: 

I’m currently trying this config:

template: 
  - sensor: 
      - name: "OnePlus Distance"
        unique_id: '1264321320975731'
        unit_of_measurement: meters
        state: "{{ state_attr('sensor.oneplus_bluetooth_room_presence', 'distance') | int }}"

But I’m getting this error:

  • Invalid config for [template]: required key not provided @ data[‘trigger’]. Got None. (See /config/configuration.yaml, line 111).

If I change the config to…

template: 
  - trigger: 
    sensor: 
      - name: "OnePlus Distance"
        unique_id: '1264321320975731'
        unit_of_measurement: meters
        state: "{{ state_attr('sensor.oneplus_bluetooth_room_presence', 'distance') | int }}"

there is no error in the log, but the sensors only show up with the value ‘Unknown’, and I’m guessing they won’t be updated, since there is no trigger specified. Putting the template in the template debugger returns the value correctly.

The docs say ‘trigger:’ is optional here:

trigger list (optional)

Define an automation trigger to update the entities. Optional. If omitted will update based on referenced entities. [See trigger documentation](https://www.home-assistant.io/docs/automation/trigger).

and it is omitted in multiple example configs, such as here:

template:
  - sensor:
      - name: "Average temperature"
        unit_of_measurement: "°C"
        state: >
          {% set bedroom = states('sensor.bedroom_temperature') | float %}
          {% set kitchen = states('sensor.kitchen_temperature') | float %}

          {{ ((bedroom + kitchen) / 2) | round(1) }}

and I’m having a hard time figuring out why this isn’t working. Hoping I haven’t missed something obvious.

What does {{ state_attr('sensor.oneplus_bluetooth_room_presence', 'distance') | int }} return in the template debugger?

Currently, “3”.

I can’t duplicate your results.

This passes “Check Configuration” and succeeds in creating sensor.length_sensor

template:
  - sensor:
      - name: Length Sensor
        unique_id: length_sensor
        unit_of_measurement: 'm'
        state: "{{ expand('group.input_booleans') | selectattr('state', 'eq', 'on') | list | length }}"

Screenshot from 2021-05-18 14-11-42

Version issue?

It is failing the same way in 2021.4.6 but working in 2021.5.3

1 Like

That must be why. It means Abragus is attempting to do something that wasn’t even available when 2021.4.X was released. The documentation is written for the latest release of Home Assistant and may refer to functionality unavailable in older versions.

Ah, this was it. My Supervisor hadn’t been started correctly, so the update didn’t show up anywhere. HA worked totally fine in every other way, as far as I could see though. I restarted the Core (restarting the Supervisor itself didn’t seem to work, or I was too impatient), and the update showed up. Thanks for pointing me in the right direction!

What led you to believe the feature existed in your older version of Home Assistant?

I believe you already answered that from your previous post.

The docs are very confusing when trying to figure out which things work with which versions.

I’ve recommended a solution to this in the past but it was completely dismissed.

1 Like

Well firstly I didn’t know I wasn’t running the newest version. I have an automation set up to send me a notification whenever there is a new version available, but since the Supervisor was “broken”, there was no notification nor an update button in the Supervisor tab.

Secondly, as @finity said, there was no mention of incompatible version in the docs, so I assumed it had changed during the months that passed since I set up my old template sensors. That’s not to say there has to be a “minimum version” mentioned for everything in the docs, that could probably get a bit messy, but as I said, I thought was running the latest version, so there was no reason to believe it wouldn’t work.

I usually try to keep up with the latest update for this exact reason, and to not encounter problems when I try to update from a version that is more than a few months old (which did happen a few years ago, before I started following this principle.)

That’s surprising.

  1. It runs the version you install.
  2. A new version is released each month (first Wednesday of the month).
  3. You didn’t install May’s release so you weren’t running the latest version.

New month, new version. It’s as simple as that.

If you don’t upgrade in June, to version 2021.6, you won’t be running the latest version either (regardless of whether you receive a notification or not).

The documentation is written to reflect the capabilities of the latest version. If something doesn’t work as described, always ensure you are using the latest version.

In fact, had you raised this as an Issue in GitHub, you would have been required to report the version you are using. As a result, the cause of the problem would have been immediately evident.

For future reference, all posts in this forum are based on the assumption the user is employing the latest major release. There’s no point in reporting issues for older versions because it may have already been corrected in a newer version.

Of course. But I don’t keep track of exactly when I installed the last update, and maybe I should, but I almost never have to, since I always immediately install any new update I see, and then make sure it is installed correctly. I trust my smart home, Home Assistant included, to work correctly and be able to keep track of itself, or inform me anytime that is not the case. This time it didn’t, and so the reasons this post came to be was:

  1. I got no notification about a new update, and there was no update available on the Supervisor page, as stated before…

  2. …which in turn was caused by a problem with the Supervisor, that hadn’t started properly.

  3. The Supervisor otherwise functioned without fault, leading me to believe there was no reason to search for any problems with it.

  4. The fact that there was a problem wasn’t conveyed in any way, shape, or form in the System tab, where all other information about the Supervisor is shown. In fact, the first time there was a sign of something being wrong was when I tried to update from the command line.

  5. And lastly, I didn’t react to the ‘4’ in my Core version in the System tab not matching up with the number of the current month, 5.

Had only one of these points turned out differently, this post would have never existed. I realize I could have found the problem myself, though it was hidden better than most problems I’ve come across have been. I’m infinitely thankful for being part of a community where you are able to get help in a matter of a few hours, however unnecessary your post is in the eyes of the one who is helping you.

Case closed, I appreciate the help.

There’s not much to track, it’s once a month. It’s downright T-shirt worthy: “New month = New release”

  • If it’s mid-May and you have no memory of performing a recent major update, you probably didn’t.

  • Release Notes; they should always be read before performing a major update (otherwise you may introduce a breaking change). If you haven’t read Release Notes recently, then it probably means you haven’t updated in awhile.

For future reference, new functionality only appears in major releases (the 5 in 2021.5.X) and not in patch releases (the X in 2021.5.X). You attempted to use new functionality introduced in 2021.5 using 2021.4.

Your memory is better than mine, then :neutral_face:

1 Like

You made my point. If a monthly task is lost in brain fog, err on the side of caution and assume it wasn’t done.

A cautionary tale for people filing their annual income tax return …

As reported in the 2012.12 Release Notes:

This also means our release schedule is changing. Home Assistant Core will now be released every first Wednesday of the month!

Here’s a simple automation that creates a persistent notification on the first Wednesday of every month.

alias: Major Release Reminder
trigger:
- platform: time
  at: '12:30:00'
condition: "{{ now().isoweekday() == 3 and now().day < 8 }}"
action:
- service: notify.persistent_notification
  data:
    title: "Monthly Major Release"
    message: "It's the first Wednesday of the month. Check for release: {{now().year}}.{{now().month}}"