Google Assistant Door and Window Status

I’ve found a way to integrate my door and window sensors so that I can query the status of a sensor with Google Assistant.

You can create a template cover for each door and window sensor, then export the covers to Google Assistant.

In your configuration.yaml file:

Create cover templates:

cover:
  - platform: template
    covers:
      kitchen_window:
        device_class: window
        friendly_name: "Kitchen Window"
        value_template: "{{ is_state('binary_sensor.kitchen_window_sensor', 'on') }}"
        open_cover:
        close_cover:
      front_door:
        device_class: door
        friendly_name: "Front Door"
        value_template: "{{ is_state('binary_sensor.front_door_sensor', 'on') }}"
        open_cover:
        close_cover:

Make sure that cover is exposed, or expose your individual door and window cover templates

google_assistant:
  # your other google assistant yaml code here
  exposed_domains:
    # your other domains here
    - cover

Then restart Home Assistant to get your templates and google assistant exposed domains loaded, then re-sync Google Assistant (“OK Google, re-sync my devices”).

Make sure you have the new devices in Google home and move them to appropriate rooms. Windows look like blinds, and doors look like… boxes with a lens on them (maybe garage door opener like MyQ Garage)

Once done, you can ask google “OK Google, is the kitchen window open?” and it will tell you if the window is open or closed, or “OK Google, are any windows open?” to give you the status of multiple windows, etc.

This can be used in routines, such as your bedtime routine including the command “are any windows open?” etc.

5 Likes

This indeed works great (as a workaround).
However, I would like to create a single template cover from 2 (or more) window sensors. So, if one of the windows are open, template cover indicates it is open. Otherwise, closed. Can you please help me to achieve this in the value_template code?
The main reason for combining is to avoid asking google assistant the status of each window individually.

Here’s a cover template that will check all of your sensors of window class and return open if ANY window is open or closed if ALL windows are closed.

It’s kind of a kludge, its really from a script I have that will announce the list of open windows with tts.google_translate_say, just removing the list if any window is open.

“Hey Google, are all windows closed?”

Also includes a similar template for doors.

cover:
  - platform: template
    covers:
      all_windows:
        device_class: window
        friendly_name: "All windows"
        value_template: >-
          {%- set windows = states.binary_sensor|
          selectattr('attributes.device_class','eq','window') |
          selectattr('state','eq','on') | map(attribute='name') | list %}
          {% if windows | length == 0 %}
            False
          {%- else %}
            True
          {%- endif %}        
        open_cover:
        close_cover:
      all_doors:
        device_class: door
        friendly_name: "All doors"
        value_template: >-
          {%- set doors = states.binary_sensor|
          selectattr('attributes.device_class','eq','door') |
          selectattr('state','eq','on') | map(attribute='name') | list %}
          {% if doors | length == 0 %}
            False
          {%- else %}
            True
          {%- endif %}        
        open_cover:
        close_cover:

Here’s the script it was adapted from, but it doesn’t use “inline” Google Assistant responses, it announces on tts.google_translate_say.

“Hey Google, Activate check windows”
(or add a routine that triggers the “Check windows” script, such as “Check the Windows” trigger phrase)

check_windows:
  alias: Check Windows
  mode: single
  sequence:
  - data_template:
      entity_id: media_player.home_group
      message: "{%- set windows = states.binary_sensor| selectattr('attributes.device_class','eq','window')\
        \ | selectattr('state','eq','on') | map(attribute='name') | list %} {% if\
        \ windows | length == 0 %} All windows are closed. {%- elif windows | length\
        \ == 1 %} {{ windows[0] }} is open. {%- else %} {{ windows[:-1] | join(',\
        \ ') }}{{',' if windows | length > 2 else ''}} and {{ windows[-1]}} are open.\
        \ {%- endif %}  \n"
    service: tts.google_translate_say

The underlying code is not mine, it’s from the community forums but I can’t recall the thread its from.

Thanks.

Where in the code can I include the list of applicable binary sensors? In my case I have 3 binary sensors to be checked, e.g. 1 sensor named as binary_sensor.shenzhen_neo_electronics_co_ltd_door_window_detector_sensor

You can make a cover group with your covers and ask for the group

The above solution will use all sensors of device class “window” automatically.
You can go into Configuration, then Customizations and check the “Device class” for your sensors.

Thank you. It works like a charm.

Curious if you all might be able to help guide me in the right direction. I have a GPS Tracker for my cat – it populates into home assistant via their Whistle integration. This creates a “device_tracker” entity with a bunch of Attributes attached. One of these attributes is “Battery Level”

I was able to create a Template Sensor using the following code:

-template:
  - sensor:
      - name: "Moe's Battery"
        unit_of_measurement: "%"
        state: "{{ state_attr('device_tracker.whistle_moe', 'battery_level') }}"

I want to figure out how to then be able to ask google “What is Moe’s battery level” but I can’t figure out how to expose this entity to Google Assistant. Do I need to use a “cover?”