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 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.

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

  • $.runRule("RuleID") syntax in Hyperlink enabled tiles
  • Added transparency option to Day of Month tile (reference)
  • Added day of week format to the Date tile (reference)
  • Added Content Size options to the Date Tile

Help

We understand that variables can be difficult to get your head wrapped around, so please feel free to ask questions here or send them to support@sharptools.io

If you have any specific use-cases that you think variables could help with, but you don’t know how to accomplish it, feel free to post it and we’ll do our best to help you out!

Also be sure to reference the 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!

1 Like

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.

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