Duplicate Key Problem in Sensors.yaml

Hi Guys, I am a Noob at HA and have been experimenting with keeping track of how long my geysers have been on in any 24 hour period and then starting them up again at 4am if they haven’t been heating for at least 3 hours in the past day.

I added Sensors.yaml and addled the !include command in the configuration file.

I can add 1 geyser but as soon as i add the others i get the duplicate key error and only the last one on the list is recognised.

Any advice would be appreciated.

Code from Sensors.yaml below:

platform: history_stats
name: Geyser Domestic ON today
entity_id: switch.geyser_domestic_switch_1
state: “on”
type: time
end: “{{ (now() + timedelta(hours=17)).replace(hour=7, minute=0, second=0, microsecond=0) }}”
duration:
hours: 24

platform: history_stats
name: Geyser Feeder ON today
entity_id: switch.geyser_feeder_switch_1
state: “on”
type: time
end: “{{ (now() + timedelta(hours=17)).replace(hour=7, minute=0, second=0, microsecond=0) }}”
duration:
hours: 24

platform: history_stats
name: Geyser Primary ON today
entity_id: switch.geyser_primary_switch_1
state: “on”
type: time
end: “{{ (now() + timedelta(hours=17)).replace(hour=7, minute=0, second=0, microsecond=0) }}”
duration:
hours: 24

1 Like

impossible to say with your wrangled code posting, but each sensor should have a - in front of it.

1 Like

Apoligies for the rookie error. I hope this is now pasted with formatting. I suspect i have messed up indentation in the Sensors.yaml file

name: Geyser Domestic ON today
entity_id: switch.geyser_domestic_switch_1
state: "on"
type: time
end: "{{ (now() + timedelta(hours=17)).replace(hour=7, minute=0, second=0, microsecond=0) }}"
duration:
  hours: 24

platform: history_stats
name: Geyser Feeder ON today
entity_id: switch.geyser_feeder_switch_1
state: "on"
type: time
end: "{{ (now() + timedelta(hours=17)).replace(hour=7, minute=0, second=0, microsecond=0) }}"
duration:
  hours: 24


platform: history_stats
name: Geyser Primary ON today
entity_id: switch.geyser_primary_switch_1
state: "on"
type: time
end: "{{ (now() + timedelta(hours=17)).replace(hour=7, minute=0, second=0, microsecond=0) }}"
duration:
  hours: 24```

You are correct. Try using https://www.yamllint.com/ to check your code.

2 Likes

Thank you Guys - The indent and “-” was what it needed.

  name: Geyser Domestic ON today
  entity_id: switch.geyser_domestic_switch_1
  state: "on"
  type: time
  end: "{{ (now() + timedelta(hours=17)).replace(hour=7, minute=0, second=0, microsecond=0) }}"
  duration:
    hours: 24

- platform: history_stats
  name: Geyser Feeder ON today
  entity_id: switch.geyser_feeder_switch_1
  state: "on"
  type: time
  end: "{{ (now() + timedelta(hours=17)).replace(hour=7, minute=0, second=0, microsecond=0) }}"
  duration:
    hours: 24

- platform: history_stats
  name: Geyser Primary ON today
  entity_id: switch.geyser_primary_switch_1
  state: "on"
  type: time
  end: "{{ (now() + timedelta(hours=17)).replace(hour=7, minute=0, second=0, microsecond=0) }}"
  duration:
    hours: 24```