Sensor Template or Template Sensor?

Team,
Just going through my configuration.yaml when I noticed that I have 2 ways of configuring sensors.

  • Template with a sensor
  • Sensor with a template

???

Example:

template:
  - sensor: 
    - name: "e-usage sensor"
      unit_of_measurement: "kWh"
        state: "{{ (states('sensor.electricity_lamp1') | float(0)) | round(2) }}"
        device_class: energy
        state_class: measurement

And also sensors that have templates in them? Example:

sensor:
  - platform: template
    sensors:
      ha_uptime_minutes:
        friendly_name: HA Uptime Minutes
        value_template: >
          {{ (as_timestamp(now()) - as_timestamp(states('sensor.ha_uptime'))) // 60| round (0)  }}

Did I miss overlook in the documentation? What is the difference and when should I use one or the other?
:slightly_smiling_face: :+1:

BTW, I keep reading about “legacy templates” and “modern templates” but was unable to find the difference.

1 Like

See Template and (on that page) Legacy sensor configuration format.

2 Likes

That’s what I missed :slight_smile:
I had a feeling that the initial question had something to do with the “legacy templates” - thanks for the pointer!

1 Like