First automation

I seem to be a bit lost here but i am wanting to send my self a notification when my phone battery is bellow a certain point this is what i have. Am i correct in saying that it must be put into the automations.yaml file? if so home assistant says there is a config error, what must i do to fix this?

automation:

  • alias: Check sensor value and show notification
    trigger:
    platform: numeric_state
    entity_id: sensor.stewartiphone_battery_level
    below: 20
    action:
    service: persistent_notification.create
    data:
    message: “Your battery is low,put it on charge”

It’s very difficult to read if the code is not in code blocks as we can’t check the formatting - see the blue box at the top of the posts.If the automation is in an automations.yaml file remove the automation: since is already exists in the configuration.yaml.

Here is your automation properly formatted :slight_smile:

automation:
  - alias: Check sensor value and show notification
  trigger:
    platform: numeric_state
    entity_id: sensor.stewartiphone_battery_level
    below: 20
  action:
    service: persistent_notification.create
    data:
      message: "Your battery is low,put it on charge" 

You don’t HAVE to put this in an automation.yaml file, but most people do.
If you do it that way, you have to remove the word automation from the automation.yaml file. It will already be referenced in your configuration.yaml file as

automation: !include automation.yaml

You can find out more about about using separate files here
Splitting up the configuration - Home Assistant

And yes, if you would please use formatting blocks it the future it will make it much easier for us to help you :

and placing topics in the right subforum would also be helpfull :wink:
this has nothing to do with HADashboard

Thanks for the reply’s and suggestions, i have an issue. When i put the code without the word automation in my automation file or even putting it in my config file(with the word automation), it stops home assistant from running, meaning that i cant view the network page of home assistant. why would this happen? if it is my code, what could be the issue be?

there are a view ways of putting in automations in your YAML. (and yeah YAML is sometimes hard to get used to)

in your configuration.yaml the line

automation: !include automations.yaml

from that moment on you can put automations in your automations.yaml file WITHOUT putting in

automation:

or directly in you configuration.yaml like:

automation:
  trigger:
    platform: 
...

if you put in to much or to little spaces the yaml is incorrect and that breaks your configuration.
and without a correctly configured yaml HA doesnt run. and without HA running you cant view the network page :wink:

It still does not work here is my config file.

homeassistant:
  # Name of the location where Home Assistant is running
  name: Crib
  # Location required to calculate the time the sun rises and sets
  latitude: xxxx
  longitude: xxxx
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 1551
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: xxxxx

# Show links to resources in log and frontend
introduction:

# Enables the frontend
frontend:

# Enables configuration UI
config:

http:
  # api_password: xxxx
  # Uncomment this if you are using SSL or running in Docker etc
  # base_url: example.duckdns.org:8123

# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
updater:
  # Optional, allows Home Assistant developers to focus on popular components.
  # include_used_components: true

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time.
history:

# View all events in a logbook
logbook:

# Track the sun
sun:
 
# Weather Prediction
sensor:
  - platform: cpuspeed
  - platform: yr
  
# Text to speech
tts:
  platform: google
 
#tracking
notify:
  - platform: ios 
  
#home tacking
zone 3:
  name: Home
  latitude: xxxxx
  longitude: xxxx
  radius: 50
  icon: mdi:account-multiple
  
#TVs
media_player:
  - platform: webostv
    host: xxxx
    mac: xxxxx
    name: TV Room
  - platform: webostv
    host: xxxx
    mac: xxxx
    name: Bed Room  
   
#message phone
automation:
  - alias: Check sensor value and show notification
  trigger:
    platform: numeric_state
    entity_id: sensor.stewartiphone_battery_level
    below: 20
  action:
    service: persistent_notification.create
    data:
      message: "Your battery is low,put it on charge"
   
group: !include groups.yaml
automation: !include automations.yaml

I hope the formatting is correct.:grimacing:

If you have both automations in config and it’s own file you have to number the one in the config,yaml…

automation 100:
  - alias: Check sensor value and show notification
  trigger:
    platform: numeric_state
    entity_id: sensor.stewartiphone_battery_level
    below: 20
  action:
    service: persistent_notification.create
    data:
      message: "Your battery is low,put it on charge"

