Template -> Sensor" vs "Sensor -> Template"

In my configuration.yaml file (which contains code with the structure copied from various places and modified for my needs) I have some code that has the form:

template:
  - sensor:
    - name: ....

and some with the structure:

sensor:
  - platform: template
    sensors:
      sensor_name: .....
  1. which is “more correct” (if either)
  2. what is the difference between the two

(Part of my asking question 2 is that there seem to be differences in the items I can have within each sensor specification.)
Susan

The first one is the more current, and recommended, option.

The second one (with platform) is the older, legacy method, which still works for basic purposes but does not support all the functions that the more modern method does, and is therefor not the recommended method.

The older method is only state-based, i.e. the template is rendered any time there is an update to the state of one of the entities referenced in the template (or at the top of each minute if the now() function is called). The newer method does that too, just with a slightly different set of configuration variables.

The newer method also supports trigger-based sensors, where the user can define triggers and conditions to tailor when the template will be rendered. When using a trigger you can also use actions to retrieve info from certain integrations that support response data. These includes things like calendar events, weather forecasts, and email content.

1 Like

Plus all the blossoming blueprint stuff is using the newer format as a base.

Basically anything new will be based on the new format and probably not backported.

Thank you both.
So, is it recommended that I change all of the ‘old’ style’ to the newer one?
If so, does that impact any other aspect of the dependent configurations? (I ask because I’ve made changes in the past where I deleted a sensor and created a new one only to find that the internal name (not any friendly name) has a “_2” appended to it that messed up other dependencies until I edited them.)
Susan

At this point, only if you want to… AFAIK there have not been any announcements that the legacy method will be fully deprecated any time soon.