Ask alexa about a sensor state

Hi,

is there an easy way to ask alexa about sensor states. I have aqara window sensors and I’d like to ask something like “Alexa, are all of my windows closed”?

thanks

2 Likes

Alexa Supports the entity type “CONTACT_SENSOR” (not yet in Germany). So I suppose it will be possible in the future. I plan to write an Appdaemon app for exactly that usecase. You just gave me some more incentive to finally do it :wink:

1 Like

So I finally implemented this functionality with Appdaemon and a custom Alexa App.
You can find the source code here and the documentation here

If you have any questions feel free to ask. I am glad to help and improve the documentation.

1 Like

You can use this too…

There’s an example in there of how I use it with a temp sensor, exactly the same principle for your needs.

I already use this (mentioned at the end of your link)

to let alexa talk when the washing machine is finished.

I’m not sure but I think this component will not work in the other direction. So I don’t think that I can ask Alexa something. I think with this you can only let it tell you something.

@eifinger
I did’nt try your code yet, because I never liked to tell alexa which skill should be opened. I just want to talk to alexa without thinking about what skill I need. I mostly don’t use this.

So instead of saying “Alexa ask Home Assistant about the windows”, I’d like to have it without asking Home Assistant.
So only “Alexa, are all my windows closed”.

As long this is not possible, it’s not worth to implement this. I could remember so say the “home assistant”, but everyone else in the house will forget it some days later.

Don’t know about the one you linked, never tried it, but the one I linked to does exactly that which is why I said it did!

Ok, i went through your link again.

I might be wrong but as I understand you can only command alexa to say something triggered by ha.

I did not see something about alexa triggering ha.

  1. ask alexa about the windows
  2. alexa forwards request to ha
  3. ha looks for opened windows
  4. TTS command Alexa triggered by ha

Currently I would be able to do 3 and 4.
Are you sure you can do 1 and 2?
Maybe you can point to posting in your link

I wrote an audit program to announce the state of various sensor.

Its triggered by an input boolean . You could create an alexa routine in the alexa app called "alexa tell me about “blah blah” then get this to trigger the input boolean it will then announce the state of the sensor

If you use Node Red, I think you could also set up a flow in Node Red that starts on an Alexa command, and the output is an Alexa TTS. I plan to try that when I get a chance.

Ok great, but I don’t know how to get this to work. I don’t know where to put your code. Also I’m already using this:

and you suggest using this:

I have updated my code to run

This an Appdeamon script so needs the Appdeamon add-in

https://www.home-assistant.io/docs/ecosystem/appdaemon/

If you’re not currently running Appdeamon the learning curve is quite steep.

I assume you are using emulated hue or Alexa Cloud to connect to HA and have the Alexa media player working?

If so why not simply create a script to extract the sensor value to put into the Alexa media player TTS and then call the script from Alexa using the routines in the phone app. This will also allow you to use a custom response so, for example, you can respond with “The door is”. The script will run and this will complete the sentence.

My script will give a full audit like in StarTrek :slight_smile: so maybe a little too much information. Documentation is in the script header.

Hope this helps

It’s this one…

You just need to expose the TTS script to Alexa which would give you “Alexa, turn on windows” if it was called script.windows", you can then just add “Alexa, are the windows open?” under Routines in the Alexa app and away you go.

Simples :slight_smile:

1 Like

Hello Bobby, I have read through what you did and have a working routine to ask for humidity etc (my temp sensors work directly with alexa…but those are the only ones for now). But one thing I was wondering is, as I have multiple echos, is how I can get the device that triggered the script? I want it to announce back only to the device that I spoke to.
Any hints?

1 Like

Without changing the question you ask Alexa slightly for each instance I don’t know how you’d do it, sorry.

Could you post an exaple of your script?

I’m facing problems writing a script that is able to fire two different actions dependent on the status of the windows.

have a look at this

This uses a routine from the Alexa App to trigger a dummy bulb. You can fix which alexa responds to the routine and the dummy bulb will give you 99 different triggers depending on how you set it in the Alexa routine

Ohhh suuppeeer! Thanks :smiley: