Google Assistant working with sensors?

I am sharing all my sensors, such as Xiaomi, Aqara, Netatmo. I do the same way as any other devices - through the configuration.
However they all indeed concidered as thermostats and always reported as off in addition to the actual temperature.

Hi Could you help me, what configuration are you using and is it still working?

Mine look like this (No fake heaters, and sofar I can’t see any temperature devices on Google assistant without the fake heaters?)

***************************************
 customize:
    # Add an entry for each entity that you want to overwrite.
    sensor.havetemperatur:
      device_class: temperature
      friendly_name: Havetemperatur 
    sensor.garagetemperatur:
      device_class: temperature
      friendly_name: Garagetemperatur 
      
***************************************
My two sensors: 
 sensor.havetemperatur
 sensor.garagetemperatur
  
***************************************
 
 # Google assistant
 google_assistant:
   project_id: !secret gass_projectid
   api_key: !secret apikey
   exposed_domains:
     - sensor
     - script
     - switch
     - light
     - climate
     - cover
 #   - media_player
 #   - scene    
 #   - group
 #   - fan
   expose_by_default: true
   entity_config:    
         sensor.havetemperatur:
           name: Havetemperatur
           room: Haven
           expose: true
           aliases:
             - Temperatur i haven
         sensor.garagetemperatur:
           name: Garagetemperatur
           room: Garagen
           expose: true
           aliases:
            - Temperatur i garagen


*****************************************

# Udendørstemperatur sensor
  - platform: mqtt
    state_topic: 'tele/Sonoff_TH16_1/SENSOR'
    name: 'Havetemperatur'
    unit_of_measurement: '°C'
    value_template: '{{ value_json["DS18B20"]["Temperature"] }}'
    
# Garagetemperatur sensor
  - platform: mqtt
    state_topic: 'tele/Sonoff_TH16_2/SENSOR'
    name: 'Garagetemperatur'
    unit_of_measurement: '°C'
    value_template: '{{ value_json["DS18B20"]["Temperature"] }}'

I have added the “device_class: temperature” and told Google assistant to synch devices :slight_smile:

1 Like

I can get all the premade sensors, like Hue, Xiaomi, Netatmo, to be accessible in Google Home. It just seems, even though they show as sensors, the ones created by ESPHome using home made sensors based around ESP8266 or ESP32 chips don’t show.
I’ll have to try a couple of other manual work arounds.

The indent is 6 spaces you are showing and it should be 2 so move them all 4 spaces left.

1 Like

Hi David

Thanks for helping out (Sorry sloppy cut and paste) the indents are okay.

I found that it needed the “Fake Climate” controllers and I also needed to add some more information to get it working

# https://www.home-assistant.io/integrations/generic_thermostat/

climate:
  - platform: generic_thermostat
    name: Temperatur i haven
    heater: input_boolean.fake_heater1
    target_sensor: sensor.havetemperatur
    min_temp: 15
    max_temp: 21
    ac_mode: false
    keep_alive:
      minutes: 3
    initial_hvac_mode: "off"
    target_temp: 21

  - platform: generic_thermostat
    name: Temperatur i garagen
    heater: input_boolean.fake_heater2
    target_sensor: sensor.garagetemperatur
    min_temp: 15
    max_temp: 21
    ac_mode: false  
    keep_alive:
      minutes: 3
    initial_hvac_mode: "off"
    target_temp: 21

