Error while setting up file platform for sensor

Hi,

since 2021.6.2 my sensor to read the log file doesn’t work anymore.

I get:

Error adding entities for domain sensor with platform file
Error while setting up file platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 383, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 588, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 615, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 368, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 494, in _async_write_ha_state
    self.hass.states.async_set(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1218, in async_set
    state = State(
  File "/usr/src/homeassistant/homeassistant/core.py", line 906, in __init__
    raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.log_tail. State max length is 255 characters.

This is my configuration on the sensor.yaml

 - platform: file
    file_path: /config/home-assistant.log
    name: Log tail
    value_template: >
      {{value|truncate(255,True)}}

Not sure, but truncate() adds ... by default, so your string is actually 258 char.
Truncate at 252 or do truncate(255, True, '')

Thanks, truncate at 252 worked. I don’t know why it was working before

Likely, it was silently truncated before, and became an error.
Do you remember seeing the “…” before?

Nope it was working just fine. Anyway, thanks for the help