I have 4 scrape sensors that retrieve data from the printer’s web interface. Sometimes during Home Assistant start one or two sensors are not initiated and errors appear in the log:
2018-01-14 16:09:56 ERROR (SyncWorker_2) [homeassistant.components.sensor.rest] Error fetching data: <PreparedRequest [GET]>
2018-01-14 16:09:56 ERROR (MainThread) [homeassistant.components.sensor] Error on device update!
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 217, in async_add_entity
yield from entity.async_device_update(warning=False)
File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update
yield from self.hass.async_add_job(self.update)
File "/usr/local/lib/python3.6/asyncio/futures.py", line 332, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/local/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
future.result()
File "/usr/local/lib/python3.6/asyncio/futures.py", line 245, in result
raise self._exception
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/sensor/scrape.py", line 115, in update
raw_data = BeautifulSoup(self.rest.data, 'html.parser')
File "/srv/homeassistant/lib/python3.6/site-packages/bs4/__init__.py", line 192, in __init__
elif len(markup) <= 256 and (
TypeError: object of type 'NoneType' has no len()
Configuration for this sensors:
- platform: scrape
resource: !secret brother_status_url
name: printer_toner
select: '.tonerremain'
attribute: 'height'
scan_interval: 1800
value_template: '{{ ((value | int) / 60 * 100) | round }}'
unit_of_measurement: '%'
- platform: scrape
resource: !secret brother_information_url
name: printer_printed_pages
select: 'dd:nth-of-type(5)'
scan_interval: 300
value_template: '{{ (value | int) }}'
unit_of_measurement: 'str'
- platform: scrape
resource: !secret brother_information_url
name: printer_drum_usage
select: 'dd:nth-of-type(9)'
scan_interval: 1800
value_template: '{{ 100 - ((value | replace("(", "") | replace("%)", "")) | int) }}'
unit_of_measurement: '%'
- platform: scrape
resource: !secret brother_status_url
name: printer_status
select: 'dd:nth-of-type(1)'
scan_interval: 2
value_template: >-
{% if value == 'DRUKOWANIE' %}
drukowanie
{% elif ('PROSZ' in value) and ('CZEKA' in value) %}
nagrzewanie
{% elif (('MA' in value) and ('TONERU' in value)) or (value == 'OCZEKIWANIE') %}
oczekiwanie
{% else %}
{{ (value | lower) }}
{% endif %}
Any solution for that?