I only have it within my config file. does that mean i still need to number it?

if you have the line:

automation: !include automations.yaml

in your config file you need to put all automations in the automations file.

now you have

automation:

2 times in your config

so you declare the automation platform twice and that causes that HA not starts.

so in this case i advice to delete the line

automation: !include automations.yaml

when checking the config file with (hass --script check_config) it gives the following.
,
Testing configuration at /home/homeassistant/.homeassistant
2017-06-22 09:34:52 ERROR (Thread-1) [homeassistant.util.yaml] while parsing a b lock collection
in “/home/homeassistant/.homeassistant/configuration.yaml”, line 85, column 3
expected , but found ‘?’
in “/home/homeassistant/.homeassistant/configuration.yaml”, line 86, column 3
2017-06-22 09:34:52 ERROR (MainThread) [homeassistant.bootstrap] Error loading / home/homeassistant/.homeassistant/configuration.yaml: while parsing a block coll ection
in “/home/homeassistant/.homeassistant/configuration.yaml”, line 85, column 3
expected , but found ‘?’
in “/home/homeassistant/.homeassistant/configuration.yaml”, line 86, column 3
,

So which lines are 85 and 86?

The lines 85 and 86 are:

Line 85: - alias: Check sensor value and show notification
line 86:   trigger:

take out the " - " before alias that is space-space

i took out the “-”, then tested it and it said this:

2017-06-22 19:37:46 ERROR (Thread-1) [homeassistant.util.yaml] while parsing a block mapping
  in "/home/homeassistant/.homeassistant/configuration.yaml", line 1, column 1
expected <block end>, but found '<block mapping start>'
  in "/home/homeassistant/.homeassistant/configuration.yaml", line 86, column 3
2017-06-22 19:37:46 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: while parsing a block mapping
  in "/home/homeassistant/.homeassistant/configuration.yaml", line 1, column 1
expected <block end>, but found '<block mapping start>'
  in "/home/homeassistant/.homeassistant/configuration.yaml", line 86, column 3

Line 1 being “homeassistant:”
Line 86 being"trigger:"

you’re going to have to post your entire configuration.yaml so we can help you work out the syntax problems in your file.

homeassistant:
  # Name of the location where Home Assistant is running
  name: Crib
  # Location required to calculate the time the sun rises and sets
  latitude: -26.0931700
  longitude: 28.0348800
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 1551
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Africa/Johannesburg

# Show links to resources in log and frontend
introduction:

# Enables the frontend
frontend:

# Enables configuration UI
config:

http:
  # api_password: Clayboydog123
  # Uncomment this if you are using SSL or running in Docker etc
  # base_url: example.duckdns.org:8123

# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
updater:
  # Optional, allows Home Assistant developers to focus on popular components.
  # include_used_components: true

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time.
history:

# View all events in a logbook
logbook:

# Track the sun
sun:
 
# Weather Prediction
sensor:
  - platform: cpuspeed
  - platform: yr
  
# Text to speech
tts:
  platform: google
 
#tracking
notify:
  - platform: ios 
  
#home tacking
zone 3:
  name: Home
  latitude: -26.0931700
  longitude: 28.0348800
  radius: 50
  icon: mdi:account-multiple
  
#TVs
media_player:
  - platform: webostv
    host: 10.0.0.15
    mac: C4:36:6C:A1:2D:54
    name: TV Room
  - platform: webostv
    host: 10.0.0.11
    mac: 78:45:61:FB:5F:6E
    name: Bed Room
#message
automation:
    alias: Check sensor value and show notification
  trigger:
    platform: numeric_state
    entity_id: sensor.stewartiphone_battery_level
    below: 20
  action:
    service: persistent_notification.create
    data:
      message: "Your battery is low,put it on charge"
group: !include groups.yaml

The a in “alias” has to line up with the t in “trigger” which is why I said remove space-space, yaml is very stringent with spaces and formatting :stuck_out_tongue:

2 Likes

That has fixed the issue and is now all working. Thanks everyone for the help!

1 Like

Good job :slight_smile:

1 Like