Skip to content

last_changed seems to have the current value?! #413

Answered by craigbarratt
andorardo asked this question in Q&A
Discussion options

You must be logged in to vote

Because the function call is executed immediately after the trigger, the state variable has just been updated, and, as you note, the last_changed is therefore very recent.

You can get the old_value (in kwargs) and use its last_changed attribute (although the first time, old_value will be None):

@state_trigger('sensor.xyz')
def xyz_change(old_value=None, **kwargs):
    last_changed = sensor.xyz.last_changed
    log.info(f"last_changed {last_changed}")
    if old_value is not None:
        log.info(f'  old_value {old_value} last_changed {old_value.last_changed}')

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@andorardo
Comment options

Answer selected by andorardo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants