Asking google assistant the state of a switch

Hi,
I am new to home assistant / esphome / nabu casa, so please be genteel. I created a small garage door interface using ESPhome. The hardware is Wemos D1 Mini, a Relay shield, a DHT22, and a switch. Here is the code:

substitutions:
  device_name: esp_garage
  update_interval: 30s

esphome:
  name: ${device_name}
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "XXXXXXXXX"
  password: "XXXXXXXX"

  ap:
    ssid: "ESP Garage"
    password: "XXXXXXXXXXX"

status_led:
  pin:
    number: D4
    inverted: yes
    
web_server:
  port: 80

sensor:
  - platform: dht
    pin: D2
    temperature:
      filters:
      - lambda: return x * (9.0/5.0) + 32.0;
      unit_of_measurement: "°F"
      name: "Garage Temperature"
    humidity:
      name: "Garage Humidity"
    update_interval: ${update_interval}
    model: DHT22
  - platform: wifi_signal
    name: "Garage WiFi Signal"
    update_interval: 60s
  - platform: uptime
    name: "Uptime"

binary_sensor:
  - platform: gpio
    name: "Garage Door Switch"
    pin:
      number: D3
      inverted: True

switch:
  - platform: gpio
    pin: D1
    id: switch_relay
  - platform: template
    name: "Garage Door"
    icon: "mdi:garage"
    turn_on_action:
      - switch.turn_off: switch_relay
      - switch.turn_on: switch_relay
      - delay: 1s
      - switch.turn_off: switch_relay

captive_portal:

logger:

api:

ota:

And in the Home Assistant page it looks like this:

image

It works well from the page interface and even from the device itself since I set a page accessible from the lan using the IP.

I signed up for Nabu casa and I set up two google home routines that basically do the same thing but are triggered by either “Open garage door” or “Close garage door” and I hear the corresponding answers. That parts works well. In the google home app I see the switch, but the other sensors are not present (temperature, humidity, and the switch state). The switch tells me if the garage door is open or close.

I would like to be able to ask the google assistant: “Hey google, is the garage door open (or close)?” and I would like to hear something like: “Yes (or no), the garage door is open” or “No (or yes), the garage door is closed” based on the state of the switch. A bonus would be getting the garage temperature and humidity, but not as important as the switch. Is this doable? If so, can you please explain how to me like i’m 5. My setup is extremely vanilla. I just started on this about 5 days ago.

Well, I was able to solve the issue. I was missing device_class: garage_door. I updated the binary sensor section of the code as follows:

binary_sensor:
  - platform: gpio
    name: "Garage Door"
    device_class: garage_door
    id: garage_switch
    pin:
      number: D3
      inverted: True

I renamed the switch to “Garage Door Button” also so I can just ask google: Hey google, is the garage door open? and if the switch is closed or open it answers accordingly.

1 Like

Very impressive configuration for a ‘noob’. Well done!

Thank you! This is how the hardware looks. I mounted everything on one of those Adafruit breadboard/pcb and kept it modular in case I want or need to do any upgrades later on:

I have been testing it for a while and I will be installing it this weekend. I figured out how to get the temperature, but not yet the humidity.I created a generic thermostat and I am using the ESPhome sensor as input to this thermostat. I also added the same features to Alexa. I am very happy with the results. I am thinking about what to automate next.