Indentation reasoning seems inconsistent

I am confused as to the rules for indentation
For the following the indenation of the options must be the same level as the tag

  - platform: gpio
    name:  "Water Solenoid ${solenoidname}"
    pin: GPIO${solenoidpin}
    id: WaterSolenoid${solenoidname}

Adding the indent gives this error

INFO ESPHome 2025.12.5
INFO Reading configuration /config/esphome/esphome-web-2e8530.yaml…
ERROR Error while reading config: Invalid YAML syntax:

mapping values are not allowed here
in “/config/esphome/.solenoidboardwithparams.yaml”, line 37, column 13
Yet for the following the indentation of the options must be one level up from the tag

                                - logger.log: 
                                    tag: ${solenoidname}
                                    format: "ID is %i not ${sectionid}"
                                    args: ['id(currentsolenoid)']
                                    level: debug

Removing the indent gives this error

ERROR Error while reading config: Invalid YAML syntax:

while parsing a block collection
in “/config/esphome/.solenoidboardwithparams.yaml”, line 69, column 33
expected , but found ‘?’
in “/config/esphome/.solenoidboardwithparams.yaml”, line 70, column 33

I am fairly new - and I’m slowly getting used to the system but when I move code around and it requires re-indentation this above threw me and I dont see an obvious difference between the two cases - the first one seems to me that it should be indented

This is a component definition. Component definitions generally follow this indentation rule.

This is an action. Actions generally follow this indentation rule.

So fairly easy to remember - your either defining a component, or executing an action.

Also the docs for each action and component give you examples with correct indentation.

The docs have a guide to YAML that has some hints on this.

3 Likes