I have never had a cookie timeout with the alexa mediaplayer component . Thatâs way Iâm glad the last alexa option is now supported and I can drop using the script.
I use the last alexa option to converse with echoâs dotted around the house , to ensure the correct echo responds. see the following
Uh, that really looks difficult to set that up. I will try.
And you already use the sensor.last_alexa from the mediaplayer component. Is it fast enough in your setup. This sensor takes forever for me to update.
Unfortunately, I never got to grips with Home Assistant automations , so I use Python with Appdaemon
The principle however is very simple
to create a two way conversation with Alexa.
create a routine in the aleax app. to say "is the patio door open " or whatever you have a sensor for
Trigger a dummy bulb to 10% (doesnât matter the value , 1 bulb 100 different triggers)
get alexa to say "let me check this for you " . This will buy you some time while the last alexa sensor updates
Trigger a HA automation on the dummy bulb switching to 10%
check if the patio door is open or closed and create a TTS response to the last alexa sensor saying âthe patio door is (opened or closed)â.
Set the dummy bulb back to 0%
My Parser script just allows you to create variations on the above without having to program multiple automatons. I was taught many, many years ago when compute time was very expensive âonly write a program onceâ
Thanks for making that clear. As for now Iâd like to keep it simple, if I have more ideas for that, than I will possible switch to your solution.
But currently for testing wha it can do, I think I can stay with ha automations.
However, I do have another issue now. I donât want to spam the forum a third time with that concern, so I pointing to my question (last_called doesnât update). Maybe you have an idea about it, as your are experienced with cookies. I have no idea what causes this, but maybe its a cookie issue?
See the edit seciton here
Ok, so currently the last_alexa sensor doesnât work reliable, but Iâm hopefully that this will change soon with an update.
So this is one an automation where I want to use it.
Iâd like to have have a look on it from an more experiences user like @petro
Maybe itâs possible to make this more compact.
the input_boolean is setup in alexa to I can turn it on with a routine. This triggers this automation:
The thing is that that the example above works in the dev_template (=shows the entity) and doesnât work when you use it in the sensor.yaml file. After a restart the state will stay empty (another user also reported this in the alexa thread).
Do you know how do solve this? Maybe you can try it yourself to see if you also get this behaviour.
Thatâs how template sensors work. Your top value template doesnât have any entity_idâs in it, so the template doesnât know when to trigger a change. The template below does update, because it has the entities it needs to trigger an update.
if you pair the value_template with the list of media players, the top template will work.
I have the following service call in an action and it works as expected:
- service: media_player.alexa_tts
data_template:
entity_id:
- media_player.computer_room_dot
- media_player.kitchen_dot
- media_player.livingroom_dot
#- media_player.master_bedroom_dot
- media_player.garage_dot
- media_player.big_room_dot
message: >
{% if states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[5] is defined %}
Attention!,,,Attention!,,,The National Weather Service Has issued a {{ states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[5] }}
{% elif states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[4] is defined %}
Attention!,,,Attention!,,,The National Weather Service Has issued a {{ states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[4] }}
{% elif states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[3] is defined %}
Attention!,,,Attention!,,,The National Weather Service Has issued a {{ states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[3] }}
{% elif states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[2] is defined %}
Attention!,,,Attention!,,,The National Weather Service Has issued a {{ states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[2] }}
{% elif states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[1] is defined %}
Attention!,,,Attention!,,,The National Weather Service Has issued a {{ states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[1] }}
{% else %}
Attention!,,,Attention!,,,The National Weather Service Has issued a {{ states.sensor.nws_alerts.attributes.spoken_desc.split('\n\n-\n\n')[0] }}
{% endif %}
I think you miss understood me. Iâm referring to listing out devices for updating sensor templates. @h4nc was mentioning how his template sensor was not updating. And itâs because this template doesnât contain any entity_idâs.
value_template: >
{%- for entity in states.media_player -%}
{%- if state_attr(entity.entity_id, 'last_called') == True -%}
{{ entity.entity_id }}
{%- endif -%}
{%- endfor -%}
So, if he adds the entities it will update. Like so
entity_id:
- media_player.1
- media_player.2
value_template: >
{%- for entity in states.media_player -%}
{%- if state_attr(entity.entity_id, 'last_called') == True -%}
{{ entity.entity_id }}
{%- endif -%}
{%- endfor -%}
Then I mentioned how he could shorten the template if he wanted to. A bit more complicated if you donât understand it, but it gets the same goal âthe last used alexaâ.
I got the template without the entities from the alexa component docs
So this should be changed, because other users might also have issues with that.
But I donât know how to change that there.
Edit: so there is no way to do this without specifying the entities? Maybe a more automatic way that uses all media players that start with or contain âalexaâ
That is just a limitation of template sensors, template binary_sensors, value_templates for template lights etc, triggers, and wait_templates. You always have to list out the items to cause the sensor to update. There is no way to do this without specifying the media_players. Unless you move to appdeamon or some other package. Home assistant only listens to things in templates that it can find. So when it âhearsâ a change, it updates.
The only time you donât need to list out entities in templates is inside actions/scripts or conditions. Because those trigger off something else (the trigger).
The only drawback of your template sensor is that if you add a dot, you have to update the template with an additional if statement. The template I provided and the one @h4nc came up with using the for loop only require the addition of a new entity_id in the entity_id list. So itâs essentially a difference of writing the if statement. Either way, it doesnât matter cause you still gotta update the template. It just depends on how much work you want to do.