Now I get Temperature icons on my Google assistant and it works
(Still with the Temperature is and its Off" but I can live with that)

Nowadays I’d suggest a different approach to avoid Assistant telling me the additional information about target temperature and/or thermostat state.

Example definition:

climate:
  - platform: mqtt
    name: living_room_hvac
    qos: 1
    initial: 20
    availability_topic: "ha/my-sensor/online"
    payload_available: "true"
    payload_not_available: "false"
    current_temperature_topic: "ha/my-sensor/sensor/temperature"
    temperature_state_topic: "ha/my-sensor/sensor/temperature"
    temperature_command_topic: "void/hvac/temperature/set"
    mode_state_topic: "void/hvac/mode/state"
    mode_command_topic: "void/hvac/mode/set"
    modes:
      - "off"
      - "cool"
      - "heat"

Topics beginning with ha/ are real data, topics starting with void/ are either faked or not used at all.

Make sure to assign the same value to current_temperature_topic and temperature_state_topic.

Set mode_state_topic to heat - either by using retain or an automation that sends heat to this topic at home assistant’s start (I’m doing the latter).

If possible use availability_topic so you know that your sensor’s data is recent and not the last value before your sensor stopped working…

If you sensor can’t use MQTT directly you can forward the sensor’s value to a MQTT topic using an automation.

Now Google Assistant just replies with the current temperature and nothing else :slight_smile:

3 Likes

Hello! For me when mode is off assistant says “Temperature in room is xxx, device temperature is off”, when heat or cool it only says “Temperature in room in xxx mode”

Do you have any updates?

Based on my own experience Google Assistant only responds with the temperature value when in heat mode (hence my remark to set mode_state_topic to heat).

I’m not sure if this is because of its current implementation in Home Assistant or if Google Assistant decide this on its own and HA can’t do nothing about it…

I’m trying to setup my xiaomi temp sensor (zigbee2mqtt) witch your instruction but no luck. Can you help me and tell me how do that?

I don’t use zigbee2mqtt but based on the information I found online I’m assuming you need to add current_temperature_template: "{{ value_json.temperature | round(1) }}" and temperature_state_template: "{{ value_json.temperature | round(1) }}" to your definition since the temperature information is encapsulated as an attribute inside a json object.

2 Likes

it says “device in cooling mode” or “device in heating mode” always to me… can you show values of all your topics?

sure, below are the current values. none of them are retained though.

availability_topic: "ha/my-sensor/online" --> true
current_temperature_topic: "ha/my-sensor/sensor/temperature" --> 20.68
temperature_state_topic: "ha/my-sensor/sensor/temperature" --> 20.68
temperature_command_topic: "void/hvac/temperature/set"
mode_state_topic: "void/hvac/mode/state" --> heat
mode_command_topic: "void/hvac/mode/set"

thanks! works now after switching mode from heat to cool and back to heat. no idea what was the problem actually, but works for now :))

It seems that sensors are now officially supported by Google Assistant: https://developers.google.com/assistant/smarthome/guides/sensor

However, I do not know whether Home Assistant already passes them on as sensors. In my case the temperature sensors are still recognized as switched off thermostats.

1 Like

It seems that this trait…:
https://developers.google.com/assistant/smarthome/traits/sensorstate#device-states

must be integrated in the trait.py code of the google_assistant HA integration first:

I have looked at it, but unfortunately I am a little too stupid for it. I think and hope that an experienced HA developer will take care of it soon :slight_smile:

1 Like

I just created a feature request about this. Feel free to upvote here

2 Likes

Any news on this update to google integration to expose sensors?

4 Likes

I’ve got xiami temperature working with the following automation:

Trigger
entity_id: sensor.lumi_lumi_weather_temperature
platform: state

Action
data:
  payload_template: '{{ states("sensor.lumi_lumi_weather_temperature") }}'
  topic: ac/temperature/current
service: mqtt.publish

and MQTT listen topic:

 current_temperature_topic: "ac/temperature/current"
 temperature_state_topic: "ac/temperature/current"

Note: no current_temperature_template or temperature_state_template are needed.

Thanks @Florian for the initial setup guide.

For anyone that came here because they want to expose a non-thermostat type of sensor (humidity, pressure, carbon monoxide, etc), I came up with a different approach as I was unable to get this to work for my Radon detector (my wife wanted to be able to ask google what the current radon levels are, and I have this as a sensor device type in HA).

This method uses a HA script that when triggered, uses the TTS service to play back a response containing the value or reading from your sensor, on one or all of your google home speakers. Here are the steps I took:

Prerequisites:

  • One or more Google home speakers to answer your sensor queries,
  • TTS services configured, more on this here
  1. Create a new script with the following contents (adjust as needed for your info)
read_radon_level:
  alias: Radon level
  sequence:
  - service: tts.google_say
    data:
      entity_id: media_player.full_house
      message: "The radon level is {{states('sensor.radon_latest')}}."
      cache: false
  1. Expose the new script to google, it will get shared automatically if you have the “script” domain enabled, and it will show up in GA as a “scene” which means you can trigger it by saying either “OK Google, activate {scene name}” or “turn on {scene name}”.
  2. Sync your entities to Google
  3. (optional) create a Routine if you want an alias. For my example above, I made a routine that on the keyword “What is the radon level”, it maps to the google command “Activate radon level”

Hope this helps someone. Cheers! :beers:

8 Likes

Wow, this is great! I was looking for a way to ask Google the value of a random template sensor, and while this is a bit cumbersome to use for every sensor I’ve got or anything, it should work well for a few here or there :+1:

1 Like