poudenes
(Poudenes)
October 25, 2023, 9:31am
62
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
petro
(Petro)
October 25, 2023, 12:01pm
63
This route will cause you issues. Instead use this:
create folder in integrations
folder named templates
add this to configuration.yaml
template: !include_dir_merge_list integrations/templates
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.
1 Like
âŚor you can go a bit further and use a âtask-levelâ splitting .
poudenes
(Poudenes)
October 25, 2023, 2:35pm
65
Thanks. What will go wrong. Because everything is working.
I will check the other solution you mention. thanks
petro
(Petro)
October 25, 2023, 2:37pm
66
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.
poudenes
(Poudenes)
October 25, 2023, 2:41pm
67
I donât know as well. But better to do it the right way.
chabro
November 18, 2023, 12:20pm
68
thank you for sharing
i changed my setup as you explained
helps me a lot
Hi everyone, first comment in Home Assistant forum.
Iâve been following this guide but I cant manage to get it work:
This is my configuration.yaml:
template:
- sensor: !include template_sensors.yaml
My template_sensors.yaml:
- name: "Electricity Price"
unit_of_measurement: EUR/kWh
state: >
{% set current_hour = now().hour %}
{% set current_day = now().weekday() %}
{% if current_day in [5, 6] %}
0.09
{% else %}
{% if 0 <= current_hour < 7 %}
0.09
{% elif 8 <= current_hour < 9 %}
0.14
{% elif 10 <= current_hour < 13 %}
0.19
{% elif 14 <= current_hour < 17 %}
0.14
{% elif 18 <= current_hour < 21 %}
0.19
{% elif 22 <= current_hour < 23 %}
0.14
{% else %}
0.09
{% endif %}
{% endif %}
- name: "Habitacion_last_updated"
value_template: >
{% if is_state('binary_sensor.sensor_habitacion_contact', 'on') %}
{{ as_timestamp(states.binary_sensor.door_sensor.last_changed) | timestamp_custom('%d-%m %H:%M') }}
{% else %}
{{ as_timestamp(states.binary_sensor.door_sensor.last_changed) | timestamp_custom('%d-%m %H:%M') }}
{% endif %}
I dont get any errors but I cant see the sensors