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.
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
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
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
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"
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
,
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:"
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