General question on configuration.yaml

Hello.
I have a very simple and general question that I should know by now but need to ask…
In my config I have two different entries:

template:
  - sensor:
    - name: solaredge_energy_Current_kW
      state: "{{ (states('sensor.solaredge_current_power') | float / 1000) | round(2) }}"

and this

sensor:
  - platform: command_line
    name: SE4 Malmo Electricity Spot Price Text
    command: curl -s 'https://elen.nu/dagens-spotpris/se4-malmo/' | grep -A 1 "`date +'%Y-%m-%d %H:00'`" | sed  's/,/./g'
    scan_interval: 3600

What is the difference between the “sensor” in this case?
Why is the sensor in the first example under template?
Could I also have a template under “sensor” in the second exampel?
Also, why is “platform:” sometimes needed?

If anyone can link to a training material on these topics it would be great… now I gut and pase and sometines not really knowing what I am doing…

Sensor is an integration. It supports many platforms like, command_line, restful, template, etc. Each of these platforms provide a different way to make a sensor.

Somewhat confusingly, “template” is now an integration too (as well as a platform). It supports binary sensors, sensors and triggered sensors.

So template can be a platform or an integration.

Your first example is the template integration https://www.home-assistant.io/integrations/template/#state-based-template-sensors There is a legacy sensor platform that does most things this does but you are better off using the integration as it can be reloaded and supports some new features. But if you use it, it would start like this:

sensor: # integration
  - platform: template # platform

Your second example is this sensor platform: https://www.home-assistant.io/integrations/sensor.command_line/ and yes it does support template as shown in that document link.

Thanks a lot.
Is there a clean definition on what is a “integration” compared to what is a “platform”?
Like for cameras.

camera: (I suppose this is the integration)
  - platform: generic
    stream......

What does "camera: tell home assistant and what does platform do?
"Camera is the integration I understand from the post but what does it mean for home assistant?
Is it that all entity definitions below the integration will become a “camera”?
Can I somewhere see what platforms different integrations supports?

I hope my questions are not too foolish…

An integration is something you can integrate into home assistant, like a light or camera or switch, etc…

Each integration may (but does not have to) support different platforms that provide how these connect to home assistant and offer different configuration options. e.g. The Generic Camera platform is configured differently to MQTT Camera platform.

The lines get a bit blurred as there are cameras like Amcrest that are camera integrations, not camera platforms.

There is a list of integrations here:

It includes platforms as there is no real distinction made when looking to see if your device is supported. It may be a platform or it may be an integration. The docs for each will tell you which.