@broder
NOTE: HA is releasing a new helper for templates. Maybe just wait for the next release before you do all this work. It will be out this Wednesday for HA release 2023.9.
There are many ways to split up the configuration. There is no wrong or right way to do it, it just realy depends on the way you would like it + it must work. Before splitting up your configuration I would strongly recommend that you do some research before committing to one way, as it takes some time to set everything up. Below are two links to the official Home Assistant website on this topic (there could be more but this is what I know). Both ways work. There are also a lot of different posts on this forum + some YouTube videos also on this topic so maybe check them out.
- Splitting up the configuration
- Packages
The way I like is; Splitting up the configuration - Advanced Usage " !include_dir_merge_list
". For me it is very similar to you normal PC file structure. I simple and easy and I like that. Below I will show how I set up my template sensors as I did create a FAQ on template sensors in this topic. This âSensor Lightâ post is not a âHow To Use Home Assistantâ and would prefer to stay on topic of this blueprint so I will stick to just template sensors. If you would like more information on split up the configuration please search this forum or create a new topic. There are a lot of active community members that will be able to assist you.
How I split up the configuration
1 - First most important, do a full backup of your Home Assistant, and store it in a location where you can get to it if you brick your Home Assistant (on a separate computer not running Home Assistant).
2 - You must have a file editor. There are few to choose from. If you donât have one already installed then this is how to add the official âFile Editorâ into your Home Assistant. Go to Settings / Add-ons and then click on âadd-on storeâ. In the " Official add-ons" heading you will see âFile Editorâ, click on it and install it.
3 - Once you have a file editor you will need to create a new folder called âtemplateâ in the main directory â/config/
â (same location you can see your âconfiguration.yaml
â file). Once done you will have â/config/template
â folder location. This is where we are going to put all our template sensors. In this folder I have also created another folder called âsensors
â. This is where I put all my sensor in. I donât care if they are a âsensorâ, âtemplate binary_sensorâ, âtemplate trigger_sensorâ, etc they are all in the one folder. Some people like to split there sensors into the domain of the sensor, it up to you. So now I have a â/config/template/sensors
â folder location.
4 - In your âconfiguration.yaml
â file we will need to point HA to it. To do this you would enter this code.
template: !include_dir_merge_list template
Now all your templates must go into this folder.
5 - In the â/sensors
â folder, I create a new file for each sensor. We will use the template sensor I call âBee In The Hiveâ for this example. So I create a file called âbee-in-the-hive.yamlâ. Note: You must have the â.yamlâ for each file you create. In that file I put this code as described in my FAQ Template Sensors.
# Bee In The Hive
- trigger:
- platform: state
entity_id: binary_sensor.your_door_sensor_here
to: "on"
- platform: state
entity_id: binary_sensor.your_door_sensor_here
to: "off"
for:
seconds: 10
- platform: state
entity_id: binary_sensor.your_motion_sensor_here
to: "on"
binary_sensor:
- name: "Bee In The Hive"
device_class: occupancy
icon: mdi:account-box-outline
state: >
{{ is_state('binary_sensor.your_door_sensor_here', 'off') and is_state('input_boolean.testing_motion_sensor', 'on') }}
Note: We did not need to put
template:
at the top if each sensor file as this is back in the âconfiguration.yaml
â file.
Then check your configuration by going to âDeveloper Toolsâ and âCheck Configurationâ link. Once it passes " restart HA with one sensor first to make sure you have everything correct. Test it make sure it is working. Then when you feel confident add the rest of your sensors checking your configuration every time you add a file as it is easer to find what you have done wrong.
Then you would just do the same for all your template sensors in there own file.
Hope this helps you.
Blacky