I have an issue where my TV takes some time before it opens its HTTP endpoint so I can’t run youtube right after I turn the TV on.
This translates in to this in the logs:
Error executing service <ServiceCall rest_command.play_youtube (c:e9122d1df57f414c9ab3e0fdac988b05): video_code=I97Qr7V_gaA>
…
ConnectionRefusedError: [Errno 111] Connect call failed (‘192.168.1.72’, 80)
My question is how do I figure out in a script that a service call failed and then I can run another delayed one to solve it (I know the last bit just not how to check for results/failures).
I don’t think that’s possible with the current architecture. Services don’t have return values which can be used for further processing. At least the last time I checked services are fire and forget.
It’s a bit involved but what I would try is, use a python_script to set a state in the state machine to working. Then use a shell_command to run an external python script to turn on the TV. It can do the retrying if necessary. Then when it’s done it can use HA’s REST API to change the state in the state machine to ok or failed. Meanwhile the automation or script would have used a wait_template to wait for this state change and use the new value to see if it worked or not.
If my suggestion seems interesting, and you’d like to give that a shot, let me know. I’ve already implemented pieces of such a solution that I could provide as reference. Or if you’re not up to implementing something like this, I’d be happy to lend a hand.