Hi,
Thank you for sharing your work.
I’ve managed to add sensors for my Mi Air Purifier 3H but somehow I get value “none” for all sensors.
Here is my code:
sensor:
- platform: template
sensors:
mi_air_purifier_temp:
friendly_name: "Temperature"
value_template: "{{ state_attr('fan.xiaomi_airpurifier_3h', 'temperature') }}"
unit_of_measurement: "°C"
device_class: "temperature"
mi_air_purifier_humidity:
friendly_name: "Humidity"
value_template: "{{ state_attr('fan.xiaomi_airpurifier_3h', 'humidity') }}"
unit_of_measurement: "%"
device_class: "humidity"
mi_air_purifier_air_quality_pm25:
friendly_name: "Air quality (AQI) PM2.5"
value_template: "{{ state_attr('fan.xiaomi_airpurifier_3h', 'aqi') }}"
unit_of_measurement: "μg/m³"
icon_template: "mdi:weather-fog"
mi_air_purifier_avg_air_quality_pm25:
friendly_name: "Average air quality (AvgAQI) PM2.5"
value_template: "{{ state_attr('fan.xiaomi_airpurifier_3h', 'average_aqi') }}"
unit_of_measurement: "μg/m³"
icon_template: "mdi:weather-hazy"
mi_air_purifier_use_time:
friendly_name: "Time used"
value_template: >
{% macro phrase(value, name) %}
{%- set value = value | int %}
{%- set end = 's' if value > 1 else '' %}
{{- '{} {}{}'.format(value, name, end) if value | int > 0 else '' }}
{%- endmacro %}
{% set weeks = (state_attr('fan.xiaomi_airpurifier_3h', 'use_time') | int / 604800) | int %}
{% set days = ((state_attr('fan.xiaomi_airpurifier_3h', 'use_time') | int - (weeks * 604800)) / 86400) | int %}
{% set hours = ((state_attr('fan.xiaomi_airpurifier_3h', 'use_time') | int - (weeks * 604800) - (days * 86400)) / 3600) | int %}
{% set minutes = ((state_attr('fan.xiaomi_airpurifier_3h', 'use_time') | int - (weeks * 604800) - (days * 86400) - (hours * 3600)) / 60) | int %}
{% set seconds = (state_attr('fan.xiaomi_airpurifier_3h', 'use_time') | int - (weeks * 604800) - (days * 86400) - (hours * 3600) - (minutes*60)) | int %}
{{ [ phrase(weeks, 'week'), phrase(days, 'day'), phrase(hours, 'hr'), phrase(minutes, 'min'), phrase(seconds, 'sec') ] | select('!=','') | list | join(', ') }}
icon_template: "mdi:heart-pulse"
mi_air_purifier_filter_used:
friendly_name: "Filter used"
value_template: "{{ state_attr('fan.xiaomi_airpurifier_3h', 'filter_hours_used') }}"
unit_of_measurement: "hrs"
icon_template: "mdi:heart-off"
mi_air_purifier_filter_remaining:
friendly_name: "Filter remaining"
value_template: "{{ state_attr('fan.xiaomi_airpurifier_3h', 'filter_life_remaining') }}"
unit_of_measurement: "%"
icon_template: "mdi:heart-outline"
mi_air_purifier_purify_volume:
friendly_name: "Purified volume"
value_template: "{{ state_attr('fan.xiaomi_airpurifier_3h', 'purify_volume') }}"
unit_of_measurement: "m³"
icon_template: "mdi:warehouse"
mi_air_purifier_speed:
friendly_name: "Motor speed"
value_template: "{{ state_attr('fan.xiaomi_airpurifier_3h', 'motor_speed') }}"
unit_of_measurement: "rpm"
icon_template: "mdi:speedometer"
mi_air_purifier_led_brightness:
friendly_name: "Led brightness"
value_template: "{{ state_attr('fan.xiaomi_airpurifier_3h', 'led_brightness') }}"
unit_of_measurement: "lx"
icon_template: "mdi:brightness-5"
Any idea?
Thank you.