There’s lots of documentation. I suggest you review this section: Templating
This template has many errors:
message: "{{ name("entity") }} blank has been {{ states("entity") }}"
If you use double-quotes outside of the template, you must use single-quotes inside the template (or vice-versa). You can’t use the same quotes inside and outside of the template.
There is no name() function so I don’t know where you got that from.
This part "entity" means it is simply the word entity and nothing else. Passing the word "entity" to the states() function is invalid and accomplishes nothing.
Based on just the example you posted, I don’t know where it is used (automation or a script?) or which entities it is attempting to use. Please explain how you intend to use it.
Post it and please format it correctly. The previous example you posted was unformatted and makes it difficult to determine if it has syntax errors (like incorrect indentation).
hi taras
I am trying to adapt the following code to my automation.
I have 2 problems.
if i simply paste your code to the developers tools - template
I got the following
TemplateRuntimeError: No test named 'eqon'.
I am not sure that this is a problem.
but when I try to change the bianary sensors with mine
like this
message: >
{% set fenster = [
states.binary_sensor.8_erker_tzami,
states.binary_10_ypnodomatia_tzami,
states.binary_5_trapezaria_tzami,
states.binary_sensor.13_mpanio_wc ]
| selectattr('state', 'eq' 'on')
| map(attribute='name') | list %}
{% set qty = fenster | count %}
{% if qty == 0 %}
Everything is closed.
{% else %}
Please close the following window{{ 's' if qty > 1 else ''}}: {{ fenster | join(', ') }}
{% endif %}
Yes, now the first problem is eliminated. If I paste your code i get “Everything is closed.”
but
in the same code if I try to replace the first sensor with a mine one
like this
message: >
{% set fenster = [
states.binary_sensor.10_ypnodomatia_tzami,
the binary sensor name is 10_ypnodomatia_tzami
is there any chance that HA template can’t work with this kind of naming in the binary sensors (if they have a number for example?)
my 4 sensors names are
binary_sensor.10_ypnodomatia_tzami,
binary_sensor.5_trapezaria_tzami,
binary_sensor.13_mpanio_wc
binary_sensor.8_erker_tzami
I’m struggling with the templating here; I put all the window sensors into a group, but I can’t get the automation to parse. I get the error: Error rendering data template: TypeError: argument of type ‘NoneType’ is not iterable
Can anyone suggest what is wrong and how to fix it?
alias: Status Automation
description: ""
trigger:
- platform: state
entity_id:
- input_boolean.status
from: "off"
to: "on"
condition: []
action:
- service: notify.alexa_media_bedroom
data:
message: >-
{% set open_windows = states | selectattr('entity_id','in', state_attr('group.windows','entity_id')) | selectattr('state','eq','on') | map(attribute='name') | list %}
{% if open_windows | length == 0 %}
All windows are closed.
{% elif open_windows | length == 1 %}
There is a window open in the {{ open_windows | join('') }}.
{% else %}
There are windows open in the {{ open_windows[:-1] | join(', ') }}{{',' if open_windows | length > 2 else ''}} and {{ open_windows[-1]}}.
{% endif %}
mode: single
You are right! I put the window sensors in a group, but the group is showing as binary_sensor.windows. I will just change the name to binary_sensor.windows and see if that helps.
I have the following script working as a notification
alias: "Windows open notification 2 "
sequence:
- service: notify.mobile_app_imrans_pixel
data_template:
message: >
{{ states | selectattr('entity_id','in', state_attr('group.windows','entity_id')) | selectattr('state','eq','on') | map(attribute='name') | join(', ') }}
title: "Window still open: "
data:
priority: 1
mode: single
icon: mdi:window-open-variant
Can anyone help to get this working as tts. I have tried the following but I just get a voice saying null. If I change the string to simple text then it works.