You can do that with custom skills. You have to ask for the skill, but it works. I have a few of them:
“alexa, ask home how cold/hot is now” and she replies with the values of outside and living room temperatures.
“alexa, ask home about windows”, and she tells me if i left a window open
and one we use here at work/university:
“alexa, ask home about lunch” and she tell us the menu of university restaurant. For this one i use a couple of auxiliary scripts to scrape a webpage and google tts to make it a mp3 in portuguese :-).
Thanks, I appreciate the response, and not saying it’s not useful information, But both of these solutions are TTS solutions that happen to use Alexa’s. Again, I love that, and use it myself. I totallty understand how to use Alexa to trigger automations/scripts to have TTS devices speak back anthing you want. Weather reports, etc. Anything. But it’s not the same as saying “Alexa what is the upstairs Temp”, Or Alexa what is the state of the back door deadbolt."
After doing more searching, it looks like state information for devices discovered by Alexa, might be limited to Thermostat/Temp, lock/unlock, At this time. I’ve never asked if a light is on/off.
Ok. Thanks. Guess I misunderstood. I’ll have to read through the posts to figure out how lounge temp is the device to trigger your script. Sounds very promising. I gues I could set up something similar for google time sensors which was kind of my goal.
Sounds like I should be able to say Alexa how long is my commute to work and have a TTS message from my echo provide the answer.
Thanks again. Very cool. Sorry I missed that. I have not spent as much time on that thread as I had my Econ’s set up with the other “testers needed” custom component.
No worries, I was hopeful we’d get there in the end
Doing what you want is something that frustrated me back when I first started with HA so this was a Holy Grail tick box when I sussed it. Must admit I haven’t tried the media player version as the original did everything I wanted but assume you should be able to achieve the same results following the same logic if you want to stick with that.
@ptdalen and @Bobby_Nobble do you have confirmation that this “out of the box” approach will work for any sensor? In my case I am trying to get Alexa to read the value of my BMW i3 battery level. The sensor is exposed via the Home Assistant cloud along with the my other devices - see below:
However when initiating discovery in the Alexa app it doesn’t seem to find the new sensor resulting in Alexa being unaware of it entirely. It seems to me that Alexa can read the value of specific sensors that can be controlled and have a value (e.g. thermostat), but not other generic or read-only sensors. At this point it seems to me that the only way to achieve that is by following the approach outlined here:
If indeed there is an “out of the box” solution that I am missing I’d appreciate your help.
At this moment it supports binary sensors (Amazon refers to them as sensors) and temperature sensors.
Of course, everything is possible with a custom skill (not using the Smart Home Skill API), but this is much more effort.
I do not understand, why Amazon is supporting Cooking Appliances, but not Covers (covers can be faked as dimmable lights though). Cooking Appliances would be much much further down the list for me
@hsepm thanks for the reply. Based on this I’ll go the custom skills route. I suppose the cooking thing may be prioritized by Amazon because its a way of appealing to and bringing in the broader non-enthusiast market?!
Maybe they want to sell some Alexa-enabled microwaves, but I don’t get the point. After all you have to physically interact with the device to put food in and out, whereas that would not be required when adjusting a cover or to check on the humidity in a room
The only use case for an Alexa-enabled microwave I can see is for visually impaired people.
If you read my solution you’ll see I’m just getting Alexa to read out the value of a sensor as it is seen in Home Assistant using TTS which is no different than getting her to read any other piece of text and will therefore work for absolutely anything Home Assistant can see, I’m not getting Alexa to see anything as a sensor or otherwise.
So this is what I am doing.
First I have the Alexa TTS script working. It’s pretty straight forward to set up, but still takes a bit of work. The cookie seems to be the hardest part for most.
Once you get this working, I then created a dummy light as recommended by @lonebaggie
His way of doing it used app daemon, but I’m not using app daemon. The dummy light is still used though
I have several echo devices, and I want alexa to answer me on the echo that I asked the question on so I created a sensor and a switch using the alexa TTS script. So…
This is my sensor
- platform: command_line
name: Last Used Echo
command: "/home/homeassistant/.homeassistant/alexa_remote_control.sh -lastalexa"
entity_id: switch.last_echo_used
This is my switch
switch:
- platform: command_line
switches:
last_echo_used:
command_on: "/home/homeassistant/.homeassistant/alexa_remote_control.sh -lastalexa"
command_off: ""
Last step is to go into the alexa app and create routines. If you look at my automation below you will see that I have routines set up for each dimmer level of the dummy bulb. So my routine basically says something like
"Alexa, where is Paul. " This sets my dummy bulb to 2%, which kicks of the appropiate response. This might be overkill for you, if you only have one sensor you want to expose, you could just create an input_boolean and turn that on/off via alexa and have that kick off the routine TTS.
- alias: "Alexa Report"
trigger:
- platform: state
entity_id: light.alexa_virtual
to: 'on'
condition:
- condition: numeric_state
entity_id: sensor.ha_runtime_in_minutes
above: 1
action:
- service: homeassistant.update_entity
data:
entity_id: sensor.last_used_echo
- service_template: "notify.{{ states('sensor.last_used_echo') }}"
data_template:
message: >-
{% if (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 1 and states('device_tracker.tracy_all') == 'not_home' %}
Tracy is away and is approximately {{ states('sensor.tracys_time_to_home') }} minutes from home.
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 1 and states('device_tracker.tracy_all') != 'home' %}
Tracy is at {{ states('device_tracker.tracy_all') }} and is approximately {{ states('sensor.tracys_time_to_home') }} minutes from home.
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 1 and states('device_tracker.tracy_all') == 'home' %}
Tracy is at home.
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 2 and states('device_tracker.paul_all') == 'not_home' %}
Paul is away and is approximately {{ states('sensor.pauls_time_to_home') }} minutes from home.
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 2 and states('device_tracker.paul_all') != 'home' %}
Paul is at {{ states('device_tracker.paul_all') }} and is approximately {{ states('sensor.paul_time_to_home') }} minutes from home.
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 2 and states('device_tracker.paul_all') == 'home' %}
Paul is at home.
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 3 %}
Here is your local surf report. The next tide is {{ states('sensor.noaa_tides') }}. The waves are currently {{ states('sensor.virgina_beach_surf_report_forecast') }} feet.
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 4 %}
At the moment, your commute to the work 2 will take {{ states('sensor.time_to_work2') }} minutes. Traffic is {{ states('sensor.pauls_traffic_density_to_base') }} at the moment.
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 5 %}
At the moment, your commute to wok 1will take {{ states('sensor.time_to_work1') }} minutes. Traffic is {{ states('sensor.pauls_traffic_density_to_caci') }} at the moment.
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 6 %}
At the moment, your commute to work will take {{ states('sensor.time_to_work_tracy') }} minutes. Traffic is {{ states('sensor.tracys_traffic_density_to_avis') }} at the moment.
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 7 %}
The Garage Door is currently {{ states('cover.garage_door_opener') }}.
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 9 %}
Based on current traffic, you have 15 minutes to leave if you want to get to work by {{ states.input_datetime.work_time_paul.attributes.hour }} {{ states.input_datetime.work_time_paul.attributes.minute }} A M . Traffic is {{ states('sensor.pauls_traffic_density_to_work') }} today.
{% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 10 %}
{{ as_timestamp(now())|timestamp_custom ('%-I %M') }} and then {{ as_timestamp(now())|timestamp_custom ('%H %M') }} and one more {{ as_timestamp(now())|timestamp_custom ('%I %M') }} and lastly {{ as_timestamp (now()) | timestamp_custom('%-I %-M %p') }}
{% else %}
{{ states('light.alexa_virtual.attributes.brightness') }}
{% endif %}
@Bobby_Nobble thank you for the reply. I think the challenge is that the solution(s) are buried and intertwined in long threads - so I missed the crux of how it works.
@ptdalen great summary - this helped me a lot, and your approach is not overkill for me as I will be exposing a bunch other stuff too - that script is super helpful.
I got the tts working finally - it looked like I was able to sort our the cookie issue with Chrome, but there was no audio when issuing the command to Alexa. Performing the same steps with FireFox worked (could ave something to do with it being a clean install?).
You seem to really know what is going on and have achieved what i am trying to achieve.My hat is off to you sir! I have read thru so many different ways to do something that should be so simple that my head hurts, and have accomplished nothing but a headache, lol. My problem is i am not a coder by any since of the word and wind up getting lost, and all the different ways run together. Could you PLEASE PLEASE PLEASE put together a step by step of how you accomplished what seems unachievable to me. I would be willing to pay you for your time.
Alexa discovers the scripts as lights. When I toggle the light, the script plays the house temperature over the last_alexa. After seeing it, I understand how the emulated_hue is seen as a light.
In your example, you don’t use emulated_hue but the alexa_virtual template
which appears to have the same brightness feature as an emulated_hue bulb. When I run discovery on Alexa app, all that shows up are the scripts as light devices. It does not see the alexa_virtual light.
That said, I can get a script to run by setting up an Alexa routine in the app which turns on the script directly. In your example you show a sensor and a switch (in configuration.yaml?) and an automation. I don’t understand how the automation gets run if the alexa app doesn’t seem to see the virtual light which is set up like yours after discover devices.
So at the moment, I have an automation called ‘virtual’ that has your automation in it with some changes but I don’t know how to get alexa to see it and set a brightness level.
BTW: if I tell Alexa to set the script to 50% bright, the script ‘light’ goes to 10% in the Alexa app. Does this behavior seem odd?
Sorry this is so long and hits on several questions, but I’m flapping about here for a while without much progress. Any hints to get me off the ground on this?
Thanks
@ptdalen Thanks. The math in @lonebaggie s solution and the one you point out is clear. I was seeing the odd numbers before I tried that automation/script. Yes that part all works fine now but it is limited to returning a TTS action. Thanks to both of you.
Then expose the light.alexa_virtual with emulated hue, then discover it with alexa, then set the levels on the light.alexa_virtual, and have the levels of that light trigger scripts, automations, etc using alexa routines.
While you can expose the scripts, I dont think you can set a level on them. I have a couple scripts that I use, and just turn them on.