Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: fire events for every completed service run #16

Merged
merged 2 commits into from
Mar 27, 2023
Merged

feat: fire events for every completed service run #16

merged 2 commits into from
Mar 27, 2023

Conversation

matfax
Copy link
Contributor

@matfax matfax commented Dec 23, 2022

Firing events after services allows other automations and templates to respond to saved state and variable changes. The call_service event doesn't guarantee that the update is completed.

@PiotrMachowski
Copy link
Owner

Nice idea 👍

matfax and others added 2 commits March 21, 2023 11:51
Firing events after services allows other automations and templates to respond to saved state and variable changes. The call_service event doesn't guarantee that the update is completed.
@PiotrMachowski
Copy link
Owner

To be honest I'm still a bit unsure about this functionality. Can you describe automations/scripts that can utilize this feature?

@matfax
Copy link
Contributor Author

matfax commented Mar 21, 2023

The variables, in particular, might be relevant to multiple automations. You might want to update a device's state whenever a variable changes, or create a variable on that other automations depend in other ways, as some cached/lazy version of some sort of calculation, etc.

call_service doesn't ensure that the respective service is completed, last I checked. That's why you have to fire the events at the end.

This is only what I can spontaneously think of. There is a specific use case where this was necessary in my setup, it's not up at the moment so I could check.

@PiotrMachowski
Copy link
Owner

Isn't it achievable using built-in state_changed event as well?

@matfax
Copy link
Contributor Author

matfax commented Mar 21, 2023

It captures state changes, not state saves, restores as a subset of changes, or any variable changes.

I think the restore events might also be relevant for automations that are supposed to be triggered during startup and which rely on states being restored already.

If it's really important, I can look up my use case eventually and explain it as well. It might have involved template sensors.

@PiotrMachowski
Copy link
Owner

All things that are "stored" in saver are also visible as attributes of saver.saver entity, so their changes should result in state_changed events as well.

I think that I these custom events can be added as well though

@matfax
Copy link
Contributor Author

matfax commented Mar 21, 2023

Fair enough, but isn't it all cramped into the same entity? It might be difficult to match a specific variable without additional complexity.

I'm just guessing here. Cause I'm positive that I've exhausted these other methods before going this route.

I'll know more when I get my HA running again so that I can conveniently access by backed up database.

@PiotrMachowski
Copy link
Owner

Fair enough, but isn't it all cramped into the same entity?

Yes, it is. That's why I think that custom events are acceptable after all

@PiotrMachowski PiotrMachowski changed the base branch from master to dev March 27, 2023 17:19
@PiotrMachowski PiotrMachowski merged commit f896dac into PiotrMachowski:dev Mar 27, 2023
@PiotrMachowski
Copy link
Owner

Thanks @matfax!

@matfax matfax deleted the patch-1 branch March 28, 2023 09:36
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants