As ST now has official support for the FP2 I’m trying to set a rule for when a zone gets triggered, but SharpTools doesnt see any zones, it just gives me a JSON thing, do I have write some code for when a zone has motion?
What other attributes are available for the FP2?
It looks like the zoneState
is some sort of special attribute format – as you mentioned, it looks like it’s potentially reporting some sort of JSON value.
I would recommend adding that attribute as a Hero Attribute to a dashboard or as a Trigger to a rule and then monitor the attribute values as they change to see what it reports. Then you can monitor it manually by:
- Open your SharpTools User Page
- Tap the
...
next to the location in question - Scroll down and tap the device in question
- Monitor the Attribute Values section
Note: The device + attribute must be added to a dashboard or rule trigger for it to receive status updates.
@josh I am having trouble getting if conditions based on the attribute value to match. I have copy/pasted from the Attribute Values from the User Page, Location, Device as you mentioned above into my rules and it’s not matching the if condition and moving to else instead.
Any tips you can suggest? I also have the device and attribute shown on a dashboard and those update accordingly when I enter either of the 2 zones defined by my sensor.
The attribute for my 2 detection zones shows as follows:
[ { “id”: “1”, “name”: “Master Shower”, “state”: “not present” }, { “id”: “2”, “name”: “Master Bathtub”, “state”: “not present” } ]
I want to match that exactly to turn off my exhaust fan, but the if condition match is failing despite copy/pasting that into the JSON field.
Does the device driver also create those zones as child devices? I thought I read something about that when I did a quick search a few days ago.
If not, I would consider setting up a rule that listens for any change in the attribute, then use an expression to parse out the JSON and store each zone as a true/false variable.
Then you can use those variables to directly react to the zone statuses changing as needed.
They are not child devices.
I’ll dig into the method you described.
@josh Can you give an example of parsing the JSON of the device attribute value? I read through the expressions and functions examples, but I’m not seeing how to tell the expression to search the value of the device attribute for a specific string to allow me to set the variable.
If it’s a raw object passed across from SmartThings, you would access the object properties similar to JSON notation with any language:
object.property
object[index]
So in the case of the context variable for the event value:
$context.event.value.someProperty
$context.event.value[0]
So maybe something like:
equalText($context.event.value[0].state, "present")
—-
That still looks above my ability. For my use case, I don’t need status of both zones, just if one is active or neither is active, so setting a text variable to the trigger context variable and using that text variable to set true/false variables, I was able to get it to work.