briis / weatherbit

The weatherbit integration adds support for the weatherbit.io web service as a source for meteorological data for your location.
MIT License
33 stars 7 forks source link

Invalid state encountered for entity ID: sensor.weatherbit_weather_alerts. State max length is 255 characters #61

Closed lymanepp closed 2 years ago

lymanepp commented 2 years ago

I found the following error messages in my homeassistant.log file. Might need to truncate alerts to 255 chars.

2022-01-29 01:22:24 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 134, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 265, in _async_refresh
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 505, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 629, in _async_write_ha_state
    self.hass.states.async_set(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1222, in async_set
    state = State(
  File "/usr/src/homeassistant/homeassistant/core.py", line 912, in __init__
    raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.weatherbit_weather_alerts. State max length is 255 characters.
briis commented 2 years ago

State should just be a number. Count of alerts. can you see what the value is/was?

lymanepp commented 2 years ago

State should just be a number. Count of alerts. can you see what the value is/was?

I can't see what the invalid value was. But I can see that it has been set recently though.

image

Edit: here's partial output from your WeatherBitApiClient test client.

alert_count - 3
alerts - [AlertDescription(key='C3609', title='Freeze Watch issued January 28 at 11:51AM EST until January 30 at 9:00AM EST by NWS Tampa Bay Ruskin FL', en_description='', loc_description=' WHAT...Sub-freezing temperatures as low as 29 possible.', severity='Warning', effective_utc='2022-01-28T16:51:00', ends_utc='2022-01-30T14:00:00', expires_utc='2022-01-30T00:00:00', onset_utc='2022-01-30T06:00:00', uri='https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.685f3eeddb6bc64448acb225ee29d9f285e6b23a.002.1', city_name='Cape Coral', regions=['Polk', ' Hardee', ' Highlands', ' DeSoto', ' Coastal Pasco', ' Coastal Hillsborough', ' Inland Hillsborough', ' Inland Manatee', ' Inland Sarasota', ' Inland Charlotte', ' Inland Lee']), AlertDescription(key='C3609', title='High Surf Advisory issued January 28 at 4:07AM EST until January 30 at 1:00AM EST by NWS Tampa Bay Ruskin FL', en_description=' feet. For the High Rip Current Risk, dangerous rip currents', loc_description=' WHAT...For the High Surf Advisory, large breaking waves of 5 to', severity='Advisory', effective_utc='2022-01-28T09:07:00', ends_utc='2022-01-30T06:00:00', expires_utc='2022-01-30T12:00:00', onset_utc='2022-01-29T06:00:00', uri='https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.dca1abc4643ee36be344d5b0c1e76955cda079dd.001.1', city_name='Cape Coral', regions=['Pinellas', ' Coastal Manatee', ' Coastal Sarasota', ' Coastal Charlotte', ' Coastal Lee']), AlertDescription(key='C3609', title='Rip Current Statement issued January 28 at 4:07AM EST until January 30 at 7:00AM EST by NWS Tampa Bay Ruskin FL', en_description=' feet. For the High Rip Current Risk, dangerous rip currents', loc_description=' WHAT...For the High Surf Advisory, large breaking waves of 5 to', severity='Watch', effective_utc='2022-01-28T09:07:00', ends_utc='2022-01-30T12:00:00', expires_utc='2022-01-30T12:00:00', onset_utc='2022-01-29T06:00:00', uri='https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.dca1abc4643ee36be344d5b0c1e76955cda079dd.001.2', city_name='Cape Coral', regions=['Pinellas', ' Coastal Manatee', ' Coastal Sarasota', ' Coastal Charlotte', ' Coastal Lee'])]
briis commented 2 years ago

Something goes wrong in the formatting of the Alert - damn they have many different formats🥴. I'll work on a fix.

briis commented 2 years ago

Did you by any chance download the new sensor.py file? I just found that I introduced an error in that file, that is leading to this error.

briis commented 2 years ago

Released 1.0.8, where this is fixed. Please check and close if you agree.

lymanepp commented 2 years ago

I've upgraded to 1.0.8 and don't see any errors in the log. Thanks for the fix!