Google Assistant working with sensors?

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

What kind of sorcery is this?
I would love that view, of exposed entities, in Google home.
Could not find anything under integration?

It’s in the cloud settings section of configuration.

Configuration>Home Assistant Cloud>Manage Entities (under Google Assistant)

1 Like

Yes that is a great view and gui to expose items I wish I could use it, but if you are using the non Nabu solution, (i.e. self hosing and not paying, the I think reasonable amount) I believe you are stuck manually editing the config yaml instead.

1 Like