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.