Adding more information to a list for speaking it

Just for my curiosity (I use Google Homes instead) How do you ask Alexa to run the script here? Do you literally just say ‘alexa Offen Fenster’?

crazy, you wrote the whole thing for me!

i made the alias like this:

alias: Fensterstatus

You can say “Alexa turn on Alexa Offen Fenster” or you can set up a routine and assign trigger phrases such as “Alexa, which windows are open” or “Alexa, how long have the windows been open”. I think your allowed up to 7 voice triggers per routine.

I’ve got a well developed ctrl-C / ctrl-V muscle… :slight_smile:

1 Like

Thanks. Very similar to google. Although I refuse to use their routines because others in the house cant as routines are voice match specific per the person. Very annoying permissioning issue. I end up creating a boolean for each and say ‘turn on boolean’ (which triggers the script by the same name. There’s an automation for that… and also assign a few aliases. Wish it were better.

I now set up the script, made the Alexa routine which “switches on” the scene and my blind wife can just say “Alexa Fenster” and she gets the windows status.

Thankyou guys for your help!

These days i will try to implement a similar thing for the washing machine and dryer. We also mounted door sensors there, they automatically open after the machines end. And i want to have a status command too.

And i need to have the 3rd window sensor also in my group. I need to find out how to define a group in yaml i think. (Or i buy another sensor)

1 Like

They are simple for old style ones… I’m sure they’ll phase these out at some point though but the news ones can’t do everything the old style ones can… Just add them to the yaml and reload it.

group:
  upstairs_presense:
    name: Upstairs Presense
    entities:
      - binary_sensor.upstairs_motion
      - binary_sensor.master_motion
      - binary_sensor.loft_motion
      - binary_sensor.cory_room_motion
      - binary_sensor.raleigh_room_motion
      - binary_sensor.emerson_room_motion
      - binary_sensor.master_bathroom_motion

I would try to address this at some point as well.

The quick and dirty way to get the other entity into your template without setting up a group is to add it into the expand(). So the second line of your template would be:


{%- for entity_id in expand('switch.fenster', 'binary_sensor.YOUR_SENSOR_HERE')|selectattr('state','eq','on')|map(attribute='entity_id')|list %}
1 Like

and one question more:

is it possible to make an announcement to Alexa, so it will say something on every device? Or at least on more than one?

For that you need to alter the service call…

For all Alexas you can use the auto-generated Everywhere group. If you have other speaker groups defined in the Alexa app you can use them as well. Be aware that you must use type: announce for any Alexa-defined speaker group including the Everywhere group:

alias: Alexa Offen Fenster
sequence:
  - service: notify.alexa_media_everywhere
    data:
      data:
        type: announce
      message: '{{fenster}}'

For a list of specific Alexas use the plain notify.alexa_media service. Then list the Alexas under the target: key. When doing it this way you can use either tts or announce as your type depending on whether you want the notification “bong” sound before the spoken message.

alias: Alexa Offen Fenster
sequence:
  - service: notify.alexa_media
    data:
      target:
        - media_player.kuche
        - media_player.schlafzimmer
      data:
        type: tts
      message: '{{fenster}}'

status_announcement. Unable to find service notify.alexa_media_everywhere

made a 2nd script… altered the lines, but it wont work…

Go to the Developer Tools > Services and type in “notify.alexa_media_”. It should show you all the available Alexa-based media player services.

Maybe it’s not in English…? Maybe it isn’t created automatically in the EU…?

PERFECT!

i was searching around where to find that name, in entities and everywhere, but not in developer tools services…

it is called:

alexa_media_uberall_2

for german Überall = everywhere…
i think its created on how you name it in Alexa… and why the 2? i dont know.

And its even a bit harder, because i am swiss, and not EU, and the Alexa is working but i only can buy the german version, but they dont have the full potential when used here… Its a crazy world…

Here it is almost eleven PM. i will get my coffee (of which i drink 2 a month only) and rest.

thankyou so much for your help!

1 Like

Hi all,

im very new to Hassio - im coming from openhab and found out that many things are more eady in hassio than in openhabe - so actually im in the migration phase…

In OpenHab I had a script with amazon echo binding - that i can ask alex “are there any open windows” and alexa/openhab checkt the states of all windows in a group and alexa answere “yes the kitchen window is open” or “no window is open”…

This i want also in hassio - i installed the Alexa Media Player and also checked the " Live Sensor Reports" discription on github but i dont understand it. The virtual switch Dummy is created but now i need help - how to find out which window is open and responed that via alexa.

I think i need a combination of this:

- alias: "Alexa Report"
  trigger:
  - platform: state
    entity_id: light.alexa_virtual
    to: 'on'
  condition:
  action:
  - service: alexa_media.update_last_called
  - delay: 2
  - variables:
      messages:
        1: "What you want to say {{ states('sensor.name_of_sensor') }} Degrees"
        2: "What you want to say {{ states('sensor.name_of_sensor') }} miles"
        3: "What you want to say {{ states('sensor.name_of_sensor') }} minutes"
        4: "What you want to say {{ states('sensor.name_of_sensor') }}"
        5: "What you want to say {{ states('sensor.name_of_sensor') }}"
        6: "What you want to say {{ states('sensor.name_of_sensor') }}"
        7: "What you want to say {{ states('sensor.name_of_sensor') }}"
        9: "What you want to say {{ states('sensor.name_of_sensor') }}"
        10: "What you want to say {{ states('sensor.name_of_sensor') }}"
  - service: notify.alexa_media_last_called
    data:
      data:
        type: tts
      message: >-
       {% set brightness = state_attr('light.alexa_virtual', 'brightness') %}
       {% set id = (brightness | int(0) / 255 * 100 ) | round | string %}
       {% if id in messages %}
         {{ messages.get(id) }}
       {% else %}
         No value has been set for brightness level {{ brightness }}
       {% endif %}
  - service: light.turn_off
    entity_id: light.alexa_virtual
	
	
	
	
	
	tts_opened_windows:
  alias: Notify - Alexa - List Open Windows
  sequence:
  - service: notify.alexa_media_last_called
    data:
      data:
        type: tts
      message: '{{active_windows}}'
  variables:
    active_windows: |-
      {% set ow = expand('binary_sensor.all_window_sensors')
      | selectattr('state','eq','on')  |
      map(attribute='entity_id') | map('area_name')  
      | unique | reject('eq',None) | sort | map('lower') | list %} 
      {% set qty = ow | count %} 
      {% if qty != 0 %} 
      There {{'is an' if qty==1 else 'are'}} open window{{' ' if qty==1
      else 's '}}in the {{' and '.join((ow|join(', ')).rsplit(', ', 1)) }}.
      {% else %} 
      All windows are closed. 
      {% endif %}

Could anybody help me out :slight_smile:
Best Regards from germany

Either one of those will work, you need to decide which method you want to use. Both of these options rely on you creating routines is the Alexa app that take your trigger phrase/question and relay it into something HA can act on. For the “Dummy” bulb method, your routine changes the brightness percentage of the bulb to a specific value. For the second method you simply have the Alexa routine call the script directly. In the Alexa app’s Routine editor, HA scripts can be found under Smart Home > Scenes.

If you want to go the “Dummy” bulb method and you have already created the template light entity, all you need to do is add the template for the open windows announcement to the messages dictionary.

alias: "Alexa Report"
trigger:
  - platform: state
    entity_id: light.alexa_virtual
    to: 'on'
condition:
action:
  - variables: 
      messages:
        1: |-
          {% set ow = expand('binary_sensor.all_window_sensors') | selectattr('state','eq','on')  |
          map(attribute='entity_id') | map('area_name') | unique | reject('eq',None) | sort | map('lower') | list %} 
          {% set qty = ow | count %} 
          {% if qty != 0 %} 
            There {{'is an' if qty==1 else 'are'}} open window{{' ' if qty==1 else 's '}}in the {{' and '.join((ow|join(', ')).rsplit(', ', 1)) }}.
          {% else %} 
            All windows are closed. 
          {% endif %}
  - service: alexa_media.update_last_called
  - delay: 1
  - service: notify.alexa_media_last_called
    data:
      data:
        type: tts
      message: |-
        {% set brightness = state_attr('light.alexa_virtual', 'brightness') %}
        {% set id = (brightness | int(0) / 255 * 100 ) | int | string%}
        {% if id in messages %}
          {{ messages.get(id) }}
        {% else %}
          No value has been set for brightness level {{ brightness }}
        {% endif %}
  - delay: 1
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.alexa_virtual

For the script method you create the script in HA, tell Alexa to discover devices, then set up your Routine. With a script you can also tell Alexa to turn on the script directly. For example, if you named the script “Window Report” you could say “Alexa, turn on window report” and that would also fire the script in HA.

Hi Didgeridrew

thank you very much for your help.

Hopefully I understand what you mean - let me repeat it and ask questions about it.

So if i use the bulb config - you mean with a spezial brightness value for example 50 i trigger this and with 51 i dont need to create a new bulb for another action just let alexa routene the other value ? Where can i set the number which is corresponding to that rule ?

The rule/script you paste me i put just in the “automation” tab in HA as yaml ? or what you mean with messages dictionary ?

I need to understand it cause I have a view of these alexa rules in openhab (which was created with echo binding)

Edit: if i copy this just to the YAML under automation in HA it come "message malformed: extra keys not allowed @ data[‘0’]

Yes, each “virtual bulb” can be used for up 99 outputs, corresponding to brightness percentage values 1-99. But you need 1 Alexa routine for every brightness value/message.

Yes, it is an automation. You can add a new automation, then click the expansion menu at the top right and select “Edit in YAML” then copy/paste and save.

Make sure to change any entity ids to whatever you are using.

You set the message that corresponds to each brightness value in the messages dictionary under variables. I’ve copied it below from my earlier post. As it is, setting the brightness of the bulb to 1% will trigger the “open windows” announcement.

...
  - variables:
        messages:
          1: |-
            {% set ow = expand('binary_sensor.all_window_sensors') | selectattr('state','eq','on')  |
            map(attribute='entity_id') | map('area_name') | unique | reject('eq',None) | sort | map('lower') | list %} 
            {% set qty = ow | count %} 
            {% if qty != 0 %} 
              There {{'is an' if qty==1 else 'are'}} open window{{' ' if qty==1 else 's '}}in the {{' and '.join((ow|join(', ')).rsplit(', ', 1)) }}.
            {% else %} 
              All windows are closed. 
            {% endif %}
          2:  This is the message for 2% brightness
2 Likes

great now i understand it with the values of the brightness - perfekt thanks !

but if i copy this just to the YAML under automation in HA it come "message malformed: extra keys not allowed @ data[‘0’]

Can you clarify where you are pasting this… are you using the Automation Editor or pasting it directly into configuration.yaml or automations.yaml?

It’s likely just an indentation error, but we’ll need more details to find the cause.