I have a problem, well my family has a problem. We can’t shut the freezer door. Regularly (once a month) our freezer would be left open just enough to defrost but not enough to sound the audible alarm, resulting in squishy food.
To combat this, I bought myself a Sonoff TH10 temperature sensor and configured this to send me an alert when it reached a certain temperature. The problem is I became blase to the alert, as it would go off as soon as someone opened the door or was not around to react. The module would only alert me once, when a warm temperature was reached, not keep reminding me or escalate to someone else when I didnt react by shouting at a teenager to close the door. So how could I ensure it alerted me less frequently and also alert the rest of the family when there was a real issue?
I know that this article is a little bit of fun with no real business benefit, but using Flow to fix a problem in my life is worth talking about. Everyone will have a little annoyance that Flow can help with, and it acts as a training exercise for us all.
As with all problems, starting with a flow chart helps. This is what I need to achieve. The Sonoff device is configured to turn on and off when a certain temperature is hit. IFTTT is triggered by Sonoff on both of these conditions.
When the hot temperature is hit, wait 30 minutes (to allow for the temp change when a door is opened and closed naturally) then check if freezer is still is over temperature. If it is still hot, send out a notification.
Then, wait 60 minutes now and check again if the temperature is too high, before repeating the loop, sending out a further notification and waiting 60 more minutes.
If we check the temperature and it is now back down to cold, stop the process.
If you don’t know the IF This Then That, it is a great service to interact with disparate systems, a point-to-point integration to do something on a trigger. I have used it previously to log Sales users calls from an android phone and I use it to change my phone’s background with the NASA wallpaper of the day. It is a free service which plugs the gaps where Flow does not have direct connections, such as with the Sonoff device.
Sonoff can trigger IFTTT, which in turn can trigger a web service, triggering the Flow.
Log into IFTTT and link your account to eWeLink (this is the app you install to manage the Sonoff switches).
Select Create from your account
This presents you with the standard IFTTT applet creator.
Hit the big + to display all the available services, eWeLink should be on that list.
Next, you get a long list of the options eWeLink make available for you, this is where you need to select the appropriate switch, for me just a single channel switch.
Next step is to select your switch, named by you when you configure it in the eWeLink app, and whether you want this to be triggered when it is switched On or Off. For me, On means that the Freezer has gone below -20 ° C. Off means it has gone above -17 ° C.
IFTTT then needs to know what to do.
Hitting the big + again lists the action services, the one we want is a WebHook.
Next, the action requires a URL, which is from our Flow, so skip to that bit to get the URL, we aren’t posting anything to this hook, just a trigger. You could secure this a little more to pass in a key to know it is you that is triggering it.
Our flow starts with a web trigger.
I am passing a delay to the trigger, though the initial call will not have any delay.
Next, initialise a variable for checking the freezer later as well as an ID for the SharePoint Item I will create later.
If this has come from the initial IFTTT trigger, then we assume the delay is 30 minutes. You could just update a delay variable, but as you will see, I want to do something different if I am passed a delay, the second time we call it.
In the yes branch, we now wait for the default 30 minutes.
Cancelling the Flow
Now, according to our design, we need to check the temperature to see if it has dropped back below our trigger point.
Ideally, you would call the Sonoff and ask for a reading, and I am sure more expensive IoT devices allow you to do this, but I am cheap. The Sonoff and eWeLink interfaces allow you to look at the temperature on your phone, but do not broadcast the temperature out to anyone apart from the App, just the on / off trigger. Checking the temperature is not an option.
What about creating another trigger to turn off this looping? Unfortunately, this isn’t possible; there is an idea on the flow community; you can vote for here. I would also like to be proven wrong, reach out if there is a way to cancel a flow run.
I started doing this by adding a file in a Google drive location (it could be SharePoint or OneDrive but wanted to expand my use of connectors) when the temperature went down, but this was inconsistent. I ended up getting multiple emails as the file create did not happen every time. I am sure I could sort this out, but wasn’t really the point of the flow.
I ended up with creating an item in a SharePoint List when the flow was first triggered, complete the delay and check this item to see if another process has updated the same item while I was in pause mode. If that item has been updated, just stop the Flow. If it hadn’t send the email alert and trigger the flow again, to repeat the process.
First, create the item in SharePoint, with the current time (this is just for my interest, knowing how many times it triggers the freezer temp)
The Id of the item that is created is copied so we can pass it to the next iteration of the flow if needed.
After the delay, check the item that was created for a cold temperature. Using a bit of odata filtering here to only return the item that was just created and only if there is no cold time.
This Scope useage is only to allow me to copy the contents to the other branch, saving me time. The copy function is really useful, if you havent seen it, why not?
Next, if any items are returned (the item that was created was updated with a cold temperature), the title is changed to Cancelled. This is not really needed, but gave me something to do in the apply for each. The boolean is set to true, meaning Freezer is now cold and this flow can cancel itself.
Out of the loop, check the value. If the previous loop did anything, it will be true, if not false. If the freezer is now cold, just terminate gracefully. If it has not updated the temperature, let it fall through to the next action.
The final part of the original check to see if it sent a delay count is to email. In this no delay sent path, an email is just sent to me. I am using Gmail here, just because it was a new connector.
Finally, call the same flow but pass in the delay we want and the Id of the SharePoint item that was created.
What about if it gets really serious?
Telling me if the freezer has been open is fine, it usually results in a yell to a teenager to shut the f**king door. What about if I am not in?
After the first 1/2 hour delay, if the freezer is still showing hot, I need to escalate, for me means emailing my whole family. In the No branch, I delay for whatever value was sent in, set a variable to pass on to the next iteration and do the same code as in the other branch, the difference is that I include more people on the next email.
Here, I email all my family, with a nice in your face subject and also hike up the importance. Hopefully, they won’t ignore this email like they ignore me.
Triggering when it is cold
Using IFTTT the same as I have done early on, if the temperature hits -20 ° C, the second trigger is fired. This updates any items it finds in the list without a cold temperature with the trigger time
And that’s it.
In my inbox, after I have taken the temperature controller out of the freezer for a little while, I get a series of Freezer is hot messages, also sent to the rest of the family.
Once it gets back in, the notifications stop.
And in SharePoint, there is a list of the hot & cold triggers, from natural door opening, thankfully