YET another take on an alarm system

my other automations dont have the ‘-’ in front of alias so did a quick test without it but. The component didnt error to the point of total failure like before but gave this in the log.

2017-11-16 11:48:38 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/automations/alarm_automation.yaml contains duplicate key “alias”. Check lines 1 and 16.
2017-11-16 11:48:38 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/automations/alarm_automation.yaml contains duplicate key “trigger”. Check lines 2 and 17.
2017-11-16 11:48:38 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/automations/alarm_automation.yaml contains duplicate key “action”. Check lines 6 and 21.
2017-11-16 11:48:38 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/automations/alarm_automation.yaml contains duplicate key “alias”. Check lines 16 and 41.
2017-11-16 11:48:38 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/automations/alarm_automation.yaml contains duplicate key “trigger”. Check lines 17 and 42.
2017-11-16 11:48:38 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/automations/alarm_automation.yaml contains duplicate key “action”. Check lines 21 and 46.
2017-11-16 11:48:38 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/automations/alarm_automation.yaml contains duplicate key “alias”. Check lines 41 and 58.
2017-11-16 11:48:38 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/automations/alarm_automation.yaml contains duplicate key “trigger”. Check lines 42 and 59.
2017-11-16 11:48:38 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/automations/alarm_automation.yaml contains duplicate key “action”. Check lines 46 and 63.
2017-11-16 11:48:38 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/automations/alarm_automation.yaml contains duplicate key “alias”. Check lines 58 and 72.
2017-11-16 11:48:38 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/automations/alarm_automation.yaml contains duplicate key “trigger”. Check lines 59 and 73.
2017-11-16 11:48:38 ERROR (SyncWorker_0) [homeassistant.util.yaml] YAML file /config/automations/alarm_automation.yaml contains duplicate key “action”. Check lines 63 and 77.

So i put the - in and I got the same breaking error as before where the automation component wont load at all. I’m thinking that without the ‘-’ is best but there must be some other indentation issue…

I really dont understand why I am having so much trouble with this automation :tired_face: the above error is what I get with this code below. This is killing me! I’ve spent so many hours trying to work out what is wrong and I dont understand why it fails yet is just like my working automations (except for additional spaces in front of everything… :thinking:) I see so much variation in the use of ‘-’ in the docs and other peoples examples that I dont know where I should and shouldnt use them.

#- id: alarm_armed_away
  alias: '[Alarm] Away Mode Armed'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.house
      to: 'armed_away'
  action:
    - service: notify.Pushbullet
      data:
        message: 'Alarm Away Mode Armed'

#    data:
#      message: 'The house alarm has been switched on in away mode. Goodbye'
#    service: notify.example_phone_tts

#- id: alarm_armed_home
  alias: '[Alarm] Home Mode Armed'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.house
      to: 'armed_home'
  action:
    - service: notify.Pushbullet
      data:
        message: 'Alarm Home Mode Armed'
#    data:
#      message: 'The house alarm has been switched on in home mode'
#    service: notify.example_phone_tts

#- id: alarm_arming_away
#  alias: '[Alarm] Away Mode Arming'
#  trigger:
#    - platform: state
#      entity_id: alarm_control_panel.house
#      to: 'pending'
#  action:
#  - data:
#      message: 'House alarm activating, ensure all doors and windows are closed'
#    service: notify.example_phone_tts

#- id: alarm_disarmed
  alias: '[Alarm] Disarmed'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.house
      to: 'disarmed'
  action:
    - service: notify.Pushbullet
      data:
        message: 'Alarm Disabled'
#      target: email/[email protected]
    - service: switch.turn_off
      entity_id: switch.alarm_siren1_switch
#  - data:
#      message: 'The house alarm has been Deactivated'
#    service: notify.example_phone_tts

#- id: alarm_triggered
  alias: '[Alarm] Triggered'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.house
      to: 'triggered'
  action:
    - service: switch.turn_on
      entity_id: switch.alarm_siren1_switch
    - service: notify.Pushbullet
      data:
        message: 'ALARM TRIGGERED!!! {{ states[states.alarm_control_panel.house.attributes.changed_by.split(".")[0]][ states.alarm_control_panel.house.attributes.changed_by.split(".")[1]].name }}'
#      target: email/[email protected]

#- id: alarm_warning
  alias: '[Alarm] Warning'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.house
      to: 'warning'
  action:
    - service: notify.Pushbullet
      data:
        message: 'ALARM Warning {{ states[states.alarm_control_panel.house.attributes.changed_by.split(".")[0]][ states.alarm_control_panel.house.attributes.changed_by.split(".")[1]].name }}'
#      target: email/[email protected]
#  - data:
#      message: 'Hello, the house alarm has been tripped. Please deactivate'
#    service: notify.example_phone_tts

So I have #'d out things above as they are from the original code but I either dont need it yet or it has been for testing.

It would be awesome if someone can point out the errors for me please

If you have an automations.yaml then the alias: needs a - because they are then a list, same for trigger platforms to have multiple triggers the platforms have to have - before them, same for actions to have multiple service calls they have to have - before them, same for lists of entity_id’s they have to have - before each, so an example…

The alias’ below are a list as it is called by automation old: !include automation.yaml from the configuration.yaml file

 - alias: "Send notification upon Greenhouse Door Closed"
   initial_state: 'on'
   trigger:
     - platform: state <---- this dash is not strictly needed but I always put them in as I like everything to line up :(
       entity_id: switch.rfl_greenhouse_door_closed
       to: 'off'
   action:
     - service: switch.turn_off <----- dashes needed as this is a list of service calls
         - entity_id: switch.rfl_greenhouse_door_open1 <------ dashes needed as this is a list of entity_ids
         - entity_id: switch.rfl_greenhouse_door_open2
         - entity_id: switch.rfl_greenhouse_door_open3
     - service: switch.turn_on
       entity_id: switch.rfl_greenhouse_door_closed
     - service: notify.mypushbullet
       data:
         message: 'Greenhouse Door Closed'      

 - alias: MQTT Sign Plant Data Update
   initial_state: 'off'
   trigger:
     - platform: numeric_state <----- dashes needed as this is a list of triggers
         - entity_id: sensor.miflora_bird_of_paradise_moisture
         - entity_id: sensor.miflora_trailing_plant_bathroom_moisture,
         - entity_id: sensor.miflora_volcano_fern_moisture,
         - entity_id: sensor.miflora_flowering_fern_moisture
       below: 15
     - platform: numeric_state
       entity_id: sensor.miflora_bird_of_paradise_battery, sensor.miflora_trailing_plant_bathroom_battery, sensor.miflora_volcano_fern_battery, sensor.miflora_flowering_fern_battery  <- no dash needed here as they are on the same line ;)
       below: 5
       above: 1
     - platform: numeric_state
       entity_id: sensor.miflora_bird_of_paradise_conductivity, sensor.miflora_trailing_plant_bathroom_conductivity, sensor.miflora_volcano_fern_conductivity, sensor.miflora_flowering_fern_conductivity
       below: 25
   action:
     - service: mqtt.publish
       data_template:
         topic: "cmnd/MQTTSign/PLANT"
         payload_template: '{{ trigger.from_state.attributes.friendly_name }} NEEDS Attention!'

Yaml is very picky about spaces and indentation and lists :frowning: I hope this helps :slight_smile:

If your automations are in the configuration.yaml then the then the alias doesn’t need a dash but you would need to precede each automation with …

automation x:

where x is a unique number.

The above code a have there is in its own alarm_automation.yaml which is in a folder (all of my automations have their own files in this folder) called by an include from the config. I’ll have another try using your tips, thanks

whenever I try to use the ‘-’ in front of the alias, I get the error as per just above where it talks about ‘expected a dictionary’ etc…

Hopefully @gazoscalvertos can help me. I think perhaps part of my issue is because I am using a folder with automation files in it rather than the single automation.yaml in the same folder as the config.yaml.

That could be it I think you can only have 1 automation per file in that case.

Look here for inspiration :wink:

I have followed that in the past. My issue here stems from trying to split up someone elses work to suit my setup.

Yep I know how that feels I’m trying to get my head around packages atm and not really getting it, none of them seem to work for me :frowning:

I split all the automations out of the alarm automation from above and now just get the single error:

2017-11-17 09:45:12 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: required key not provided @ data[‘action’]. Got None
required key not provided @ data[‘trigger’]. Got None. (See ?, line ?). Please check the docs at Automation - Home Assistant

From memory its an indentation issue when it states ‘required key not provided’. I couldnt see where the problem is though.

Yeah it’s a pain when it doesn’t give any line/file info to look at, post them here for us to look at :slight_smile:

alarm_armed_away.yaml

#- id: alarm_armed_away
  alias: '[Alarm] Away Mode Armed'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.house
      to: 'armed_away'
  action:
    - service: notify.Pushbullet
      data:
        message: 'Alarm Away Mode Armed'

#    data:
#      message: 'The house alarm has been switched on in away mode. Goodbye'
#    service: notify.example_phone_tts

alarm_armed_home.yaml

