Skip to content

Conversation

@dmamelin
Copy link
Contributor

@dmamelin dmamelin commented Dec 5, 2023

Modifying StateVal according to homeassistant.core.State. Useful in complex logic: no need to store and pass entity_id.
Simplified example:

def func(state):
    num_seconds_ago = (dt.now(tz=timezone.utc) - state.last_changed).total_seconds()
    if num_seconds_ago > 10:
        light.toggle(entity_id=state.entity_id)
        log.info(f"toggle {state.entity_id}")

@dmamelin dmamelin closed this Jan 6, 2024
@dmamelin dmamelin reopened this Jan 6, 2024
@ALERTua
Copy link
Contributor

ALERTua commented Jan 22, 2024

@craigbarratt, ping :)

@dmamelin
Copy link
Contributor Author

dmamelin commented Feb 1, 2024

ooops... I wanted to make a separate PR for #581, but forgot about this PR and when I pushed to my fork, the changes were added here.

@craigbarratt craigbarratt merged commit 8302c13 into custom-components:master Jun 19, 2024
@craigbarratt
Copy link
Member

Thanks for the PR. Sorry about the delay in following up.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants