Anyway to expose a sensor value to Alexa/Echo/Google

Was just thinking it might be neat to expose some sensor values to alexa. Tons of possibilities of what you could ask.

Simple examples, with google traffic/waze travel sensors

You could ask "Alexa, whats the value of “Sensor name”
Or temp of a open close, or motion sensor.

i dont think you can do that now, but thought maybe if you created a template and set the device type as a thermostat type device? I know I can ask alexa what the temp is in a room based on ecobee temp sensors.

Anyway, just wondering if anyone has done anything like that, and if so, what kinds of values have you been able to “report”, binary? Number? Text?

Thanks

1 Like

My Temp Sensors are working via Alexa. I added them to my cloud config under included entities. For transparency, they only showed up recently. Perhaps after Amazon added the new sensor stuff, or maybe some other reason. But now I can ask Alexa, what’s the back porch temperature, and she reads if off.

I’ll try the travel sensors and se if it works as well.

1 Like

I was thinking you could make a fake temp sensor that used the value template from another sensor.

Other than it saying degrees at the end of the report, I think it would work based on your results.

I only have ecobee sensors expsoed, but i use the native alexa app for those, so thanks for your testing.

You can get it to read anything you like using either…

or

I use the first option to get her to read say all sorts of things.

I extensively use the Echo Devices (alexa), to say plenty of things. But, what I’m saying is I want to ask Alexa what the value of a Sensor is. For example the Google Maps sensor. it’s not quite the same.

I guess I could create another sensor, like a boolean, and say alexa turn on “Work Commute”, which could trigger an automation, to tell me what I want. Of course I could do that with any TTS enabled speaker.

What I’m really asking is what types of sensors/devices have people exposed to Alexa and been able to get the values. It sounds like Temp Senors work,

And that’s exactly what I gave you in my answer, there’s an example of one I use in the thread if you read it.

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 :-).

edit: did you saw this?

2 Likes

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.

1 Like

Don’t know why I’m persevering but hopefully third time lucky.

If you actually read the link you’d see you can do EXACTLY what you want to do, this is my specific post I was referring too…

it’s triggered by “Alexa, what is the lounge temperature?” just like you want.

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 :slight_smile:

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.

Currently, the Amazon Smart Home Skill API is quite limited.

[https://developer.amazon.com/de/docs/smarthome/understand-the-smart-home-skill-api.html#what-kinds-of-devices-are-supported](Amazon Reference)

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 :wink:

@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 :wink:

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.

BTW - here is the custom skill intents

so I can ask

Alexa, tell me the status of the front door
Alexa, tell me everything that is on

1 Like

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

- platform: template
    lights:
      alexa_virtual:
        friendly_name: "Alexa Dummy Light"
        turn_on:
        turn_off:
        set_level:

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 %}
5 Likes

I have written a Parser to expose sensor values to Alexa/ Google

1 Like

@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?).

@RobDYI thanks for posting your intent script.

@lonebaggie thanks for the parser script. I’ll take a look at it soon, but I’m sure it will come in handy.

Its awesome to be part of such a capable and helpful community.

1 Like