Add Xiaomi Temperature and Humidity Sensor

Hey all!

I’ve runned into the same problem but restarting HA have not halped me at all.

I do connect the gateway with HA properly tho since it adds my yeelight automaticly, still don’t see the temperature sensor.

Besides doing the gateway configuration, do i need to do something else if i want the sensor to be working? Anything from the Mi Home app or something like that?

Thanks all.

Just confirming, you have enabled LAN access in the gateway and setup the Gateway component

Is there anything in the logs

Yeah sure, the gateway syncs well, even it detects my yeelight from aqara’s component, the only thing is that i can’t see my temperature and humidity sensor

Yeelights aren’t connected to the gateway. Can you see the sensor in the mi home app?

Yeah that’s right, the yeelight can work itself, but once i’ve connected the gateway, it was appearing twice, and i have removed the “light:” configuration and it is working by the gateway.

I can’t see the sensor in the mi home app neighter, but to be honest i don’t understand mi home app very well.

Thanks guys

you need to add the device to the gateway before home assistant can see it

Or if you just want the sensors and you are using hassio, you can use an addon with a cheap stick: https://github.com/danielwelch/hassio-zigbee2mqtt

As I wrote, yeelights do not connect to the gateway, and read the opening post of this topic. Solution to your “problem” is in post #2.

Oh i see! Thank you very much guys, i’ll try with the mi home app, and if i still can’t add it i’ll try to ask in aqara formus since it’s more suitable there.

Sincerely thank you all very much.

OP has the gateway, so for starters i think best get used to using the gateway then if needed move to another solution.
i am using the zigbee2mqtt also as well as the gateway to compare reliability in both. still pretty even at the moment.
Not fussed about the gateways trying calling home as they have been capped at the knees with that and are in separate network with internet access

1 Like

Completely agree, if you have the gateway start with that.

I’ve been using the gateway as well (xiaomi) but plan to get fully on zigbee2mqtt because of flexibility. I hate that I am dependent on the MiHome app for pairing and firmware updates quirks. There was a period when their (Xiaomi MiHome) app was broken on IOS for around 2 weeks.

You can start the pairing from Home assistant by calling the service xiaomi_aqara.add_device from the developers panel. just need to add the json for the gateway you want to pair with.
{{“gw_mac:” “xxgateway_macxx”}}

that way no need to use the mihome app unless you wish to update the gateways

1 Like

I have a Xiaomi temperature sensor with barometric pressure sensor. Everything is working great, it’s auto discovered, but for pressure it’s showing raw pressure, not the widely used sea level pressure (corrected with your elevation).

Is there any formula in HA to convert raw pressure reading to the more used mean sea level?

Mean sea level pressure calculator (converter) – Simple formula

On the page is the formula too:

p0 = Calculated mean sea level pressure
p1 = Measured/barometric pressure
T = Measured air temperature:
?? = Elevation of measured data

p0 =p1 (1-0,0065h / (T + 0,0065h +273,15))^-5,257

…but how do I use this to correct reading for my Xiaomi sensor?

Ever get any help with this?

You do this with templates. Say your absolute pressure looks like this:

  - platform: mqtt
    name: "Man Cave Air Pressure"
    state_topic: "tele/sonoff9/SENSOR"
    value_template: "{{ value_json['BMP280'].Pressure }}"
    unit_of_measurement: "hPa"

It doesn’t matter what sort of sensor it is - you just need the name to plug into a template. Create a template like the following:

  - platform: template
    sensors:
      man_cave_pressure_msl:
        friendly_name: "Man Cave Air Pressure MSL"
        unit_of_measurement: hPa
        value_template: "{{ (states('sensor.man_cave_air_pressure')|float * (1 - (0.0065 * 175) / (states('sensor.man_cave_temperature')|float + (0.0065 * 175) + 273.15)) ** -5.257) | round(1)  }}"
        icon_template: mdi:gauge

In this template substitute the Xiaomi temperature and pressure sensor names to replace the example ones. The number “175” is the elevation in metres above sea level of your sensor. Substitute your elevation, all other figures should remain the same.

Input and output sensors should look like:

 sensor.man_cave_air_pressure	998.1

 sensor.man_cave_pressure_msl	1018.6
2 Likes

I could fix my installation with your hint as well. One open point is still left: How to include the reading in a device area? Thank you.

Where do you put this code?
I’m new to home assistant and cant understand wich file to put all the code into?

/Tomas

If you are new to HA you probably haven’t edited any yaml files as a lot can be done these days from the Configuration tab, but this needs to go in your configuration.yaml file.

Install the File Editor add-on from the Supervisor add-on store to get started.

I did a copy and paste of this and just replaced my sensor names and elevation but it returns a value of 0.0?

Hmm. Then one of your sensor values is probably wrong.

Pasting this into your template editor (substituting your sensors and elevation):

{{ states('sensor.man_cave_temperature') }}
{{ states('sensor.man_cave_air_pressure') }}
{{ (states('sensor.man_cave_air_pressure')|float * (1 - (0.0065 * 175) / (states('sensor.man_cave_temperature')|float + (0.0065 * 175) + 273.15)) ** -5.257) | round(1)  }}

Should give a result like:

Result type: string
18.2
1000.2
1020.9
This template listens for the following state changed events:

Entity: sensor.man_cave_air_pressure
Entity: sensor.man_cave_temperature

Also paste your template sensor definition, that you have edited, rather than the one I use - so we can see if any weird typos. :slight_smile: