How to get temp and humidity from air purifier

Hello,
I can’t find how to get temperature and humidity from air purifier.
My air purifier is configured (I can turn it on and off and nothing else)

I have Xiaomi air purifier 2. (model: zhimi.airpurifier.m2)

Please help me. I can’t find any example configurations :frowning:

Telling us your air purifier make and model would help. So would the code you are currently using to control it.

Yep, my crystal ball is on the blink again…

Check the states ‘<> button in the dev tools’ and see which attributes show up for the air purifier in the right column.

To extract the temperature I’d use the template:

“{{ states.sensor.plug_bedroomheater_power.attributes.temperature }}”

1 Like

Sorry :slight_smile:

I have Xiaomi air purifier 2. (model: zhimi.airpurifier.m2)

Can You paste me sample configuration of sensor?

Now I get the error:

Invalid config for [sensor.template]: expected a dictionary for dictionary value @ data[‘sensors’]. Got None. (See ?, line ?)

My config:
sensor:

  • platform: template
    sensors:
    syp_temp:
    friendly_name: temperatura B
    value_template: ‘{{ state.fan.syp.attributes.temperature }}’
    unit_of_measurement: “°C”

Please format your code properly, see the top of the page.

My config:

sensor:
  - platform: template
    sensors:
    syp_temp:
      friendly_name: temp B
      value_template: '{{ state.fan.syp.attributes.temperature }}'
      unit_of_measurement: "°C"

fan:
  - platform: xiaomi_miio
    name: syp
    host: 192.168.1.25
    token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    model: zhimi.airpurifier.m2

The error I get is:

Invalid config for [sensor.template]: 
expected a dictionary for dictionary value @ data['sensors']. Got None. (See ?, line ?).

Please help! :slight_smile:

1 Like

Try states (instead of state)

1 Like

According to the docs you need to double quote the friendly name, and double (not single) quote the template. See

Also your indentation is off, the lines below sensors: need to be indented, see the same docs.

Actually you can use single or double quotes for templates (Rule 3): Automation trigger variables - Home Assistant

Thanks, I must admit I was just looking at the examples…

I think my indentation point is correct though.

It probably depends who writes the examples and their preferred style. I guess double quotes is safer - in case you have single quotes inside.

is_state or states… there is no “state”

1 Like

To elucidate @Dixey’s point, this is what you should have:

value_template: ‘{{ states.fan.syp.attributes.temperature }}’

1 Like

I was getting ready to post a snippet from my sensors.yaml to show an example and I noticed I also had sometimes used single quotes and sometimes double… depending on my mood I guess. :slight_smile:
My lack of coding discipline is showing… I better tuck it in.

2 Likes

There were two mistakes:

  1. state --> states
  2. indentation

Thank You very much :slight_smile:

1 Like