Change state of Xiaomi Door/window sensor

Hi Guys,

i’m using the xiaomi door sensor to detected if the AC are on or off. its working great!!!
the only thing that i would like to change is the following:
the state present, please see the picture uploaded, is Open/Closed.

i would like to change it to On/Off. and also when its changes to On i would like that the color will also change to yellow like its working now.

Someone ?

Have you tried changing the device_class?

would you mind provide example, tried and got confused

Whats the full proper name of the sensor under “States”

Try adding the following to your customize.yaml

binary_sensor.door_window_sensor_158d0002582d8b
  device_class: cold
binary_sensor.door_window_sensor_158d00025ead67
  device_class: cold

If you don’t have a customize.yaml in your folder create one and make sure you add the customize: !include customize.yaml part to you configuration.yaml as in:

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: !secret latitude
  longitude: !secret longitude
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 207
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Europe/London
  # Customization file
  customize: !include customize.yaml

I have to put a colon in the end so that it does not return an error, is it okay?

binary_sensor.door_window_sensor_158d0002582d8b:
device_class: cold
binary_sensor.door_window_sensor_158d00025ead67:
device_class: cold

still the same, need to do something else ?

Sorry, yes I missed the colon out

1 Like

still the same, need to add more?

Have you restarted HomeAssistant?

Another way to do it is through the interface.
Delete the contents of your customize.yaml.

Then goto Configuration on the Left panel, then Customization at the bottom.
Select your binary_sensor from the dropdown for Entity.
Then you should have the option to edit the Device_class

what to choose?

i did the following in configuration.yaml
sensor_35:
friendly_name: ‘AC Bedroom’
value_template: “{% if is_state(‘binary_sensor.door_window_sensor_158d00025ead67’, ‘on’) %}On{% else %}Off{% endif %}”

now its working, the only thing is the color not changing to yellow based on the state

For your purpose the correct choice is power.

It’s not necessary to create a Template Binary Sensor. It just duplicates the functionality of your existing xiaomi binary sensor.

Simply set the device_class of your xiaomi binary sensor to power.

would you mind to show me how ?

The way you were doing it in your previous post using Home Assistant’s Customization page.

Change the device class to power and don’t forget to click Save.

there is no power option to choose

What is AC Sensor Bedroom?

It’s not the xiaomi binary_sensor because because Home Assistant understands it to be a sensor.

AC Sensor Bedroom (sensor)

Sensors have less choice of device class compared to binary sensors.

The friendly name of the xiaomi binary sensor is AC Bedroom Sensor.

found it,
please look at following errors

resolved, the problem was that already had customize enabled on my configuration.yaml

so i add there the following and issue resolved.

binary_sensor.door_window_sensor_158d0002582d8b:
  device_class: power

So why did it work now but did not work when you tried the first time? You reported it failed to work in this post. Yet the configuration in your first attempt:

first

is virtually the same as in your second attempt:

second

cold vs power is not what determines if it works or not, it’s something else you did. What was it?

1 Like