diff --git a/custom_components/pyscript/state.py b/custom_components/pyscript/state.py index 88130b0..46389af 100644 --- a/custom_components/pyscript/state.py +++ b/custom_components/pyscript/state.py @@ -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): @@ -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 diff --git a/docs/reference.rst b/docs/reference.rst index 6790374..de10187 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -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: