Help Needed: "Map keys must be unique" Error in YAML Configuration

Hi openHAB Community,

I’m encountering an issue with my YAML configuration, and I’m stuck. The error I’m seeing is:

Map keys must be unique at line 68, column 1:
component: div

Configuration Details

Here’s the relevant portion of my YAML file:

timestamp: Jan 1, 2025, 10:44:14 AM
component: oh-context
config:
  constants:
    widgetID: Number.parseInt(Math.random()*8912).toString(16).padStart(4, '0')
component: div
config:
  stylesheet: |
    .card:not(.card-opened) .card-content {
      width: 100% !important;
    }
slots:
  default:
    - component: f7-card
      config:
        expandable: true

The Issue

The error seems to point to the component key being duplicated or misused in the YAML file. Since component is a required property in multiple parts of the configuration, I’m not sure how to handle this.

What I’ve Tried

  1. Checked the YAML file for any accidental duplicate component keys.
  2. Validated the YAML syntax using an online YAML linter—no syntax issues found apart from the error mentioned.
  3. Reviewed the openHAB documentation, but couldn’t find specifics about handling multiple component entries in this way.
  4. Tried this
mainComponent:
  component: oh-context
  config:
    constants:
      widgetID: Number.parseInt(Math.random()*8912).toString(16).padStart(4, '0')
subComponent:
  component: div
  config:
    stylesheet: |
      .card:not(.card-opened) .card-content {
        width: 100% !important;
      }
slots:
  default:
    - component: f7-card
      config:
        expandable: true

But without success

Questions

  1. Is it valid to have multiple component keys in openHAB YAML configurations? If not, how should I structure this instead?
  2. Could the use of slots or nested component definitions be causing this problem?
  3. Are there better practices for organizing a complex YAML configuration like this to avoid such errors?

Any advice or insights would be greatly appreciated. Let me know if more details or a larger portion of the YAML file would help.

Thank you so much!

Shouldn‘t it be

- component

like on other places?

I also tested this

but this is the error

A block sequence may not be used as an implicit map key at line 186, column 1:

timestamp: Jan 1, 2025, 10:58:54 AM
- component: oh-context
^

A widget can only have one root component. That is, one component defined by

component: some-component

All other components in the widget must be children of that single root component by using slots.

The first error you are seeing is a yaml error because you cannot have two yaml keys with the same name at the same level (in this case component, of course. When you look at other widgets, the lists of multiple components in some of the slots all start with - because that defines a yaml array instead of a single key, but you cannot do that with the root element.