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

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. :grinning::grin::wink:

I have a script that will run based on an emulated hue light where I expose the script like this:

   emulated_hue:
      type: alexa
      expose_by_default: true
      exposed_domains:
        - script
      entities:
        light.ha2:
          name: "ha2"

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

I use dummy bulbs like you use the scripts .

I have to convert from 0 -100 (alexa) to 0-255 (HA) that why you maybe getting odd results , however I cannot emulate your results

Iā€™m not using appdaemon, but the yaml automation has worked great for me.

if (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round == 1ā€¦
This should help with the math.

My alexa routines set values of 1 to 100 (I actually only have 10 right now, so 1-10), and have not had any issues at all

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

Ahh, I think I misunderstood. Are you setting a ā€œscriptā€ to a percentage? Do you have a dummy bulb set up and exposed to alexa using emulated hue?

like this one

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

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.

I do have the virtual light set up and working fine. So Iā€™m all set there. I do just turn scripts on and off.
Thanks

Iā€™ve found that using an input_number helper and an automation to synchronize a sensor value to that input_number is a functional method. You can expose the input_number entity to Alexa and ask for the value.

Alexa, what is the value of <sensor name>?

2 Likes