I am new to HA and trying to get the hang of yaml syntax. Can anyone tell me what is wrong with this sensors.yaml file? If I comment the !include line out (with a pound sign at the beginning of the line) in configuration.yaml, I can reload all yaml configurations without an error, but if I uncomment it, I get the error “Failed to call service homeassistant/reload_all. argument of type ‘NoneType’ is not iterable” which suggests that I have an indentation problem. I copied the syntax carefully from a YouTube video and cannot see an issue. Help!
Does the naming of the file, sensorS (multiple) correspond with the reference in your configuration file?
It seems you have put those spaces/blanks manuallly; what if you put everything on 1 line? The system will automatically ‘do a word wrap’ (don’t know if this is the right terminology)
If you post your YAML as code instead of a picture it helps to help you.
Like I said, you don’t need to break those lines, the system will do that for you.
Definitely, the spaces that you have put are wrong AFAIK.
When you say “put everything on 1 line” you mean literally everything except the comment line on single very long line? When Ido that I get this error:
I get this: “Failed to call service homeassistant/reload_all. Cannot quick reload all YAML configurations because the configuration is not valid: Error loading /config/configuration.yaml: mapping values are not allowed here in “/config/sensors.yaml”, line 2, column 29”
Here is my sensors.yaml file:
Count the number of lights on
platform: template sensors: number_lights_on: friendly_name: Number Lights On value_template: >- {{ states.light | selectattr(‘state’, ‘eq’, ‘on’) | list | count }} icon_template: mdi:lightbulb-group
Tried to put just the template code (I think) on one line, and now this error:
“Failed to call service homeassistant/reload_all. Cannot quick reload all YAML configurations because the configuration is not valid: Error loading /config/configuration.yaml: while scanning a block scalar in “/config/sensors.yaml”, line 6, column 21 expected a comment or a line break, but found ‘{’ in “/config/sensors.yaml”, line 6, column 24”
My sensors.yaml is here:
##### Count the number of lights on #####
- platform: template
sensors:
number_lights_on:
friendly_name: Number Lights On
value_template: >- {{ states.light | selectattr('state', 'eq', 'on') | list | count }}
icon_template: mdi:lightbulb-group
##### Count the number of lights on #####
- platform: template
sensors:
number_lights_on:
friendly_name: Number Lights On
value_template: "{{ states.light | selectattr('state', 'eq', 'on') | list | count }}"
icon_template: mdi:lightbulb-group
or
##### Count the number of lights on #####
- platform: template
sensors:
number_lights_on:
friendly_name: Number Lights On
value_template: |
"{{ states.light | selectattr('state', 'eq', 'on') | list | count }}"
icon_template: mdi:lightbulb-group
Check your configuration in the developer tools before restarting.
I believe that’s incorrect - the OP is using legacy format for a template sensor, with the deprecated platform: key, so sensors: is technically OK here.
There should however be indentation of the whole block after the line number_lights_on:.
Or better yet, use the modern format, and include from configuration.yaml using the ```template:`` key. Refer to the documentation linked above.
Both give me errors. The second one gives me this when I click “ALL YAML CONFIGURATION” in " YAML configuration reloading:"
“Failed to call service homeassistant/reload_all. Cannot quick reload all YAML configurations because the configuration is not valid: Error loading /config/configuration.yaml: mapping values are not allowed here in “/config/sensors.yaml”, line 6, column 23”
Would that line and column be the double quotes? The example on YouTube did not have double quotes. It looks like you used them in place of the characters “>-”
##### Count the number of lights on #####
- platform: template
sensors:
number_lights_on:
friendly_name: Number Lights On
value_template: |
"{{ states.light | selectattr('state', 'eq', 'on') | list | count }}"
icon_template: mdi:lightbulb-group
#### Count the number of lights on #####
- platform: template
sensors:
number_lights_on:
friendly_name: Number Lights On
value_template: |
{{ states.light | selectattr('state', 'eq', 'on') | list | count }}
icon_template: mdi:lightbulb-group
Indented ‘value_template’ properly
Removed quotes from the “{{ template }}”
That fixed it - I really need a resource on understanding indentation, the documentation devotes literally two lines to it. Nick said there is something that will correct it for me automatically, but ‘save’ in File Editor doesn’t do that for me. What else am I missing?
Sorry if I had mislead you…
I’m not that good with templates and it’s always trial and error with lots of reading/searching.
Just wanted to help you and I was convinced that I have experienced it when putting a template on 1 line, the system would add line breaks…
YAML is a file format that Home Assistant has decided to use to hold its configuration. They didn’t make it up so they don’t spend much time documenting it.
I recommend learning the YAML basics from other resources. And then the instructions from the Home Assistant will make more sense.
I could explain some highlights (or try to recommend some google results), but it helps to know your background so I target it right. Do you know a programming language? JSON file format?