Cannot define any - platform statement behind sensor:

Hi guys,
I am fairly new to HA and after countless futile attempts and days of google research I ask you now.
I try to define the systemmonitor according to the official documentation like this:


mqtt:
 device_tracker:
   - name: "NodeMCU SZ"
     state_topic: "ac0bfbd67288/state"
     unique_id: nodemcuszstate

 
 sensor:
   - platform: systemmonitor
     resources:
       - type: disk_use_percent
         arg: /

   - name: Raspi4 Nodes
     state_topic: "raspi4mqtt/sensor"
     unique_id: raspirpi

 

Unfortunalety that does not work.
The HA configuration checker says:

Invalid config for [mqtt]: [platform] is an invalid option for [mqtt]. Check: mqtt->mqtt->sensor->0->platform. (See /config/configuration.yaml, line 56).

Is the documentation wrong, or am I making a mistake?

Any hint appreciated.

Sigi

What file is this in?

And are you sure the indentation shown above reflects what is in your file exactly?

  1. It’s in configuration.yaml
  2. Yes - I did a copy/paste from VSCODE into the post.

btw. Any “- platform” ( below the sensor: ) leads into an error. Even the command platform.

My environment:
Home Assistant 2023.2.5
Supervisor 2023.01.1
Operating System 9.5
Frontend 20230202.0 - latest

running on hassio on an Odroid XU4

As the error message states, platform is not a valid configuration variable for the mqtt platform… I suspect you are trying to do something like the following:

mqtt:
    device_tracker:
      - name: "NodeMCU SZ"
        state_topic: "ac0bfbd67288/state"
        unique_id: nodemcuszstate
 
    sensor:
      - name: Raspi4 Nodes
        state_topic: "raspi4mqtt/sensor"
        unique_id: raspirpi

sensor:
    - platform: systemmonitor
      resources:
        - type: disk_use_percent
          arg: /

Sensors that are not based on the MQTT platform cannot be added to the same list as those that are. You need a top level sensor configuration key.

@ Didgeridrew:
as you can see in my first post, I definitely have only one sensor key as described in the HA documentation.
If I put the sensor statement on the same level as mqtt I get
Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None. (See /config/configuration.yaml, line 68).

Just tried to define the systemmonitor on the mqtt level


systemmonitor:
   - platform: systemmonitor
     resources:
       - type: disk_use_percent
         arg: /
mqtt:
.
.
.

but that don’t work either:
Setup failed for systemmonitor: No setup or config entry setup function defined.

In your first post you have 0 top-level sensor keys. You have 1 sensor child key with mqtt as the parent. Under that you have a configuration stanza for 1 MQTT sensor, and 1 non-MQTT sensor.

As shown in the example I posted above. Your MQTT-based sensors must be children of the top-level mqtt key… non-MQTT sensors must be children of a top-level sensor key.*

That is not what I showed above…

YAML for non-programmers

*Note: Other top-level keys can also have sensor children, but sensor is the most common parent key for sensor integrations.

Finally!
I’m not sure I’ve got the configuration guidelines right now, but as you suggested above, I’ve defined an additional top-level sensor statement after my other sensors and - it’s working now.
You are my hero of the day.
Thank you very much!

The Solution tag is assigned to the first, or best, post that resolves the problems originally presented. Refer to guideline 21 in the FAQ.