Description
Right now, when a pyscript performs a service call, the LogBook has an entry like this:
HallDown Occupied turned off by service input_boolean.turn_off
However, when Home Assistant Automations perform an action, the LogBook looks like this:
halldown_overhead turned off by halldown_occupied_off
It does this through a context
object:
service_task = self._hass.async_create_task(
self._hass.services.async_call(
domain,
service,
service_data,
blocking=True,
context=self._context,
limit=limit,
)
)
pyscript can create one of these with something like:
from homeassistant.core import Context
# context comes from the state_trigger, time_trigger, etc
parent_id = None if context is None else context.id
new_context = Context(parent_id=parent_id)
I can't find a lot of documentation on how to create context and name the pieces so they show up well in LogBook, but I think this is a start anyway. I think even this small bit of code would make the logbook show that, for instance, the "binary_sensor.dark" in my @state_trigger is what called input_boolean.turn_on. And, even this, is better than what we have now.
The final bit would be to get LogBook to show that binary_sensor.dark activated my pyscript called "halldown_at_dark", and that "halldown_at_dark" is what called input_boolean.turn_on.