Error of duplicating in automation file

Hi,

I’m trying to start a home assistant and doing step by step I’m stuck in something strange.

For example I want that if sensor.random above 10 to give a message, else dismiss it.

My code from automations.yaml is:

`

alias: NumberOn
trigger:
  platform: numeric_state
  entity_id: sensor.aleator
  above: 10
action:
  service: persistent_notification.create
  data:
    message: "Random number peste 10"
    title: "Numarul este {{ sensor.aleator.state }}"
    notification_id: "201711131"
    
alias: NumberOff
trigger:
  platform: numeric_state
  entity_id: sensor.aleator
  below: 10
action:
# When next line activated - gives error
  service: persistent_notification.dismiss
  date:
    notification_id: "201711131"

The error is:

2017-11-13 09:41:20 ERROR (Thread-2) [homeassistant.util.yaml] YAML file /opt/homeassistant/automations.yaml contains duplicate key “alias”. Check lines 0 and 12.
2017-11-13 09:41:20 ERROR (Thread-2) [homeassistant.util.yaml] YAML file /opt/homeassistant/automations.yaml contains duplicate key “trigger”. Check lines 1 and 13.
2017-11-13 09:41:20 ERROR (Thread-2) [homeassistant.util.yaml] YAML file /opt/homeassistant/automations.yaml contains duplicate key “action”. Check lines 5 and 17.

P.S. I’ve read multiple webpages and docs, but I from their example it should work. I run the last version of hass but with yarl 0.13

You have date instead of data in second automation.

Ups… sorry, indeed now accepted.
But now the only automation script that runs is the last is NumberJos

I don’t understand why. Here is the new code:

alias: NumberSus
trigger:
  platform: numeric_state
  entity_id: sensor.random_sensor
  above: 10
action:
  service: persistent_notification.create
  data:
    message: "Random number is: {{ states('sensor.random_sensor') }}"
    title: "Number above 10"
#    notification_id: "201711131"

alias: NumberJos
trigger:
  platform: numeric_state
  entity_id: sensor.random_sensor
  below: 10
action:
  service: persistent_notification.create
  data:
#    notification_id: "201711131"
    message: "Random number is: {{ states('sensor.random_sensor') }}"
    title: "Number below 10"

with multiple automations in a file you must use a “-” to denote separate automations. Put a “-” in front of each alias:. If it still complains, you may then also need to indent everything with 2 spaces.

Example:

- alias: NumberJos
  trigger:
    platform: numeric_state
    entity_id: sensor.random_sensor
    below: 10
  action:
    service: persistent_notification.create
    data:
  #    notification_id: "201711131"
      message: "Random number is: {{ states('sensor.random_sensor') }}"
      title: "Number below 10"

Now I get it… even if you are using an file you should have an -id: before

I added “-id: numbersus and -id: numberjos” before each alias and now is working corectly.

I’ll ttry with “- alias” but now with “- id” is working.
Thanks,

That works too. alias: gives your automations a friendly name, id: gives them an identity so they show up in the frontend editor.

Regardless which one you put the - in front of, it will fix your error.

Yes, indeed it works perfectly now. Thanks.