WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
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