- trigger:
- platform: time_pattern
seconds: "/1"
- platform: event
event_type: "oplaad_matrix_update"
- platform: homeassistant
event: start
sensor:
- name: "AI Oplaad Master Matrix"
unique_id: ai_oplaad_master_matrix
icon: mdi:matrix
# De status telt simpelweg het aantal laders in de lijst
state: >
{% set h = state_attr('sensor.ai_oplaad_master_matrix', 'actief') %}
{{ h | count if h is list else 0 }}
attributes:
actief: >
{# 1. HAAL GEHEUGEN OP ZONDER 'THIS' #}
{% set h = state_attr('sensor.ai_oplaad_master_matrix', 'actief') %}
{% if h is not list %} {% set h = [] %} {% endif %}
{# 2. VERWERK DATA #}
{% if trigger.platform == 'event' and trigger.event.event_type == 'oplaad_matrix_update' %}
{% set d = trigger.event.data %}
{% if d.actie == 'add' %}
{% set n = {
'id': d.id | string,
'naam': d.naam | string if d.naam else 'LADER',
'start': d.start | int,
'eind': d.eind | int
} %}
{{ ([n] + (h | rejectattr('id', 'eq', n.id) | list)) | list }}
{% elif d.actie == 'del' %}
{{ h | rejectattr('id', 'eq', d.id | string) | list }}
{% elif d.actie == 'reset' %}
{{ [] }}
{% else %} {{ h }} {% endif %}
{% else %}
{# Seconde-tik of start: behoud de lijst #}
{{ h }}
{% endif %}
spreuken:
- "Matrix motor v_8.7 online"
- "Systeem reanimatie voltooid"
- "Wachten op Bart..."
The file states:
config:\Templates\AI
in configuration.yaml it says: template: !include_dir_merge_list Templates/.
All other sensors in this map are working
I've been searching high and low but there must be an error somewhere here, I've already tried 101 things but the sensor remains unavailable?
Your state is based off an attribute that won't have a value, and you haven't supplied a default.
I would move the large template into a variable so that it is rendered immediately after the trigger and supply a default for h so it doesn't fail on the first run:
- triggers:
- trigger: time_pattern
seconds: "/1"
- trigger: event
event_type: "oplaad_matrix_update"
- trigger: homeassistant
event: start
variables:
actief: |
{# 1. HAAL GEHEUGEN OP ZONDER 'THIS' #}
{% set h = state_attr('sensor.ai_oplaad_master_matrix', 'actief')|default([],true) %}
{# 2. VERWERK DATA #}
{% if trigger.platform == 'event' and trigger.event.event_type == 'oplaad_matrix_update' %}
{% set d = trigger.event.data %}
{% if d.actie == 'add' %}
{% set n = {
'id': d.id | string,
'naam': d.naam | string if d.naam else 'LADER',
'start': d.start | int,
'eind': d.eind | int } %}
{{ ([n] + (h | rejectattr('id', 'eq', n.id) | list)) | list }}
{% elif d.actie == 'del' %}
{{ h | rejectattr('id', 'eq', d.id | string) | list }}
{% elif d.actie == 'reset' %}
{{ [] }}
{% else %} {{ h }} {% endif %}
{% else %}
{# Seconde-tik of start: behoud de lijst #}
{{ h }}
{% endif %}
sensor:
- name: "AI Oplaad Master Matrix"
unique_id: ai_oplaad_master_matrix
icon: mdi:matrix
# De status telt simpelweg het aantal laders in de lijst
state: >
{{ actief | count if actief is list else 0 }}
attributes:
actief: "{{ actief }}"
spreuken: |
{{- ["Matrix motor v_8.7 online",
"Systeem reanimatie voltooid",
"Wachten op Bart..."] }}
When I try the config I'm getting an error related to the spreuken attribute... it doesn't seem to like the YAML list syntax. If I change it to a list in a Jinja template it works...
I've changed my post above to use what is working on my instance: