Variables for Rules and Dashboards!

We’re excited to announce the next SharpTools.io release which brings basic support for Variables to SharpTools! :tada: Variables are a neat way to store custom values that you can use in Dashboards and the Rule Engine.

:crown: Variables are a Premium only feature.
If you are using the free tier, please let us know if you’d like us to reset your trial.

Supported variable types include:

  • Text
  • Numbers
  • True/False

Variables in Rule Engine

The Rule Engine includes support for Variables in the following features:

  • Event Triggers: when a variable changes or stays a value, trigger a rule running
    • You can also use a Variable in a Device event trigger comparison!
  • IF Condition: compare a variable value to a static value; or compare a device value or location value to a variable
  • Action: Set Variable: change a variable value to a manual input (static value), device value, or location value as part of a rule flow
  • Action: Send Command: use a variable as a parameter in a Thing Command

These features make for some really neat use cases! For example, you can use a single variable to trigger multiple rules simultaneously. Or use variables to set conditions as to what set of actions occur (or if the action will occur at all).

And because variables can be viewed / set from dashboards, this makes for some really powerful tools for integrating dashboards and rules!

Variables in Dashboards

We’ve included support for Variables in dashboards which provides a neat way to use variables on their own or along with the SharpTools.io Rule Engine.

The video below shows the result of the rule shown in the screenshot above. When the myFavoriteColor text variable is changed, the rule automatically adjusts the isFavoriteColor true/false variable accordingly.

Also pictured in the Number variable tile with the optional ‘Quick Adjust’ setting enabled.

https://imgur.com/Vg69lns

Note that the standard security features apply here as well, so you could easily restrict variables to being Read Only or PIN protected. Similarly, the tiles support features like Colors/Labels and the True/False tile acts much like a Switch tile in that you can map different icons and colors for the different states.

Other Enhancements

Help Article

4 Likes

Examples

This enables some really neat capabilities in rules - here’s a few examples:

  • Set a $volumeLevel variable from a dashboard and have it set the volume level of multiple speakers to the new level
  • When motion is detected, take a snapshot of the current dim level, change to a desired level, then reset the light back to the ‘snapshot’ level
  • Use a true/false variable as a condition for determining if a static value or a stored variable should be used for setting the dim level
    • eg. IF $isPartyMode THEN setVolume($partyLevel) ELSE setVolume(5)
  • Use variables to ‘aggregate’ the status of multiple devices in place of virtual devices
  • Use a variable to dynamically change the threshold of an IF condition
    • eg. Change the threshold from the dashboard and the IF condition in a rule will use that value for a comparison - for example, when you want to fine tune a temperature threshold

Screenshots

Here are a couple screenshots showing where to toggle the static input or variable in the Trigger/IF_Condition and Device Command.

2 Likes

Hi Josh and James,

Just started playing with the variables and they are awesome (the ability to set them directly from the dashboard - genius!!)! I went through the overview of variables and, as I was adding them to my dashboard, I noticed that the tile editors for number and boolean variables don’t have an option to set the size of the content and the content shows up way too big on the tile itself. I have posted a couple screen shots showing the layout of the tiles and the tile editor. There IS an option to “enable quick adjust” but I’m not sure what exactly that does. It’s very possible that I could have missed something along the way but wanted to check before adding a bunch more variables to the dashboards.

Thanks!!
Screen Shot 2020-05-12 at 10.07.59 PM|690x421


Thanks for the feedback, @Brett_Crawford. It looks like the autoscaling isn’t being applied to the new Variable tiles as expected.

Edit: I just pushed out an update which enables the autoscaling on the new Variable tiles. Can you refresh your dashboard and give it a try? (Note that if you reduced the Main Content Size on the Text Variable tile, you’ll likely want to make it bigger now that the autoscaling is in place)

Hi - just started using Sharptools and really like the addition of variables. Another simple use case for variables is a simple multi-state button using a variable tile with $runRule and a rule that moves from state to state with each execution (caused by the variable tile).

I think a nice enhancement would be the ability to add a variable to certain string values. The example I have in mind is adding a speaker selection to a Echo Speaks search parameter, i.e. ‘Pink Floyd on $SPEAKER’ or even better combine, ‘$ARTIST on $SPEAKER’… I think this would open up a look of cool possibilities.

Thanks!

2 Likes

That is a really neat concept.

If I understand correctly, you setup a variable to hold a value (for example, a Text variable). Then you display that in your dashboard and change the action to Hyperlink and use the special $runRule syntax. And the rule that you run cycles through various predetermined ‘states’, updating the variable to the next state on each run of the rule.

Brilliant idea!

That is correct… I did it for echo device/groups… ex. Kitchen, Downstairs, Everywhere. So the rule is just if/then statements that move you through the states. Then a variable tile button with .runRule, runs the rule and changes/displays the state. For my purpose, it is just a variable changing so far, but you could also add things like device control - like cycle a light through OFF, 25%, 50%, 100%, etc.

1 Like

Love the Content Size option on the Date Tile! I hadn’t found this 'till today. It’s perfect!

2 Likes

Is it possible to save the names of several devices to a variable? Trying to figure out of I can create a variable that displays a list of open windows in our house.

1 Like

Not at the moment, but I’ve noted the request.

1 Like

Is it possible to use a variable in the URL field of a media item by chance?

Is this in context of your post in the Hubitat Community around changing the dashboard background dynamically? I’m trying to better understand the use-case so I can properly document the request. :slight_smile:

Yup, you’re on it! I’m having trouble figuring out how to serve different images at an endpoint of my hub, so just figured I would see if Sharptools variables would provide an easy solution. If I could set a Sharptools variable to mirror a string field of a device, and then use that variable as the URL of a media item, it would work to dynamically change the dashboard background.

1 Like

I know this is from a few months ago but I have a similar issue. Have a variable pull weather forecast from ST Weather Tile. However the difference between content size 1 and 2 is HUGE. See image:

Hello, taking you up on your offer to help with variables :slight_smile: I am trying to figure out how to “emulate” a while statement from Webcore to Sharptools… But I can’t seem to get the logic or process correct as I am learning about variables, etc. Here is the example (real case).

I have a Thermostat and I want to be notified if the temperature goes above say 75 degrees. I can make this work and get an SMS message. HOWEVER, the next step I want which was accomplished with a while-loop is this. Same example, I want to be notified if the temp goes above 75 deg AND I want to wait (or delay say 10 minutes - which I can also do) and then be notified AGAIN. In the while-loop I would say, while the temp is above 75 deg notify me, wait 10 min, then notify me again if above 75 deg, wait 10 min and do again… You get the idea. But without a while statement I don’t know how to keep TRIGGERING this to happen. Thanks very much? Another very similar example is, If it is past 11pm and the garage is open, then notify me. Again I can get this to work… but I want to keep getting notified if no one shuts the garage after 10 min or so… I can’t figure out the trigger to continue the rules without WHILE statements… Thanks Alan