New sensor template vesync

Hi all,

I am totally new to HA and to programming.

I have an air purifier and I have follwed instructions to add it to my HA. It shows up and is great, I can turn it on and off but I wanted to use the air quality attribute to see the history of the air quality then build some automations around this attribute. It’s a LEVOIT Smart Wifi Air Purifier (LV-PUR131S) I followed this guide to add it to my HA: https://www.home-assistant.io/integrations/vesync

So to get the attribute I have added this to my config.yaml:

sensor:      
  - platform: template
    sensors:
      air_quality:
      friendly_name: Air Quality
      value_template: "{{ state_attr('fan.angelina_s_air_purifier', 'air_quality') }}"

But now HA just spins when checking config and a new error has appeared in the log:

Logger: aiohttp.server
Source: helpers/config_validation.py:748
First occurred: 15:21:13 (3 occurrences)
Last logged: 16:35:57

Error handling request
Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py”, line 422, in _handle_request
resp = await self._request_handler(request)
File “/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py”, line 499, in _handle
resp = await handler(request)
File “/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py”, line 118, in impl
return await handler(request)
File “/usr/src/homeassistant/homeassistant/components/http/security_filter.py”, line 56, in security_filter_middleware
return await handler(request)
File “/usr/src/homeassistant/homeassistant/components/http/request_context.py”, line 18, in request_context_middleware
return await handler(request)
File “/usr/src/homeassistant/homeassistant/components/http/ban.py”, line 72, in ban_middleware
return await handler(request)
File “/usr/src/homeassistant/homeassistant/components/http/auth.py”, line 127, in auth_middleware
return await handler(request)
File “/usr/src/homeassistant/homeassistant/components/http/view.py”, line 129, in handle
result = await result
File “/usr/src/homeassistant/homeassistant/components/config/core.py”, line 29, in post
errors = await async_check_ha_config_file(request.app[“hass”])
File “/usr/src/homeassistant/homeassistant/config.py”, line 874, in async_check_ha_config_file
res = await check_config.async_check_ha_config_file(hass)
File “/usr/src/homeassistant/homeassistant/helpers/check_config.py”, line 215, in async_check_ha_config_file
p_validated = platform_schema(p_validated)
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 272, in call
return self._compiled([], data)
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 594, in validate_dict
return base_validate(path, iteritems(data), out)
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 386, in validate_mapping
cval = cvalue(key_path, value)
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 817, in validate_callable
return schema(data)
File “/usr/src/homeassistant/homeassistant/helpers/config_validation.py”, line 495, in verify
return cast(Dict, schema(value))
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 272, in call
return self._compiled([], data)
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 594, in validate_dict
return base_validate(path, iteritems(data), out)
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 386, in validate_mapping
cval = cvalue(key_path, value)
File “/usr/local/lib/python3.8/site-packages/voluptuous/validators.py”, line 215, in _run
return self._exec(self._compiled, value, path)
File “/usr/local/lib/python3.8/site-packages/voluptuous/validators.py”, line 339, in _exec
v = func(path, v)
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 817, in validate_callable
return schema(data)
File “/usr/src/homeassistant/homeassistant/helpers/config_validation.py”, line 748, in validator
if key in config:
TypeError: argument of type ‘NoneType’ is not iterable

When I comment out the sensor I don’t get the error in the log and I can check config…

Any ideas on how to fix this would be much appreciated :wink:

hi there…Maybe there could be some syntax issues. But to check it, instead of using bulletins to paste your config, please copy and paste the config between ``` so that it will appear as code.

Thanks for replying so quickly and for the tip on posting code. It probably is some kind of syntax thing as I am totally new. Need to start learning the basics as I find it hugely interesting …

sensor:      
  - platform: template
    sensors:
      air_quality:
      friendly_name: Air Quality
      value_template: "{{ state_attr('fan.angelina_s_air_purifier', 'air_quality') }}"

Could you also provide a view of that entity (print screen is fine) ? You can have it in the development tools, by typing the name of the entity… You will have a view of the structure of that entity…

Thank you. I’m guessing it’s something very basic I’ve missed…

I can see the friendly name is in two different colours. Does this mean something and could this be effecting it somehow?

In the development tools → template, when you copy/paste this line, do you get the result “fine” ?

Try this

sensor:
  - platform: template
    sensors:
     air_quality:
        friendly_name: 'Air Quality'
        value_template: "{{ state_attr('fan.angelina_s_air_purifier', 'air_quality') }}"

It does:

The problem is maybe the friendly name with the same name than the sensor ? Seems strange to me but for me I do not see why it should not work…
Try to remove the friendly name and retest…

Thank you!!!

My syntax was wrong… Got a lot to learn. Thank you for taking the time to help :slight_smile:

1 Like

Hope it worked. i had made a correction in the code I submitted. i accidently omitted one closing ’

I worked it out mate thank you

1 Like

Hi There I been following this, if you don’t mind what was your working code line used? I am trying to reverse engineer how you got this working to get my Vesync Humidifier to show up…
Also did you add something to the configuration.yaml as well?

Sorry for the delay in responding

      
vesync:
  username: !secret vesync_username
  password: !secret vesync_password 


   - platform: template
     sensors:
      air_quality:
         friendly_name: Air Quality
         value_template: "{{ state_attr('fan.angelina_s_air_purifier', 'air_quality') }}"
      filter_life:
         friendly_name: Filter Life
         value_template: "{{ state_attr('fan.angelina_s_air_purifier', 'filter_life') }}"
      mode:
         friendly_name: Mode
         value_template: "{{ state_attr('fan.angelina_s_air_purifier', 'mode') }}"
      screen_status:
          friendly_name: Screen Status
          value_template: "{{ state_attr('fan.angelina_s_air_purifier', 'screen_status') }}"
1 Like