Shelter-in-Place Journal, Day 192

I’ve been using Indigo for home automation for a couple of years. I haven’t written my own plugins yet (and I hope to avoid doing so), but I have created a few Python scripts to run inside Indigo, and I have set up some fairly complicated trigger/action combinations. So I didn’t expect to have any problems adding a daily Action Group to send the weather to Diane and me.

The Action Group was pretty simple:

Step 1: run a Python program to create the message (combining information from several sources) and write it to a persistent variable in Indigo,

Step 2: send a message with the contents of the variable.

But I kept getting a message with old data – data that had been captured from the previous execution of the action. I added code to the Python program to make sure that the variable was being set properly – it was. I even added a sleep to the Python program to make sure that the new value of the variable had time to propagate – no dice.

I was very confused. I had to take desperate measures: I looked at the online documentation. And there, I discovered that Indigo runs all of the steps in an Action Group in parallel – so the message was being sent before the Python script had had the chance to update the variable. The fix was simple – add a five-second delay to the second step. That’s not five seconds after the first step ends – it’s five seconds from the time the entire Action Group starts.

I’ll have to look at all my other Action Groups and see if I’ve fallen into this trap elsewhere; I suspect that I have, because sometimes, things don’t wind up in the state I expect, and race conditions might well be the cause.