home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.11k stars 29.79k forks source link

Plant does not work (SQL error) #114328

Closed martijnbuts closed 5 months ago

martijnbuts commented 5 months ago

The problem

After upgrading to beta 2024.4.0B0 the plant or plant monitor does not work anymore. https://www.home-assistant.io/integrations/plant/

What version of Home Assistant Core has the issue?

core-2024.4.0b0

What was the last working version of Home Assistant Core?

core-2024.3.x

What type of installation are you running?

Home Assistant OS

Integration causing the issue

plant

Link to integration documentation on our website

https://www.home-assistant.io/integrations/plant/

Diagnostics information

Example YAML snippet

plant:
  Plant_links:
    sensors:
      moisture: sensor.plantenbak_1_vochtigheid
      temperature: sensor.serre_temperature
      conductivity: sensor.plantenbak_1_vochtigheid
      brightness: sensor.bh1750_illuminance
    min_moisture: 10
    min_conductivity: 20
    max_conductivity: 90
    min_temperature: 16
    max_temperature: 25

  Plant_rechts:
    sensors:
      moisture: sensor.plantenbak_2_vochtigheid
      temperature: sensor.serre_temperature
      conductivity: sensor.plantenbak_2_vochtigheid
      brightness: sensor.bh1750_illuminance
    min_moisture: 10
    min_conductivity: 20
    max_conductivity: 90
    min_temperature: 16
    max_temperature: 25

Anything in the logs that might be useful for us?

Logger: homeassistant.components.plant
Bron: helpers/entity_platform.py:580
integratie: Plant (documentatie, problemen)
Eerst voorgekomen: 19:02:27 (2 gebeurtenissen)
Laatst gelogd: 19:02:28

Error adding entity plant.plant_links for domain plant with platform plant
Error adding entity plant.plant_rechts for domain plant with platform plant
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1971, in _exec_single_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 919, in do_execute
    cursor.execute(statement, parameters)
sqlite3.OperationalError: no such column: states.last_reported_ts

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 580, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 881, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1333, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/plant/__init__.py", line 282, in async_added_to_hass
    await get_instance(self.hass).async_add_executor_job(
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/plant/__init__.py", line 311, in _load_history_from_db
    history_list = history.state_changes_during_period(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/history/__init__.py", line 175, in state_changes_during_period
    return _target(
           ^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/history/modern.py", line 437, in state_changes_during_period
    execute_stmt_lambda_element(
  File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 232, in execute_stmt_lambda_element
    executed = session.connection().execute(stmt)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1422, in execute
    return meth(
           ^^^^^
  File "/usr/local/lib/python3.12/site-packages/sqlalchemy/sql/lambdas.py", line 603, in _execute_on_connection
    return connection._execute_clauseelement(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1644, in _execute_clauseelement
    ret = self._execute_context(
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1850, in _execute_context
    return self._exec_single_context(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1990, in _exec_single_context
    self._handle_dbapi_exception(
  File "/usr/local/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 2357, in _handle_dbapi_exception
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
  File "/usr/local/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1971, in _exec_single_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 919, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: states.last_reported_ts
[SQL: SELECT states.metadata_id, states.state, states.last_updated_ts, states.last_reported_ts 
FROM states 
WHERE (states.last_changed_ts = states.last_updated_ts OR states.last_changed_ts IS NULL) AND states.last_updated_ts > ? AND states.metadata_id = ? ORDER BY states.metadata_id, states.last_updated_ts]
[parameters: (1711303347.714514, 1012)]
(Background on this error at: https://sqlalche.me/e/20/e3q8)

Additional information

No response

home-assistant[bot] commented 5 months ago

plant documentation plant source

joostlek commented 5 months ago

Seems related to #114327

bdraco commented 5 months ago

This one is fixed via #114333 and will be in the next beta