Can't change friendly name of sonoff switch

Trying to modify the programmatically-generated friendly name of a new auto-discovered sonoff switch, and HA won’t do it.

Some entities don’t have the gear icon in the upper right of their properties panel when you open them, and therefore you can’t change their properties from there. When you open the entity from the Customization menu, the “Name” (=friendly name) is listed in the first section that’s greyed out and says that programmatically-generated attributes can’t be edited.

If I attempt to override the entity’s friendly name in the Customization section of the yaml files, I get an invalid configuration file, mapping error at the friendly_name line.

Any ideas? Is it just not possible to override the automatically-assigned friendly name for auto-discovered devices?

Please post code from customize.yaml. It’s in this file that you can customize name using friendly_name

First, since I had nothing in customize.yaml as yet, I tried commenting out the line “customize: !include !customize.yaml” in my configuration.yaml file, and included these lines:

customize:
  switch.sonoff_100021f433
  friendly_name: Garage

That produced the mapping error at the “friendly_name” line. I then tried transferring it to the customize.yaml file and re-including the file reference in customize.yaml:

  switch.sonoff_100021f433
  friendly_name: Garage

That produced the same mapping error at line 2 of the customize.yaml file.

Try

  switch.sonoff_100021f433:
    friendly_name: Garage

Nope, extra indent produces the same error on the same line: “mapping values are not allowed here”

Adding an extra : at the end of the entity name makes the customize section invalid.

You should have:

customize:
  switch.sonoff_100021f433:
    friendly_name: Garage
1 Like

Ok, I think I’ve got it solved now. It was a combination of:

  1. Bad examples giving me the wrong syntax for the individual entity section
  2. customize: section has to be placed at the beginning of configuration.yaml and indented 2 spaces under the heading homeassistant:

As is so often the case with Home Assistant, the information is 90% there, and it’s the last 10% that causes trouble, things like not showing the context that goes around the example.

Nice!

I agree it’s quite difficult when you start. You may validate your yaml with website like https://jsonformatter.org/yaml-validator
If you use hassio, the configurator add-on or the vscode add-on have an embedded validator, both yaml and HA specific syntax.

Thanks for your help, and for the additional suggestions. Just to confirm in case some other new user runs across this thread, your syntax is the correct one, and it does match the official HA page on Customization.

I was using the built-in configuration validator to check my configuration changes as I made them, so thank goodness I didn’t have to do a full restart and puzzle over the results each time. And it did correctly identify the location of the error each time. The problem was more that the error message is not sufficiently helpful. “mapping error” may tell an experienced yaml user that there’s definitely some sort of syntax error in the use of spacing or colons, but it has little meaning to someone who hasn’t encountered it before, especially when you’re just following the exact syntax given by an example. The varying use of indenting, dashes, and colons in yaml is all a bit mysterious. But at least I’ll know to check the syntax against different examples next time I see a mapping error!

The general yaml checkers can help verify that there’s a syntax error, but they can’t tell that a section is in the wrong place in the configuration.yaml file because they don’t have that much specific knowledge.

Now this is getting a bit frustrating. I moved the lines from configuration.yaml to customize.yaml, and the mapping error is back, no matter what spacing I try. I’ve looked at the HA documentation and every example I could find of the format for include files, and I can’t see what’s wrong. Help!

Original in configuration.yaml:

homeassistant:
...
  customize:
    switch.sonoff_100021f433:
      friendly_name: Garage

After move:

homeassistant:
...
  customize: !include customize.yaml

and in customize.yaml:

    switch.sonoff_100021f433:
      friendly_name: Garage

I’ve tried with 4/6 spaces in front of these lines, exactly as they appear in configuration.yaml, and with the variations: 0/2 spaces and 2/4 spaces. Every time it gives me a mapping error at line 2 position 16.

All the examples of customize.yaml I’ve looked at have used different leading spacing seemingly at random, so I can’t tell if it’s significant or not. What am I missing?

Update: apparently not missing anything. After trying all the variations twice, it suddenly started working on the 3rd try with 0/2 spaces for no apparent reason. For the benefit of any new user who isn’t sure, when you use an include file to break out part of the configuration.yaml file, you lose one level of indent (2 spaces) because it is already considered to be under the section header you broke out.