It’s basically two rules in one.
- React to the
power
level of the device changing and set a variable accordingly
- React to the variable staying in ‘Low Power Cycle’ for three minutes (eg. device
power
is less than 3 for 3 minutes) and announce a message
Triggers and Event Type Condition
In the Triggers, we’re basically saying that the rule will be triggered anytime the plug power
changes (above 0) -or- if our variable is a certain value for 3 minutes.
The key part here is that the first IF Condition in the Flow checks what type of event we are receiving.
This takes advantage of something called Context Variables which provide more information about the event that triggered the rule
Based on the Triggers section, we know that we have two types of events that can trigger the rule:
So the IF condition is basically saying that if it’s triggered by a device
(eg. the power changing), then take the THEN side of the flow… otherwise we know it must be the variable (which was set to low for 3 minutes) so we take the ELSE flow.
Note that if you use a virtual device to track the running state (instead of a variable), you would need to use a different context variable since the type of both triggers would be device
. For example, you could use $context.event.deviceName
to differentiate between the events.
So from there onward, the left side of the IF Condition is basically a rule around the device changes (first trigger)… and the right side is a rule related to the variable staying low for 3 minutes (second trigger).
Then Side of Main IF Condition (Device Changes)
On the left side, we’re again using context variables to get details about the event that triggered the rule… but this time instead of checking the type
, we’re checking the value
which triggered the rule.
So if the power
(via the $context.event.value
) is greater than 60, then we set a $laundryStatus
variable to ‘Running’ so we can track the state.
Otherwise if the power is not greater than 60 (eg. the Else branch within this section), then we add one more check to see if the value is less than 3. If it’s less than three, then we set the $laundryStatus
value to ‘Low Power Cycle’.
If you recall, the second trigger for this rule is the $laundryStatus
variable staying ‘Low Power Cycle’ for three minutes and that will take us into the ELSE condition of the main flow (next section).
Else Side of Main IF Condition (Variable Stays)
The last part of this is the Else side of the main if condition which checks which type
of event we’ve received. If you recall from further above, we know that if the type is not device
, then it must be the variable
since those are the only two types of triggers we have in this rule.
And since the IF condition already applies a set of conditions (eg. the $laundryStatus
variable has stayed the value ‘Low Power Cycle’ for three minutes, we know that our condition for sending the notification / announcement is already met.
So the Then side of the main condition is basically just resetting our $laundryStatus
variable to Stopped (in case we use it on our dashboard or somewhere else), then proceeds to trigger an announcement on an Echo Device using Voice Monkey.
James linked to a nice video by Justin from SimplySmart explaining how the last action is working, but Voice Monkey is basically a service that can play announcements on an Echo Device. So this step uses the HTTP Action to trigger a Voice Monkey Announcement.