Need help scraping a specific line of text from a website. The end goal is a scrape sensor that picks up this text so I can use it as a surf report (ocean conditions).
If you are trying to configure an entity, but it isn’t added to the system, there is usually an error message in the logs.
Did you try restarting Home Assistant?
It could quite possibly be that my selector is incorrect. I only tested it in Firefox’s developer tools, I did not add a scrape sensor myself. However, if that’s the problem, there should definitely be an error message.
Ah! Dummy me… I found the error message… Does this mean that the output is too long for HA and the scrape sensor?
Logger: homeassistant.components.sensor
Source: core.py:1047
Integration: Sensor (documentation, issues)
First occurred: 1:22:59 PM (2 occurrences)
Last logged: 1:22:59 PM
Error adding entities for domain sensor with platform scrape
Error while setting up scrape platform for sensor
Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 382, in async_add_entities await asyncio.gather(*tasks) File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 614, in _async_add_entity await entity.add_to_platform_finish() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 799, in add_to_platform_finish self.async_write_ha_state() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 532, in async_write_ha_state self._async_write_ha_state() File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 679, in _async_write_ha_state self.hass.states.async_set( File “/usr/src/homeassistant/homeassistant/core.py”, line 1361, in async_set state = State( File “/usr/src/homeassistant/homeassistant/core.py”, line 1047, in init raise InvalidStateError( homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.surfdata. State max length is 255 characters.
Yes, that’s the problem.
States in Home Assistant cannot be longer than 255 characters. Attributes do not have this limitation, but I don’t see an easy way to provide the scrape sensor’s value as an attribute. Maybe the service you are scraping has an API? It is much easier to do this using a RESTful sensor.
Yeah… lack of an API is what started me down this path! Haha… Maybe I’ll just try to scrape a different part of the page with less text and the info I want.
Did you have a way your pulled that selector? Clearly my HTML/CSS skills are pretty sad! haha
I really appreciate your help though! And if I get it figured out I’ll let you know