now i would like to be able to let her say;
âthe following windows are open:â
and then for each entry in the list:
âxxxxx window since xx hours xx minutesâ
is there a way to achieve this?
Is there a code reference for that line:
{{ expand(âswitch.fensterâ)|selectattr(âstateâ,âeqâ,âonâ)|map(attribute=ânameâ)|list|join(â, ') }}
which language is that?
where can i help myself?
i feel like the last idiot on this world for having to ask every step on here.
Itâs jinja and you can definitely do this just by looping through the list of windows where they are open and then retrieving that data for each. You should use the developer tab template section and construct it till you get closer then ask questions on the way.
The first question for the outer loop is how do you identify all the windows to loop through? By a naming convention? Domain? etc⌠Once you can produce a list of windows the next step is to filter on the âopenâ which is already part of your code selectattr above.
Maybe this will get you goingâŚ
{% for entity_id in expand('group.presence_simulation_group')|selectattr('state','eq','on')|map(attribute='entity_id')|list %}
{{state_attr(entity_id,'friendly_name')}} are {{states(entity_id)}}
{%- endfor %}
I have routines set up with specific trigger phrases that then run scripts in HA. If you have HA exposed to Alexa, your scripts are available as end points under Smart Home > Scenes in the Alexa routines.
This is what I use for open windows, it is room-based rather than listing every open window by nameâŚ
I donât have anything set up to pull time open.
{% for entity_id in expand('group.presence_simulation_group')|selectattr('state','eq','on')|map(attribute='entity_id')|list %}
{{state_attr(entity_id,'friendly_name')}} are {{states(entity_id)}}
---- In there you then just need to write the query to compare the current time to the time last_changed time. Then you know 'how long'.
{%- endfor %}
Or you find someone who has already wrote this to paste their code and win.
what do i do wrong, and why do i need to ask every step?
EDIT: and why does my group not have the name group.fenster?
why is it switch.fenster? i made a helper group.
and why can i have 4 of 5 sonoff sensors in it, but the last one is not a switch, its a binary.sensor.
and its also a sonoff device, i bought 5 and one is differentâŚ
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