Using Context Variables to assign Dashboard Trend Range Min/Max to Device Attribute Tag Values

Hi.

I am trying to set up a templated dashboard for devices of the same type.
Generally, I have been able to get this to work pretty well with context variables and expressions.

The one remaining area where I am stuck is with Trend Ranges.
Two devices of the same type might have quite different values for the same property… varying a small amount compared to the difference between the average values of the two devices.

This means to dial in the ranges of a trend means the two devices need different range min and max on the trend.

I have been trying to set this up using Attribute Tags… called min and max.

I have two problems…

  1. I am unable the trend block to accept any expressions in the min/max fields
  2. I am unable to determine the expression path to drill into these values… expecting it to be similar to {{ctx.deviceId-0.tags.xyz}} but unable to find the right path and unable to find that detail in the docs.

Can someone please guide me as to how to resolve these problems or suggest an alternative solution?

Best,
Tim.

Assuming this is referring to a Time Series Block? The min and max properties for each segment do support string templates referencing values from your dashboard context.

You mentioned that these are stored as attribute tags, but the example template in your question references a device tag.

If you are storing those values as attribute tags on a device, you first need to ensure that the “Include full device info” checkbox is checked when defining the context variable. Then, assuming the following:

  • Variable name is DEVICE_ID
  • Attribute name is MY_ATTRIBUTE
  • Attribute tag key where the minimum is stored is MIN

You can reference that with the template {{ctx.DEVICE_ID.attributes.MY_ATTRIBUTE.tags.MIN}}.

We do resolve those values when you attempt to save the block to verify that the result is a number (in the case of a min or max on a graph), so if that tag is not defined on the current context value, or it is defined but the value is not a number, that would cause you to be unable to save the block. So what I like to do is provide a reasonable minimum value with the defaultTo helper, like so:

{{defaultTo ctx.DEVICE_ID.attributes.MY_ATTRIBUTE.tags.MIN '0'}}


For a pro tip, something I like to do while developing dashboards is to throw the following into the dashboard description (minus the \ characters, which I had to add to escape this):

\```
{{jsonEncode . 2}}
\```

This will throw a block at the top of the dashboard showing the full templatable context, which is very helpful while developing.

Once again, Dylan, you’ve nailed a fix for my problem. Thankyou.

I was, indeed, talking about the time series block… and the reference you provided was exactly what I was looking for…
I really did try to find that in the help… I found material close but not quite this specific… and I guessed close but not close enough!
If you have a link to where this is in the doco, I’d appreciate it to fill in knowledge gaps.

Really appreciate the extra tips too, regarding “defaultTo” and “jsonEncode”… I have used both techniques already.

Best,
Tim.