Skip to content

added last_reported to state attributes #743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion custom_components/pyscript/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

_LOGGER = logging.getLogger(LOGGER_PATH + ".state")

STATE_VIRTUAL_ATTRS = {"entity_id", "last_changed", "last_updated"}
STATE_VIRTUAL_ATTRS = {"entity_id", "last_changed", "last_updated", "last_reported"}


class StateVal(str):
Expand All @@ -26,6 +26,7 @@ def __new__(cls, state):
new_var.entity_id = state.entity_id
new_var.last_updated = state.last_updated
new_var.last_changed = state.last_changed
new_var.last_reported = state.last_reported
return new_var


Expand Down
3 changes: 2 additions & 1 deletion docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,13 @@ Here's an example using ``input_number``, assuming it has been configured to cre
input_number.test.set_value(value=13)
input_number.test.set_value(13)
Three additional virtual attribute values are available when you use a variable directly as
Four additional virtual attribute values are available when you use a variable directly as
``DOMAIN.entity.attr`` or call ``state.get("DOMAIN.entity.attr")``:

- ``entity_id`` is the DOMAIN.entity as string
- ``last_changed`` is the last UTC time the state value was changed (not the attributes)
- ``last_updated`` is the last UTC time the state entity was updated
- ``last_reported``is the last UTC time the integration set the state of an entity, regardless of whether it changed or not
If you need to compute how many seconds ago the ``binary_sensor.test1`` state changed, you could
do this:
Expand Down
Loading