Need the big picture


I am new to Home Assistant. I am having trouble finding good tutorials that basically teach various concepts.

Now “templates” have their own help and so do other things, but there is nothing that ties all together and gives a big picture view (may be I can’t see and just need someone to point me to it).

What confuses me are terms like: platform, sensor, sensors, template.

I have a working HA for various things, but its more of a use an example and modify. It helps me in the short run but not long run.

My sensor.yaml contains template which contains sensors:

  - platform: template
        value_template: >-
          {{ }}
        unit_of_measurement: 'V'

My template.yaml contains sensor:

  - sensor:
      - name: "Turn Off after"
        unique_id: turn_off_after
        icon: mdi:progress-clock
        state: >
           {% set delay_total_min = states('input_number.countdown_timer') | float * 60 %}
           {% set delay_hour = delay_total_min / 60 %}
           {% set delay_min = delay_total_min % 60 %}
           {{ '%02i:%02i'%(delay_hour, delay_min) }}
          hour: 25
          minute: 26

Both the yaml files contain sensors. If I move them all to one location (say template) and format it accordingly, it does not work.

This confuses me. Any guidance is appreciated.


Well sensor is easy, it senses something. Temperature, Pressure, whether you are home etc.

A template is a programme that calculates one thing from another.

In your first example you have a switch called That switch has an attribute for the voltage. The example converts the attribute to a sensor so that you can show it in the UI.

1 Like

Maybe this could help

Not overly complicated once you have the grasp of it.

Basically, everything in HA relates to entities. An entity is something HA can act upon.
Entities are generated and managed by platforms. A platform is what links HA to a physical (or abstract) device.
All platforms (and thus entities) relate to a domain, which is the high-level “type” of the entity (e.g. “sensor”, “light”, “switch”) and which defines what can be done on the entities.
An integration is the module that handles all domains related to a vendor (or category of device for a vendor). By instance, the “Hue” integration creates specific platforms to manage the “light”, “switch”, … domains when you want to talk to a Philips Hue bridge.


A part of your problem is that HA is evolving and there are often old and new ways to do things, and documentation & tutorials (particularly non-HA ones) can go out of date. Template sensors have a new format that is under template: and a legacy format under sensor: as you have described. See here:

Here’s how my system looks (and make reference to this document). First, the top of configuration.yaml:

automation: !include automations.yaml
automation manual: !include_dir_merge_list automations
binary_sensor: !include binary_sensors.yaml
camera: !include cameras.yaml
climate: !include climate.yaml
group: !include groups.yaml
light: !include lights.yaml
proximity: !include proximity.yaml
rest: !include_dir_merge_list rest
script: !include scripts.yaml
sensor: !include_dir_merge_list sensors
shell_command: !include shell_commands.yaml
switch: !include switches.yaml
template: !include_dir_merge_list templates

For template:, I’m using the new format, and have migrated all of my template sensors to this, so as an example, here is templates/shellies.yaml converting the raw sensor’s W-min units into kWh:

- sensor:
    - name: "Immersion switch energy consumption"
      unique_id: 8190d7b1-63c4-446b-9cda-6b2eb7dd7ed8
      unit_of_measurement: 'kWh'
      device_class: energy
      state: "{{ (states('sensor.immersion_switch_energy')|float / 60000.0)|round(2) }}"

My non-template sensors are spread across files under sensors/ — here is the top of sensors/leaf.yaml:

- platform: mqtt
  name: "LEAF monthly trips"
  unique_id: 55dd8dfa-2d2d-488c-bedc-31ccbd6be94d
  state_topic: "leaf/MY_VIN/tripsNumber"

- platform: mqtt
  name: "LEAF monthly travel time"
  unique_id: 1455042c-1b14-4cb4-bd6c-528d4de3ef1b
  state_topic: "leaf/MY_VIN/traveltime"
  value_template: >-
    {% set vl = value.split(":") %}
    {{ timedelta(0,(vl[0])|int*3600 + (vl[1])|int*60) }}

Hope that helps clarify.

1 Like

Thanks. Your reply is pretty loaded.

I’ll have to read it a couple of times and tinker with the files for it to assimilate.

But you are correct, for some problem that I was facing, I stumbled upon a 2018 post, which I realised would be useless to follow because the syntax has changed since then.


As @Troon said, you’re looking at 2 different ways to implement template sensors. The old way and the new way. You can use them together in the same configuration, but they need to be in their respective ‘homes’. You can’t put the old template in the new template spot or vice versa, ant that’s what you’re attempting to do.

When in doubt, consult the docs. After enough time, you’ll understand the configuration variables and how they are place in yaml. Use the examples in the docs, not on random posts. Come here and ask questions. Most posts older than 6months have outdated information. That’s how fast development moves.

1 Like