Error when HA calls pyscript after pyscript has already been terminated during shutdown?
Hi, I have a time pattern triggered automation running in HA that calls a pyscript service every 10 secs. When I restart HA, I get the following error message after HA started again but the error is triggered at shutdown time, not when HA started!
Automation A uses an unknown service \
The automation "Automation A" (automation.automation_a) has an action that calls an unknown service: pyscript.my_pyscript.
This error prevents the automation from running correctly. Maybe this service is no longer available, or perhaps a typo caused it.
To fix this error, [edit the automation](http://192.168.x.x:8123/config/automation/edit/xxxxxxxxxxx) and remove the action that calls this service.
Click on SUBMIT below to confirm you have fixed this automation.
So it looks like the HA time trigger triggers the automation at least one more time after pyscript was already terminated?
Is there a way to prevent those errors?
Thanks!
FYI: I solved this with a workaround. I.e. I am not using a time pattern triggered automation running in HA to start the pyscript, but I use @time_trigger('period(now, 10s)') in pyscript to trigger the script every 10s. It works just as well, but I had a few other things besides calling the pyscript in the automation, but I can of course do them separately without calling the pyscript. I leave this open though, since it would be good to know if one can test from HA if a pyscript is actually available. E.g. something like a template condition {{ pyscript is defined }} or {{ pyscript is not none }}.
To confirm, you were originally triggering the service call from HA, not pyscript? It sounds like the problem is outside pyscript. pyscript shuts down in an orderly manner (including unregistering services etc) when HA is shutting down, and it appears the automation trigger happens after shutdown.
Moving the periodic trigger to pyscript sounds like a good solution. It will get shutdown at the same time as the rest of pyscript.
@craigbarratt yes, exactly, it looks like HA still calls the pyscript service after pyscript shut down and unregistered its services and therefore gives the error. Moving the trigger to pyscript is perfectly fine. I was just wondering if there is a way from within HA to check if pyscript services are available?