Platform's how do i use them in YAMl

Hello,
its me again with a YAML problem. Im a little confused about platforms and how to usem them e. g. for sensors.
I made a template sensor for my PV System and a second sensor should integrate the energy.
The first template sensor works well. Here is my template secotion:

template:
    - sensor:
      - name: einspeisung
        unique_id: TEST1
        device_class: power
        state_class: measurement
        unit_of_measurement: W
        state: >
          {% if states("sensor.tasmota_sm_16_7_0")|float > 0 %}
          0
          {% else %}
          {{ states('sensor.tasmota_sm_16_7_0') | float}}
          {% endif %}
         
         
      - platform: integration
        - name: einspeisung_int
          state: on
       #   source: sensor.einspeisung
      #    unique_id: TEST2
        #device_class: power
        #state_class: measurement
        #unit_of_measurement: W
      #    unit_prefix: Wh
        #  round: 2

I need to use the integration Platform for the second sensor.
The first question: I get an error it does not matter, if i placed it like this

template:
  - sensor:
    - name: firstSensor
      ...
    - platform: integration # at this setup the "-" befor the platform, is displayed in black not red
      - name: secondSensor

or

template:
  - sensor:
    - name: firstSensor
      ...
    - name: secondSensor
      - platform: integration

How do i have a integration sensor and one without integration ?

And the second question: If i add a third sensor under the second sensor, is the integral applied to it to ? How do i deactivate it for sensors that will come under the second one ?

Best regards and thank you for your help
Kai

The platform is a sensor platform so it goes under the sensor: integration not under the template: integration, like this:

template:
    - sensor:
      - name: einspeisung
        unique_id: TEST1
        device_class: power
        state_class: measurement
        unit_of_measurement: W
        state: >
          {% if states("sensor.tasmota_sm_16_7_0")|float(0) > 0 %}
            0
          {% else %}
            {{ states('sensor.tasmota_sm_16_7_0')|float(0) }}
          {% endif %}

sensor:
  - platform: integration
    name: Einspeisung Integral
    source: sensor.einspeisung

However, I remember from your previous topic that you have this in your configuration.yaml file:

sensor: !include sensor.yaml

So this goes in your sensor.yaml file instead:

- platform: integration
  name: Einspeisung Integral
  source: sensor.einspeisung
1 Like

Yes, this is right. Thank you for your fast reply.
Is it possibly to create (template) sensors in a sensor file ? I assumed that have to be under template, because they are not really exists … ?

If its like this

sensor:
  - platform: integration
    name: firstSensor
    ...
  - name: secondSensor
    ...

in this case the first sensor will be a integrated one and the second not or ?

Best regards
Kai

Yes you can put the templates in a seperate file using !include.

Though the example you have shown is not valid as you have used a sensor platform again. These are not part of the template integration.

See here: https://community.home-assistant.io/t/adding-include-to-existing-entries-in-configuration-yaml/607131/2?u=tom_l

1 Like

Ok, im not 100 % that i have it, but for now thank you again for your help.
It works :slight_smile:
Best regards
Kai

There are many “sensors” in HA. They can be added by an integration if the product supports that. You can also build, or “template” your own sensors if that is required. Sensors are sometimes physical devices and other times they are derived or virtual devices where you create this sensors properties by "template"ing them.

1 Like