Dynamic Alexa Flash Briefing via Routines

Thank you very much. Got it working now.

Hi Im trying to get this work but having an issue hopefully you guys dont mind helping me with. I was trying to setup the flash briefing but ran into the not connecting because of my lets encrpyt cert.

So I found this thread and created another lambda function hoping to go that route. Im getting this when I try and access the invoke url. {“message”: “Internal server error”}

my ha config is: (just testing with something simple first)

alexa:
  flash_briefings:
    test:
      - title: Who is watching Plex?
        text: "{{states('sensor.plex_template')}}"

This is the function code:

from __future__ import print_function
import json
import urllib
import datetime
def respond(err, res=None):
 return {
 'statusCode': '400' if err else '200',
 'body': json.dumps({
 "uid": res['uid'],
 "updateDate": res['updateDate'],
 "titleText": res['titleText'],
 "mainText": res['mainText'],
 "redirectionUrl": "https://xxx.xxx.xxx/" 
 }),
 'headers': {
 'Content-Type': 'application/json',
 },
}
def lambda_handler(event, context):
    print(event)
    print(context)
    response = urllib.request.urlopen('https://xxx.xxx.xxx/api/alexa/flash_briefings/alexa?api_password=stayout12!')
    html=response.read()
    rawdata = json.loads(html)
    return respond(None, rawdata[0])

Im thinking this might be wrong but idk what to use?
"redirectionUrl": "https://xxx.xxx.xxx/"

I would really like to add it as a flash briefing, its just not possible with lets encrpypt at all?

thank youuuu!!!

When I use the flash briefing way, if I take the url for the flash briefing and put it into a browser i get what amazon should be getting. So the hang up is due to the cert for sure?

thank you so much for sharing this. i feel this is much better than the official instruction. now it works with let’s encrypt SSL.

Can someone confirm if the Official Alexa Flash Briefing is working?

I’m geting an “401 - Unaurhorized” error when I try to open the URL: “https://YOUR_HOST/api/alexa/flash_briefings/BRIEFING_ID?api_password=YOUR_API_PASSWORD”.
Any my legacy API_PASSWORD is correct and working fine to access the UI.

Im unsing HA 0.102.1

are you sure that the legacy API_PASSWORD is working?
because a lot of users already mentioned that it isnt working anymore since release 101, HA took out the deprecated api password as i heard.

Yes. It is still working if it is added as an auth_providers type (not in the http header).
If API_PASSWORD is depreciated, how the alexa flash breafing url is supposed to be authenticated?

i dont know how to do it in that case, but i get a lot of reports from people that used api password for cam on HADashboard, that say it isnt working anymore since 101.
and its been deprecated for a long time.

and i got a hard time understanding what they actually mean in the blog:

API Password and trusted networks

It is no longer possible to make authenticated requests using trusted networks or by appending ?api_password=X to the URL. You will now first need to get an authentication token and use that token to make requests.

These features were deprecated in Home Assistant 0.90 and 0.91 (released around April 2019). It was initially planned to be dropped in Home Assistant 0.96 (released July 17, 2019).

The support of configuring the auth providers for API Password and Trusted Networks via the HTTP configuration is also removed. It now needs to be configured in the auth provider section (docs).

Direct authentication meant that you could make an authenticated request without a bearer token by making the request from a trusted network or appending ?api_password=X to the URL.

These features are still available as authentication providers (docs).

I confirm that the API_PASSWORD doesn’t work anymore in the http header but it is still possible to use it as an auth provider type. I tested and it is working but for some reason it is not working in the Alexa Flash Breafing url. Either the integration or the documentation for Alexa Flash Breafing has to be updated because right now it is not usable.
Do you know How can this be officialy reported?

homeassistant:
  auth_providers:
    - type: homeassistant
    - type: legacy_api_password
      api_password: <mypasswordhere>

Alexa API error: (https://YOUR_HOST/api/alexa/flash_briefings/BRIEFING_ID?api_password=YOUR_API_PASSWORD)

401 - Unauthorized

create an issue on github.

Issue created

The isse was closed without taking any action… Very disappointed…
Someone said that API_PASSWORD has been deprecated that is something that we already know. In the meantime, the Alexa Flash Breafing is useless in Home Assistant.
I don’t understand why the close the issue if the problem is still there.
Can someone create another issue? Just copy what I put in the one above.

what balloob means with PR welcome is:
you can create a pull request for the HA github to remove all code about the flash briefing, because its just not possible to use it anymore.
and he’s not doing the work to take it out.

Im creating a workarround now to use a py script to properly use the Alexa Flash Briefing API with a Token and expose the result to internet to be consumed by Alexa.
Im not familiar with HA code but it should be easy to just fix Flash Briefing. For example, to remove the authentication and users can use it under their onw risk.

Flash Breafings are really useful to create your own reports based on the sensor data and having alexa telling you the temperature of all the rooms on the house.

there are other possible ways to do it also nowadays.

with the (custom) alexa mediaplayer you can have alexa say anything you like.

and i use appdaemon to do a simular thing.

Can you give me some examples and references? Can the Custom Alexa Mediaplayer include information about the sensors? (Like temperature of all the sensors). And can I trigger it with “Alexa, report sensors status”

yes with the custom media player you can send any TTS to alexa devices, also including sensor values. (like notify)

and with emulated you you can trigger any action in HA.

in this (very long) topic you can find a lot of info from people doing that kind of stuff.

Looks promising. However, I don’t see how can I trigger Alexa with a custom command like “Alexa, report sensors status from Home Assistant”

create a routine that triggers something in HA (i use a non existing light and set the brightness to a certain level)

Here is an updated version of the Lambda code, which works with long lived tokens (I’ve tested it, and it works from my Echo Dot):

from __future__ import print_function
import json
import urllib
import datetime
def respond(err, res=None):
 return {
 'statusCode': '400' if err else '200',
 'body': json.dumps({
 "uid": res['uid'],
 "updateDate": res['updateDate'],
 "titleText": res['titleText'],
 "mainText": res['mainText'],
 "redirectionUrl": "https://xxx.xxx.xxx/" 
 }),
 'headers': {
 'Content-Type': 'application/json',
 },
}

def lambda_handler(event, context):
    token = 'YOUR_LONG_LIVED_TOKEN_HERE'
    req = urllib.request.Request('https://xxx.xxx.xxx/api/alexa/flash_briefings/alexa')
    req.add_header('Authorization',  'Bearer {}'.format(token))
    response = urllib.request.urlopen(req)
    html = response.read()
    rawdata = json.loads(html)
    return respond(None, rawdata[0])