#- id: alarm_armed_home
  alias: '[Alarm] Home Mode Armed'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.house
      to: 'armed_home'
  action:
    - service: notify.Pushbullet
      data:
        message: 'Alarm Home Mode Armed'
#    data:
#      message: 'The house alarm has been switched on in home mode'
#    service: notify.example_phone_tts

alarm_arming_away.yaml (currently not in use)

#- id: alarm_arming_away
#  alias: '[Alarm] Away Mode Arming'
#  trigger:
#    - platform: state
#      entity_id: alarm_control_panel.house
#      to: 'pending'
#  action:
#  - data:
#      message: 'House alarm activating, ensure all doors and windows are closed'
#    service: notify.example_phone_tts

alarm_disarmed.yaml

#- id: alarm_disarmed
  alias: '[Alarm] Disarmed'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.house
      to: 'disarmed'
  action:
    - service: notify.Pushbullet
      data:
        message: 'Alarm Disabled'
#      target: email/[email protected]
    - service: switch.turn_off
      entity_id: switch.alarm_siren1_switch
#  - data:
#      message: 'The house alarm has been Deactivated'
#    service: notify.example_phone_tts

alarm_triggered.yaml

#- id: alarm_triggered
  alias: '[Alarm] Triggered'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.house
      to: 'triggered'
  action:
    - service: switch.turn_on
      entity_id: switch.alarm_siren1_switch
    - service: notify.Pushbullet
      data:
        message: 'ALARM TRIGGERED!!! {{ states[states.alarm_control_panel.house.attributes.changed_by.split(".")[0]][ states.alarm_control_panel.house.attributes.changed_by.split(".")[1]].name }}'
#      target: email/[email protected]

alarm_warning.yaml

#- id: alarm_warning
  alias: '[Alarm] Warning'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.house
      to: 'warning'
  action:
    - service: notify.Pushbullet
      data:
        message: 'ALARM Warning {{ states[states.alarm_control_panel.house.attributes.changed_by.split(".")[0]][ states.alarm_control_panel.house.attributes.changed_by.split(".")[1]].name }}'
#      target: email/[email protected]
#  - data:
#      message: 'Hello, the house alarm has been tripped. Please deactivate'
#    service: notify.example_phone_tts

the last two need data_template :slight_smile:

but how would this work for everyone else then??? I didnt change that code from what @gazoscalvertos has in the Git repo…

Dunno but anything with templating needs data_template: not data:

I just tried that but get the same error still :expressionless:

OK, so when I do my templating for pushbullet I do it like this…

   action:
     - service: notify.mypushbullet
       data_template:
         message: >
           '{{ trigger.topic.split('/')[-1] }} = topic {{ trigger.topic.split('/')[-3] }} = device {{ trigger.payload }} = payload'

Other than putting the message on a new line and adding the >, I can’t think of anything else the code looks good to me.

Only other way to debug it is to comment out all but first and rerun, uncommenting a new one till the error shows. Bit of a pain tho’ :stuck_out_tongue:

unfortunately the change to the message with the ‘>’ didnt work either. I reall;y dont feel like commenting out lines :tired_face: I think its time to admit defeat and give up on it. I just reverted back to the original automation.yaml that is supplied on the Git repo, changed the entity ID of the siren and commented out the notification stuff that doesnt apply to me and it works fine, which proves that the code is good until it gets split up…

A strange thing I have found with this alarm system is that the clock shows the correct time when viewing it on my local network but when i use my phone, it shows the time 1.5 hours ahead… using my phone is through the duckdns address so I tried with my laptop also via duckdns… my laptop has the correct time! I have no idea why the time shows incorrectly on my phone.

Any ideas?

Hi Dave,

My automations are actually split up the same way you did yours above. Have you tried testing them individually to see which one is causing the issue?

This is my alarm_warning.yaml:

  alias: '[Alarm] Warning'
  trigger:
  - platform: state
    entity_id: alarm_control_panel.house
    to: 'warning'
  action:
  - service: notify.pushbullet
    data:
      message: 'ALARM Warning {{ states[states.alarm_control_panel.house.attributes.changed_by.split(".")[0]][ states.alarm_control_panel.house.attributes.changed_by.split(".")[1]].name }}'

The only real difference I can see is the indentation after trigger and action.

A good way to test your automation is to add ‘group.all_automations’ to a view in your groups.yaml then add the following to your customize.yaml:

group.all_automations:
  hidden: false

after your restart HA you should see all of your automations listed. You can then click each one and manually tigger the automation, hopefully identifying which one is causing the issue

I have noticed something similar too. It has to be with the way polymer (the underlying web code) retrieves its time. I may look for an alternative method to do this.