Splitting config for template:

Hi All,

I was struggling also with trigger templates and slit config. This is how I solved it:
only a error in VSC with the !include but all sensors, binary_sensors and triggers working.

Incorrect type. Expected: "object".

template:
  - sensor: !include integrations/template_sensor.yaml
  - binary_sensor: !include integrations/template_binary_sensor.yaml
  - !include_dir_merge_named integrations/template_trigger.yaml

/template_sensor.yaml

---
- name: "Group Family Manual"
  unique_id: "3e43a954-abc1-447a-af7c-8f789ba73f2f"
  state: "{{ is_state('input_boolean.helpers_kay_home_homekit', 'on') or is_state('input_boolean.helpers_peter_home_homekit', 'on') }}"
  device_class: presence
  delay_off: "00:15:00"

etc, etc

/template_binary_sensor.yaml

---
- name: "Asus devices offline"
  state: "{{ integration_entities('asusrouter') | select('is_state', 'not_home') | list | count > 0 | float(false) }}"
  unique_id: "42a19e1a-9396-42a9-81a1-94e8ee74fa5d"
  attributes:
    entity_id: "{{ integration_entities('asusrouter') | select('is_state', 'not_home') | list }}"

etc, etc

/template_trigger.yaml

---
trigger:
  - trigger:
      - platform: event
        event_type: "imap_content"
        id: "custom_event"
        event_data:
          sender: !secret imap_sender_2
    sensor:
      - name: "Imap import DW NS"
        state: >-
          {% if 'DiSys' in trigger.event.data["subject"] %}
            Nieuwe DW
          {% endif %}
        attributes:
          Message: "{{ trigger.event.data['text'] }}"
          Date: "{{ trigger.event.data['date'] }}"

etc, etc

This route will cause you issues. Instead use this:

  1. create folder in integrations folder named templates

  2. add this to configuration.yaml

    template: !include_dir_merge_list integrations/templates
    
  3. Use this format in your files, you can even combine or separate your sensors/binary_sensors/trigger based. Name the file whatever you want, the name won’t matter. You can organize your files based on what it’s doing.

    - binary_sensor:
      - name: "Group Family Manual"
        unique_id: "3e43a954-abc1-447a-af7c-8f789ba73f2f"
        state: "{{ is_state('input_boolean.helpers_kay_home_homekit', 'on') or is_state('input_boolean.helpers_peter_home_homekit', 'on') }}"
        device_class: presence
        delay_off: "00:15:00"
    
      ... etc
    
    - sensor:
      - name: ...
    

If you continue with your current method, you’ll need to make a separate include for every template entity type. You’ll have to maintain a correct name, and there will be no organization to your filenames. They will be rigid.

This is what my folder looks like, it tells me exactly what each file does.

image

1 Like

…or you can go a bit further and use a “task-level” splitting.

Thanks. What will go wrong. Because everything is working.

I will check the other solution you mention. thanks

when you add anything new, like another trigger sensor. Merge dir named won’t work for that. Not sure how it’s even working for you now.

I don’t know as well. But better to do it the right way.

thank you for sharing
i changed my setup as you explained
helps me a lot