core: Yaml anchors/aliases trigger false positive duplicate key warning

Home Assistant release with the issue:

0.81.6

Last working Home Assistant release (if known):

N/A

Operating environment (Hass.io/Docker/Windows/etc.):

Raspbian (Debian 9)

Component/platform:

homeassistant.util.yaml

Description of problem:

When using yaml anchors to re-use existing yaml blocks the following warnings are seen in the log. These are false positives in this scenario since the intention is to include a yaml block/anchor and override some of the values.

2018-11-09 09:35:23 ERROR (Thread-2) [homeassistant.util.yaml] YAML file /home/hass/.homeassistant/configuration.yaml contains duplicate key "name". Check lines 376 and 421.
2018-11-09 09:35:23 ERROR (Thread-2) [homeassistant.util.yaml] YAML file /home/hass/.homeassistant/configuration.yaml contains duplicate key "current_temperature_topic". Check lines 399 and 422.
2018-11-09 09:35:23 ERROR (Thread-2) [homeassistant.util.yaml] YAML file /home/hass/.homeassistant/configuration.yaml contains duplicate key "temperature_command_topic". Check lines 401 and 423.
2018-11-09 09:35:23 ERROR (Thread-2) [homeassistant.util.yaml] YAML file /home/hass/.homeassistant/configuration.yaml contains duplicate key "swing_mode_command_topic". Check lines 404 and 424.
2018-11-09 09:35:23 ERROR (Thread-2) [homeassistant.util.yaml] YAML file /home/hass/.homeassistant/configuration.yaml contains duplicate key "swing_mode_state_topic". Check lines 405 and 425.
2018-11-09 09:35:23 ERROR (Thread-2) [homeassistant.util.yaml] YAML file /home/hass/.homeassistant/configuration.yaml contains duplicate key "fan_mode_command_topic". Check lines 407 and 426.
2018-11-09 09:35:23 ERROR (Thread-2) [homeassistant.util.yaml] YAML file /home/hass/.homeassistant/configuration.yaml contains duplicate key "fan_mode_state_topic". Check lines 408 and 427.
2018-11-09 09:35:23 ERROR (Thread-2) [homeassistant.util.yaml] YAML file /home/hass/.homeassistant/configuration.yaml contains duplicate key "mode_command_topic". Check lines 410 and 428.
2018-11-09 09:35:23 ERROR (Thread-2) [homeassistant.util.yaml] YAML file /home/hass/.homeassistant/configuration.yaml contains duplicate key "mode_state_topic". Check lines 411 and 429.
2018-11-09 09:35:23 ERROR (Thread-2) [homeassistant.util.yaml] YAML file /home/hass/.homeassistant/configuration.yaml contains duplicate key "name". Check lines 376 and 431.

And etc…

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

climate:
  - &mitsu_platform
    platform: mqtt
    name: "Office A/C"
    modes:
     - "off"
     - heat
     - dry
     - cool
     - fan_only
     - auto
    fan_modes:
     - AUTO
     - QUIET
     - "1"
     - "2"
     - "3"
     - "4"
    swing_modes:
     - AUTO
     - "1"
     - "2"
     - "3"
     - "4"
     - "5"
     - SWING
    current_temperature_topic: "heatpump/office/status"
    current_temperature_template: "{{ value_json.roomTemperature }}"
    temperature_command_topic: "heatpump/office/_set/temperature"
    temperature_state_topic: "heatpump/office"
    temperature_state_template: "{{ value_json.temperature }}"
    swing_mode_command_topic: "heatpump/office/_set/vane"
    swing_mode_state_topic: "heatpump/office"
    swing_mode_state_template: "{{ value_json.vane }}"
    fan_mode_command_topic: "heatpump/office/_set/fan"
    fan_mode_state_topic: "heatpump/office"
    fan_mode_state_template: "{{ value_json.fan }}"
    mode_command_topic: "heatpump/office/_set/mode"
    mode_state_topic: "heatpump/office"
    mode_state_template: >
      {% if value_json.power == "OFF" %}
        off
      {% elif value_json.mode == "FAN" %}
        fan_only
      {% else %}
        {{ value_json.mode|lower }}
      {% endif %}
  - <<: *mitsu_platform
    name: "Master A/C"
    current_temperature_topic: "heatpump/master/status"
    temperature_command_topic: "heatpump/master/_set/temperature"
    swing_mode_command_topic: "heatpump/master/_set/vane"
    swing_mode_state_topic: "heatpump/master"
    fan_mode_command_topic: "heatpump/master/_set/fan"
    fan_mode_state_topic: "heatpump/master"
    mode_command_topic: "heatpump/master/_set/mode"
    mode_state_topic: "heatpump/master"
  - <<: *mitsu_platform
    name: "Nursery A/C"
    current_temperature_topic: "heatpump/nursery/status"
    temperature_command_topic: "heatpump/nursery/_set/temperature"
    swing_mode_command_topic: "heatpump/nursery/_set/vane"
    swing_mode_state_topic: "heatpump/nursery"
    fan_mode_command_topic: "heatpump/nursery/_set/fan"
    fan_mode_state_topic: "heatpump/nursery"
    mode_command_topic: "heatpump/nursery/_set/mode"
    mode_state_topic: "heatpump/nursery"

Additional information:

Identical to auto-closed issue #8415, related to #1714

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 15 (7 by maintainers)

Most upvoted comments

@MaxWinterstein, I’ve run into this issue recently. The solution workaround is to avoid key overrides, which can be done most of the time with the trick seen in a previous comment by @mf-social.

In this particular case, instead of anchoring the complete config of a cover and then overriding some keys, anchor only the common keys. The trick is, that the anchored partial dictionary itself is merged in with a <<. (You can verify the result with e.g. any online yaml to json converter.)

cover:
  - 
    name: Superrollo 1-3
    unique_id: a324823e-786a-407d-a7a8-60729cf89650
    payload_open: Color 000000FF; Color 00000000;
    payload_close: Color 0000FF00; Color 00000000;
    payload_stop: Color 0000FFFF; Color 00000000;
    <<: &superrollo_template
      platform: mqtt
      command_topic: cmnd/tasmota_55D0FD/Backlog
      availability_topic: tele/tasmota_55D0FD/LWT
      payload_available: Online
      payload_not_available: Offline

  - 
    name: Superrollo 1
    unique_id: 8645186d-c217-4d01-8772-886e272ff525
    payload_open: Color 00FF00FF; Color 00000000;
    payload_close: Color 00FFFF00; Color 00000000;
    payload_stop: Color 00FFFFFF; Color 00000000;
    <<: *superrollo_template

  - 
    name: Superrollo 2
    unique_id: 260319c8-619f-4710-b971-f93510039f12
    payload_open: Color FF0000FF; Color 00000000;
    payload_close: Color FF00FF00; Color 00000000;
    payload_stop: Color FF00FFFF; Color 00000000;
    <<: *superrollo_template

  - 
    name: Superrollo 3
    unique_id: 70562e1a-bae6-43db-8971-ae0e65727377
    payload_open: Color FFFF00FF; Color 00000000;
    payload_close: Color FFFFFF00; Color 00000000;
    payload_stop: Color FFFFFFFF; Color 00000000;
    <<: *superrollo_template