Tts.google_say to which window has ben opened

Hi Team

Can you please give me a hint…

Goal is to have HA to announce which window has been opened.
With the below automation (without ‘states’ stuff in the message) I can when ‘opening’ a window, to get my sonos to announce that a window has been opened. So fare so good.

But next step. The goal is to get all my windows listed as triggers, and to have the text to contain the windows that is being opened. I do believe it should be possible to ‘grab’ the ‘friendly_name’ from ‘something’ when the automation is being kick off.

But I’m stuck…
How to get the ‘friendly_name’ of the ‘binary_sensor’. I have tried a lot of things…
please come with a hint.

This is my very advanced automation ;-)) :

  • alias: Test Automation 2
    trigger:
    • entity_id: binary_sensor.neo_coolcam_door_window_detector_sensor
      from: ‘off’
      platform: state
      to: ‘on’
      condition: []
      action:
    • data_template:
      entity_id: media_player.kitchen
      message: " {{ states(’???’) }} has been opened"
      service: tts.google_say

Regards Jørn

try something like

- alias: 'test automation'
  initial_state: true
  trigger:
    - platform: state
      entity_id:
        - binary_sensor.conservatory_skylight_left
        - binary_sensor.conservatory_single_door
        - binary_sensor.conservatory_double_door
        - binary_sensor.living_room_right_big_window
        - binary_sensor.living_room_right_small_window
        - binary_sensor.master_bedroom_right_window
        - binary_sensor.master_bedroom_left_window
        - binary_sensor.cloakroom_window
        - binary_sensor.bathroom_window
        - binary_sensor.kiaan_big_window
        - binary_sensor.kiaan_small_window
        - binary_sensor.blue_room_big_window
        - binary_sensor.blue_room_small_window
        - binary_sensor.main_door
        - binary_sensor.kitchen_window
      to: 'on'
  action:
    - service: tts.google_say
      entity_id: media_player.kitchen
      data_template:
        message: '{{trigger.to_state.attributes.friendly_name}} has been opened'
1 Like

Thanks… that does the trick…

I then played with mqtt…

  • data:
    payload: ‘{{trigger.to_state.attributes.friendly_name}} has been opened’
    topic: Test
    service: mqtt.publish

this does not resolve to the name as the message does.
How come ?

/Joern.

try and use that blue bar on top of the page to format your code.
You need to use data_template instead of data if you’re not sending plain text but want to use templated data.

:slight_smile: Missed that one.
Thanks, is working.
/Joern

1 Like

Next step is to lower the volume on the ‘media_player’ (which is a Sonos speaker).
I have googled and tried a few things, but without success.

So, I would love to get that solved…
but even more. Where do I find information about how to do this ? I do believe I have read most of the ‘manuels/instructions’ I can find, about HA data models, object models, not much, and it didn’t enlighten me… It could be that i’m the problem ;-)…

But where do I find the instructions, so I would be able to read/understand, that would teach me ‘how to handle the objects’ - like turning down the volume…

Hope some can point me in a direction.

Thanks.
And thanks to all the help full spirits in here…

This is the code that I have tried with, in order to set the volume:

- alias: Test Automation 2
  trigger:
  - platform: state
    entity_id: 
      - binary_sensor.neo_coolcam_door_window_detector_sensor
      - binary_sensor.neo_coolcam_doorwindow_detector_sensor
      - binary_sensor.aeotec_zw120_door_window_sensor_gen5_sensor
      - binary_sensor.neo_coolcam_window4_detector_sensor
      - binary_sensor.neo_coolcam_window5_detector_sensor
    to: 'on'
  condition: []
  action:
  - data_template:
      entity_id: media_player.kitchen
      #volume_level: '{{states.media_player.kitchen.attributes.volume_level = 0.2}}'
      #volume_level: 0.1
      message: '{{trigger.to_state.attributes.friendly_name}} window has been opened'
    service: tts.google_say

Thanks

/Joern