PythonScriptsPro icon indicating copy to clipboard operation
PythonScriptsPro copied to clipboard

Service call context

Open jmot205 opened this issue 1 year ago • 1 comments

Is it possible for the context of a service call to be wired in so that when PythonScriptsPro calls a service and changes the state of a device it shows in the device's attribute's logbook? e.g. Calling a light to turn on via PSP results in the logbook entry:

Turned on triggered by service light: Turn on

Whereas adding context e.g. like the following would help for debugging and knowing why states have changed when triggered by a PSP script:

Turned on triggered by PythonScriptsPro script: turn_on_lights.py

Alternatively, if there was a way to know what HA script or automation called the PSP script then the logbook context could state this, and would be similar to how it shows when HA native scripts or automations change a device's state:

Turned on triggered by automation My Automation triggered by state of My Device Attribute

Another thought is maybe even optionally surfacing a context kwarg in the service call to allow this context description to be customised by passing a string in?

On the face of it, it sounds like a similar thing that was run into for the pyscript integration:

https://github.com/custom-components/pyscript/issues/50

https://github.com/custom-components/pyscript/commit/d0745ea200dc966aa089cf6d7e5638ee7f94d631#diff-35f81a73bbe8c0273529be5bdce6d1fed5f3efd7e1d14877b0c88dabe41f0f26R175-R180

jmot205 avatar Feb 13 '24 13:02 jmot205

After some thought and after switching over a whole bunch of my automations that set the states of various lights from the built-in light service calls to a PSP script, I think that, if possible to implement, the above option of mimicking the HA default logbook entry might provide the most clarity in terms of knowing why the state of an object has changed:

Turned on triggered by automation My Automation triggered by state of My Device Attribute

jmot205 avatar Mar 07 '24 06:03 jmot205