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:
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 15 (7 by maintainers)
@MaxWinterstein, I’ve run into this issue recently. The
solutionworkaround 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.)