Skip to content

Persist pyscript states through supported Home Assistant APIs #885

Open

Description

@markfrancisonly

state.persist relies on Home Assistant internals in two places:

  • register_persist() in state.py hands a stand-in PyscriptEntity to RestoreStateData.async_restore_entity_added, so Home Assistant saves the state at shutdown.
  • restore_state() in __init__.py reads the stored states back out of RestoreStateData at startup. Its own comment says it "should re-implement using RestoreEntity".

Home Assistant 2026.11 changed that internal data (home-assistant/core#183906), which stopped pyscript from setting up (#882, worked around in #883). Any later change to it can break persistence again.

Two ways to move onto supported APIs:

  • Make each persisted variable a real RestoreEntity, so Home Assistant saves and restores it through the entity API.
  • Keep persisted variables in pyscript's own Store (homeassistant.helpers.storage), saved on change and at shutdown, loaded at setup.

Either way, restore timing should stay as it is today: every persisted pyscript.* state is back at startup, before any script calls state.persist.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions