is there a way to see the output in a console window?
and what is a template and what a script? (in terms of HA)
i developed an application in C# with over 18’000 lines of code, all by myself. Wrote a manual of over 50 pages for it, and 5 people worked with my application all day long for years. All that wasnt that frustrating as it is to implement something so simple in a system like HA.
which gives me a datetime. (i also could use the as_timestamp)
but if i want to have it not from that specific entity, but from the one in the iteration of the for loop?
i tried this:
{{as_timestamp(states.(‘entity_id’).last_changed)}}
and some 20 other variants…
nothing…
{% for entity_id in expand('switch.fenster')|selectattr('state','eq','on')|map(attribute='entity_id')|list %}
{{state_attr(entity_id,'friendly_name')}} ist offen seit {{as_timestamp(states.entity_id.last_changed)}}
{% endfor %}
{{states.switch.sonoff_10015c8b2f.last_changed}}
and is there a possibility to get that keyhole window a bit bigger in that template tab?
so at least i could see a full line?
But you’ll also need that thread I linked to to make it ‘pretty’ for alexa to say… Like you’ll need the difference between now and the last change and convert that to minutes/hours/days. that is what that thread I linked you to should help with…
Annoying right? I dont think so. I saw an enhancement request for this but nada.
The example I posted was a script. Scripts can be created in the UI or saved to the file scripts.yaml located in the config directory. IMO Scripts are the best way to integrate Alexa routines with HA. The example relies on you creating a binary sensor group through the UI (options for legacy style groups can be found lower down in that same gist).
The following is quick and dirty, and still relies on a binary sensor group, but it gives name and relative time open… I have set it up as a service call for you to test it, but you will want to use a script if your desire is to be able to trigger it by voice through an Alexa.
service: notify.alexa_media_echo_studio_2
data:
message: >
{%- set ow = expand('binary_sensor.all_window_sensors')
| selectattr('state','eq','on')
| map(attribute='entity_id') | list %}
{%- set ns = namespace(open_time=[], name=[]) %}
{%- for w in expand(ow)|list %}
{%- set open_time = relative_time(expand(w)
| map(attribute='last_changed')|join|as_datetime) %}
{%- set name = w.name%}
{% set ns.open_time = ns.open_time + [name~" has been open for about "~open_time]%}
{%- endfor %}
{% set qty = ow | count %}
{% if qty != 0 %}
There {{'is an' if qty==1 else 'are '~qty}} open window{{' ' if qty==1
else 's '}}
{% if ns.open_time not in [[], None, 'unknown'] %}
{{ns.open_time|join(", \n")}}
{% endif %}
{% else %}
There are no open windows
{% endif %}
data:
type: tts
My suggestion is to ‘fix that after’ in the zigbee integration… But at least get this tts accomplished for now so you feel accomplished. You can always just change the group again after.
they are wifi ones… because i initially needed wifi ones for the washing machine and the dryer, because the room is far away and no chance to get cable there to mount a zigbee hub…
and then of 2 ordered, one came broken. then i ordered more and now i got 5.
but one is different, he identifies as binary. the rest as switch.
Option 4: We work around the strangeness… replace the all caps part with your binary sensor’s actual object id.
service: notify.alexa_media_echo_studio_2
data:
message: >
{%- set ow = expand('switch.fenster', 'binary_sensor.YOUR_BINARY_SENSOR')
| selectattr('state','eq','on')
| map(attribute='entity_id') | list %}
{%- set ns = namespace(open_time=[], name=[]) %}
{%- for w in expand(ow)|list %}
{%- set open_time = relative_time(expand(w)
| map(attribute='last_changed')|join|as_datetime) %}
{%- set name = w.name%}
{% set ns.open_time = ns.open_time + [name~" has been open for about "~open_time]%}
{%- endfor %}
{% set qty = ow | count %}
{% if qty != 0 %}
There {{'is an' if qty==1 else 'are '~qty}} open window{{' ' if qty==1
else 's '}}
{% if ns.open_time not in [[], None, 'unknown'] %}
{{ns.open_time|join(", \n")}}
{% endif %}
{% else %}
There are no open windows
{% endif %}
data:
type: tts