Custom attribute changes from "x" to "y"?

I have a device with a custom attribute that I want use as a trigger.

Attribute: cleanStatus

States: charging, cleaning, docking, idle

I want to use a change of state from cleaning to docking and change of docking to charging as triggers. Is that possible?

All three changed as the rule trigger. Then you need those attributes as conditions.

IF A then do this
Else IF B then do this
Else IF C then do this
End IF

Rule Machine doesn't have a built-in way to only trigger if something is changed from something to something else. I don't see anything in either suggestion above that handles this specific requirement, unless I'm missing something. However, as is often the case, conditionals in the "Actions" section can come to your rescue:

  1. Create two local variables of type "string," say lastState and currentState. The former will track, as my suggested name implies, the previous value for use in the next execution of the rule. The latter is necessary because there are limited ways to directly use the current value of an attribute, and this helps with that.

  2. Use a "changed" trigger for this attribute on your rule (that way, the last state is always captured).

  3. Create an actions section that looks something like:

    Set currentState to MyDevice cleanStatus
       IF (lastState is "cleaning" AND currentState is "docking") THEN
        Do things
       ELSE-IF (lastState is "docking" AND currentState is "charging") THEN
         Do things
    Set lastState to currentState

(The first action isn't clear from the above, but it sets a variable to a "Device attribute," an option you'll get from the menus when you go that far.)


Since it's a simple robot I assume it's always going to do things in the same order, but that's a really smart way to do it if that's not the case. :+1:

This is what I was after! More complex that I thought but I'm up for the challenge. I'll be sure to report the outcome.