Can't see added sesnor

Hello.
I’m newbie with home assitant so my question may seems stupid, but I don’t know what I’m doing wrong.

I’ve added integration for Xiaomi Air Purifier 2S, but I can’t see any sensors from this device:
image

So I’ve tried to add it manually, because I can see values in device attributes

My configuration.yaml:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml

and sensors.yaml:

#Air purifier
  - platform: template
    sensors:
      air_purifier_bedroom_aqi:
      friendly_name: PM2.5
      entity_id:
        -  fan.oczyszczacz_powietrza
      unit_of_measurement: μg/m³
      value_template: "{{ state_attr('fan.oczyszczacz_powietrza', 'aqi' }}"

I’ve hard restared hass (by restarting hosting device) and I can’t see my sensor

What I’m doing wrong? :frowning: Thank you for your time.

Wrong indentation, entity_id is not part of the template sensor config and a missing bracket in the value_template, try this:

  - platform: template
    sensors:
      air_purifier_bedroom_aqi:
        friendly_name: PM2.5
        unit_of_measurement: μg/m³
        value_template: "{{ state_attr('fan.oczyszczacz_powietrza', 'aqi') }}"

Also check your logs, there’s probably an error in there.

1 Like

I applied tour changes but still doesn’t work.
Now sensors.yaml looks like this:

#Air purifier
  - platform: template
    sensors:
      air_purifier_bedroom_aqi:
      friendly_name: PM2.5
      unit_of_measurement: μg/m³
      value_template: "{{ state_attr('fan.oczyszczacz_powietrza', 'aqi') }}"

In log file I see:

2021-10-30 21:56:11 ERROR (MainThread) [homeassistant.config] Unknown error validating config for template platform for sensor component with PLATFORM_SCHEMA
Traceback (most recent call last):
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/homeassistant/config.py", line 861, in async_process_component_config
    p_validated = platform.PLATFORM_SCHEMA(p_config)  # type: ignore
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/validators.py", line 218, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/validators.py", line 337, in _exec
    v = func(v)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 386, in validate_mapping
    cval = cvalue(key_path, value)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/homeassistant/helpers/config_validation.py", line 487, in verify
    return cast(dict, schema(value))
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 386, in validate_mapping
    cval = cvalue(key_path, value)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/validators.py", line 215, in _run
    return self._exec(self._compiled, value, path)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/validators.py", line 339, in _exec
    v = func(path, v)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/data/data/com.termux/files/home/hass/lib/python3.9/site-packages/homeassistant/helpers/config_validation.py", line 738, in validator
    if key in config:
TypeError: argument of type 'NoneType' is not iterable

It seems not that you applied all changes
Your indentation is still wrong

2 Likes

You need to indent the last 3 lines just like in my example.

1 Like

Yeah, it works! Thank you!
Ehh… just yaml things… couldn’t it be just json :smirk: