Hi,
is there a recommendation on how to name automations in particular, but also entities, so that I can keep track of them?
I now have about 20 automations and am slowly losing the overview.
Hi,
is there a recommendation on how to name automations in particular, but also entities, so that I can keep track of them?
I now have about 20 automations and am slowly losing the overview.
I use packages and have found that <Package Name>: <Automation Name>
works well. I havenât found the need for any greater convention-ing than that.
Thanks for the link.
Unfortunately, I donât get the use case of packages.
Could you elaborate this function with your own words, please?
This would be great.
Thanks in advance.
Packages are a way to combine multiple, related automations/helpers/scripts/etc. in a single YAML file. For example, I have a basement
package that contains everything related to my basement. Thus, the automations contained in that packages are named Basement: <Automation Name>
.
Some clarification and a real example would be nice. The documentation is of little use if one is not already familiar with the lexicon of Home Assistant.
My automations are developed in the UI (settings, automations)- how would splitting them into packages work?
Iâm not clear on where the clarification is needed. The official docs (a) explain what packages are, (b) how to create them (i.e., where to place the YAML files), and (c) give different examples. Can you tell me where youâre getting stuck?
AFAIK automations in packages are not editable in the UI. It is why my automations are the only thing I have not moved into packages yet.
Packages are great though. Recommend them over having everything in configuration.yaml.
Naming both entities and automations of the form <location>_<entity/action>
has been good enough for me though I donât use the UI editor. I have many hundreds of both.
Often, but not always the documentation provides cryptic examples that requires advanced knowledge of Home Assistant to follow. Much of the documentation is written with the new user as the audience. But not packages. I have been using Home Assistant for three years and this is not at all clear to me:
Further- how are packages any different from include files? This is in my configuration.yaml:
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
zone: !include zones.yaml
sensor: !include sensors.yaml
camera: !include cameras.yaml
mqtt: !include mqtt.yaml
And last, how does any of this answer Philâs original question?
You can incorporate more than one domain in a package. e.g. you may have a package that has sensors, automations (and yaml integrations?) all related to the one function or area in the one package.
Add this to your configuration.yaml
:
homeassistant:
packages: !include_dir_named conf/packages/
âŚand voila, youâre using packages. Now, every YAML file under that directory can contain a mixture of elements (automations, scripts, etc.), which effectively bundles related functionality together.
As to how this answers the original question⌠Iâm unclear on how to make that more obvious. He was asking about naming conventions for things like automations; I explained that I like to prefix automation names with the package they live in. There is no hard requirement for you or he to follow suit; itâs purely a preference.
I chose to split my automations & scripts into separate yaml via an include. Same for all my other domains where manual config is required.
For naming Iâm generally starting the automation or script with a word that denotes the room or service Iâm trying to work on. For example, âcctv: power on indoor camerasâ or âbathroom1: lights controlâ.
I find I use the search feature a lot to find what I want.
Packages are exactly like a miniature version your configuration.yaml.
almost anything you can put as a top level key (sensor:, binary_sensor:, template:, homeassistant:, automation:, script:, etc) in there can go into a package.
here is a (shortened) version of one of my packages:
smoke_water_alarm_package.yaml:
switch:
- platform: template
switches:
water_valve_template:
friendly_name: "Water Main Valve"
value_template: "{{ is_state('switch.water_shut_off_valve_switch', 'on') }}"
turn_on:
service: switch.turn_on
data:
entity_id: switch.water_shut_off_valve_switch
turn_off:
service: switch.turn_off
data:
entity_id: switch.water_shut_off_valve_switch
icon_template: >
{% if is_state('switch.water_shut_off_valve_switch', 'on') %}
mdi:water-pump
{% else %}
mdi:water-pump-off
{% endif %}
sensor:
platform: template
sensors:
basement_smoke_alarm_status:
friendly_name: 'Basement Smoke Alarm Status'
value_template: >-
{% if is_state("sensor.smoke_co_alarm_basement_alarm_level", "255") and is_state("sensor.smoke_co_alarm_basement_alarm_type", "1")%}
Smoke!
{% elif is_state("sensor.smoke_co_alarm_basement_alarm_level", "255") and is_state("sensor.smoke_co_alarm_basement_alarm_type", "2")%}
CO!
{% elif is_state("sensor.smoke_co_alarm_basement_alarm_level", "0") and is_state("sensor.smoke_co_alarm_basement_alarm_type", "12")%}
Testing
{% else %}
OK
{% endif %}
icon_template: >-
{% if is_state("sensor.smoke_co_alarm_basement_alarm_level", "255") and is_state("sensor.smoke_co_alarm_basement_alarm_type", "1")%}
mdi:fire
{% elif is_state("sensor.smoke_co_alarm_basement_alarm_level", "255") and is_state("sensor.smoke_co_alarm_basement_alarm_type", "2")%}
mdi:cloud-outline
{% else %}
mdi:smoke-detector
{% endif %}
alert:
livingroom_smoke_alert:
name: Livingroom Smoke Alarm is On
entity_id: sensor.livingroom_smoke_alarm_status
state: 'Smoke!'
repeat: 5
can_acknowledge: true
skip_first: false
message: "The Livingroom Smoke Alarm is going off!"
done_message: "The Livingroom Smoke Alarm is now OK"
notifiers:
- alert_group_phone_sms
- alert_group_phone_voice
water_in_workshop:
name: There is Water in the Workshop Room
entity_id: binary_sensor.water_sensor_workshop_sensor
state: 'on'
repeat: 5
can_acknowledge: true
skip_first: false
message: "There is Water in the Workshop Room"
done_message: The Workshop Room is Now Dry
notifiers:
- pushbullet_notify
water_valve_is_closed:
name: The Water Valve is Closed
entity_id: switch.water_shut_off_valve_switch
state: 'off'
repeat: 5
can_acknowledge: true
skip_first: false
message: "The Main Water Valve has been closed"
done_message: The Main Water Valve is open
notifiers:
- pushbullet_notify
automation:
- alias: SWA Notification Smoke Alarm Basement
initial_state: 'off'
trigger:
platform: template
value_template: >
{% if (is_state("sensor.smoke_co_alarm_basement_alarm_level", "255") and is_state("sensor.smoke_co_alarm_basement_alarm_type", "1"))
or (is_state("sensor.smoke_co_alarm_basement_alarm_level", "255") and is_state("sensor.smoke_co_alarm_basement_alarm_type", "2"))%}
true
{% else %}
false
{% endif %}
action:
- service: script.tts_save_dot_volume
- service: media_player.volume_set
data:
entity_id:
- media_player.computer_room_dot
volume_level: 0.9
- delay: '00:00:05'
- repeat:
count: 5
sequence:
- service: notify.alexa_media
data:
target:
- media_player.computer_room_dot
data:
type: tts
message: "The Basement Smoke Alarm is going off! The Basement Smoke Alarm is going off!"
- delay: '00:00:15'
- delay: '00:00:05'
- service: script.tts_restore_dot_volume
- service: notify.pushbullet_notify
data:
message: >
{% if (is_state("sensor.smoke_co_alarm_basement_alarm_level", "255") and is_state("sensor.smoke_co_alarm_basement_alarm_type", "1")) %}
'The Basement Smoke Alarm is Going Off For Smoke!'
{% elif (is_state("sensor.smoke_co_alarm_basement_alarm_level", "255") and is_state("sensor.smoke_co_alarm_basement_alarm_type", "2")) %}
'The Basement Smoke Alarm is Going Off For CO!'
{% endif %}
- alias: SWA Notification Water Alarm Basement
initial_state: 'off'
trigger:
- platform: state
entity_id: binary_sensor.water_sensor_main_basement_sensor
to: 'on'
- platform: state
entity_id: binary_sensor.water_sensor_workshop_sensor
to: 'on'
action:
- service: switch.turn_off
entity_id: switch.water_shut_off_valve_switch
- service: script.tts_save_dot_volume
- service: media_player.volume_set
data:
entity_id:
- media_player.computer_room_dot
volume_level: 0.9
- delay: '00:00:05'
- repeat:
count: 2
sequence:
- service: notify.alexa_media
data:
target:
- media_player.computer_room_dot
data:
type: tts
message: "The water sensor in the basement is sensing water. The main water valve has been closed."
- delay: '00:00:10'
- delay: '00:00:05'
- service: script.tts_restore_dot_volume
- service: notify.pushbullet_notify
data:
message: "There is water in the Basement"
- alias: SWA Notification Water Valve Opened
initial_state: 'off'
trigger:
- platform: state
entity_id: switch.water_shut_off_valve_switch
from: 'off'
to: 'on'
action:
- service: script.tts_save_dot_volume
- service: media_player.volume_set
data:
entity_id:
- media_player.computer_room_dot
volume_level: 0.9
- delay: '00:00:05'
- service: notify.alexa_media
data:
target:
- media_player.computer_room_dot
data:
type: tts
message: "The main water valve has been opened and there is no water detected in the basement."
- delay: '00:00:05'
- service: script.tts_restore_dot_volume
- service: notify.pushbullet_notify
data:
message: "The main water valve has been opened and there is no water in the basement"
As you can see everything is entered in there exactly as it would be if you were writing it (in yaml) in your configuration.yaml file.
as far as naming I use either an acronym for the package itâs contained, the subsystem itâs associated with or the location of the device/entity if neither of those two make any sense.
But unfortunately mine is not a perfect system. i find myself doing a keyword search in Notepad++ at times because i just canât remember where I put x.
How I do the naming is as follows:
automation.
For e.x. automation.terrace_lights_motion â automation which turns on/off lights based on motion
automation.bathroom_washmachine_finished_notification
light.
For e.x.: light.livigroom_ledstrip, light.bedroom_ceiling
switch.
For e.x.: switch.hallway_biglight, switch.bathroom_washmachine
sensor.___
For e.x.: sensor.terrace_temperature, sensor.livingroom_door_contact
Also very good is to put Friendly-Names to entities, so you can also easily search for them later.
This way, you have also easily grouped together entites or scripts or automations from that particular area.
I have some Backup/System/Hass Automations which I name automation.house_restart_rpi or automation.house_backup.
With these, you can also use âauto-entitesâ card to easily and beautifully Group Automations into areas. I have one Dashboard with all the automations, Grouped by Area.