# Resolution Logic for Time Series Node

**URL:** <https://forums.losant.com/t/resolution-logic-for-time-series-node/2219>\
**Category:** Help\
**Tags:** workflow\
**Created:** [September 26, 2019, 2:10pm UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219 "2019-09-26T14:10:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Kondrov](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/alexander_kondrov/32/1392_2.png) [@Alexander\_Kondrov](https://forums.losant.com/u/Alexander_Kondrov)\
**Post date:** [September 26, 2019, 2:10pm UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219/1 "2019-09-26T14:10:29Z")

</div>

Hello Losant Team,

I built a workflow with a Time Series Node and the following settings:

- custom time range
- range end/duration defined by payload values
- Aggregation - None

With such settings, Losant automatically puts resolution property to 1 minute and does not allow me to change this setting.

This setup works good for ranges less than a few days, but for a range of a few months 1 minute resolution seems to be small. In other words, it takes a while for such volume of data to be transferred to the front-end.

Is there a way automatically change resolution setting depending on duration value on the fly?

---

<div class="post-metadata">

**Author:** ![JuliaKempf](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/juliakempf/32/2446_2.png) [@JuliaKempf](https://forums.losant.com/u/JuliaKempf)\
**Post date:** [September 26, 2019, 3:06pm UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219/2 "2019-09-26T15:06:08Z")

</div>

Hi @Alexander_Kondrov,

The reason this is blocked out is due to your Aggregation being set to none. It is not necessarily locking at 1 minute, it is returning every state reported in your selected time range, as the data is not being aggregated. If you toggle Aggregation to something other than “None,” the Resolution should become configurable; would an aggregation of something other than “none” work in your use case? 😄

Thanks!  
Julia

---

<div class="post-metadata">

**Author:** ![Alexander\_Kondrov](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/alexander_kondrov/32/1392_2.png) [@Alexander\_Kondrov](https://forums.losant.com/u/Alexander_Kondrov)\
**Post date:** [September 26, 2019, 4:19pm UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219/3 "2019-09-26T16:19:32Z")

</div>

Hi Julia,

Thank you for the prompt reply.  
It does work and doesn’t at the same time. So, far I’ve changed the aggregation setting from None and divided flow to three different ranges (bigger time range - \> bigger resolution). It looks a bit bulky. It would be nice to have a resolution settable by a payload value as well in the future.

![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/f/fc504bb241d2f2b830eb495901d2377a25ef0d75.png)

Another question came up in addition. Is there a way to use Switch Node for value ranges. I.e. define path depending on X\<1; 1\<X\<2; X\>=2 ?

---

<div class="post-metadata">

**Author:** ![JuliaKempf](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/juliakempf/32/2446_2.png) [@JuliaKempf](https://forums.losant.com/u/JuliaKempf)\
**Post date:** [September 26, 2019, 6:21pm UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219/5 "2019-09-26T18:21:20Z")

</div>

Hi @Alexander_Kondrov,

Yes, I see what you mean, it is a bit bulky! You might benefit from using the Losant API Node in place of the Data: Time Series Node. You can use the [Data: Time Series Query](https://docs.losant.com/rest-api/schemas/#time-series-query) resource, which allows for a more advanced configuration.

 ![55%20PM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/5/5d31a403ca9c3eff8c9f2c8379a942f798a462f0.png)

This means you can configure the options in a JSON Template, so you would be able to pull a value from your payload for the resolution. The query would look like so:

```auto
{
  "end": 0,
  "duration": {{data.duration}}, /// these are my payload values
  "resolution": {{data.resolution}},
  "aggregation": "MEAN",
  "attributes": [
    "voltage"
  ],
  "deviceTags": [
    {
      "key": "floor",
      "value": "8"
    }
  ]
}

```

For the Switch node question, I had never actually tried this myself, and since my first couple ideas didn’t work out so well, I think this would be an excellent feature request and have put it into our system. The solution that _did_ eventually work was a Function Node and a Switch, and it should help to decrease your number of nodes. I set up my workflow like so:

 ![17%20PM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/1/17dca08ad8f7effadb8bb96022ca8283bb171402.png)

The value is stored on my payload at `data.x`, and I do my conditionals in my Function Node, putting a string value on the payload for the case that is true:

```auto
if(payload.data.x<=1){
  payload.data.result="less than one"; // Creating and setting result on the payload
}
else if(payload.data.x>=2){
  payload.data.result="greater than two";
}
else{
  payload.data.result="between one and two";
}

```

Over in my switch statement, I use my new `data.result` value to determine which path to take:

 ![27%20PM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/2/2ebec3aad4b1a485d67085bda4c4e51eb5753c8e.png)

I decided to take the Function Node route as it will make things easier if your conditionals were to grow in number, or become more complicated. I have created a feature request for expression based switching, and will update you in the future should that become available.

Let me know how else I can help!  
Julia

---

<div class="post-metadata">

**Author:** ![Alexander\_Kondrov](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/alexander_kondrov/32/1392_2.png) [@Alexander\_Kondrov](https://forums.losant.com/u/Alexander_Kondrov)\
**Post date:** [September 30, 2019, 3:46pm UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219/7 "2019-09-30T15:46:22Z")

</div>

> [@JuliaKempf](#):
>
> take the Function Node route as it will make things easier if your conditionals were to grow in number, or become more complicated. I have created a feature request for expression based switching, and will update you in the future should that become available.
> 
> Let me know how else I can help!

Julia,

Thank you for your reply. I will consider using Losant API Node for a configurable resolution setting, I need to learn more about it first from Losant docs, though.

Regarding Function + Switch approach, I was thinking about it as well, but it would complicate later debugging maintenance. Therefore, I will wait until this is implemented as a standard feature.

---

<div class="post-metadata">

**Author:** ![Alexander\_Kondrov](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/alexander_kondrov/32/1392_2.png) [@Alexander\_Kondrov](https://forums.losant.com/u/Alexander_Kondrov)\
**Post date:** [October 23, 2019, 11:54am UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219/10 "2019-10-23T11:54:08Z")

</div>

Hi @JuliaKempf, I would like to ask an additional question about using Losant API Node for retrieving time series data. I followed your advice and tried to implement Losant API Node with Action “Data: Time Series Data”. I didn’t find the exact example in the docs, and that’s what I put to the JSON Template field of the node, basically repeating Data: Time Series Node settings:

```
{
"aggregation":"MEAN",
"attributes": [
  "name_of_a_custom_attribute"
],
"end":{{path_to_end_number_in_ms}},
"deviceIds":[{{path_to_losant_device_id}}],
"duration": {{path_to_duration_number_in_ms}},
"resolution":60000,
"deviceTags": {}
} 

```

This gives me a error.

Could you help me to detect missing/wrong fields please?

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [October 23, 2019, 11:57am UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219/12 "2019-10-23T11:57:24Z")

</div>

@Alexander_Kondrov,

Hi! Could you provide the error you’re getting?

---

<div class="post-metadata">

**Author:** ![Alexander\_Kondrov](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/alexander_kondrov/32/1392_2.png) [@Alexander\_Kondrov](https://forums.losant.com/u/Alexander_Kondrov)\
**Post date:** [October 23, 2019, 12:06pm UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219/13 "2019-10-23T12:06:37Z")

</div>

Hi Taron,

![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/4/49235b6577af19544a929b220c43052863eec3a1.png)

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [October 23, 2019, 12:13pm UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219/14 "2019-10-23T12:13:11Z")

</div>

@Alexander_Kondrov,

Ah, I think I see the issue. You need some quotes: `["{{path_to_losant_device_id}}"] `

However, when templating string objects you can always do this:  
`{{jsonEncode path_to_losant_device_id}} `

`jsonEncode` will automatically parse as a json value. It’s helpful for two reasons:

1. It will add the quotes for you
2. It will escape any thing in the string that JSON doesn’t like. For examples, a `"` character in in the middle of the string that will break things.

---

<div class="post-metadata">

**Author:** ![Alexander\_Kondrov](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/alexander_kondrov/32/1392_2.png) [@Alexander\_Kondrov](https://forums.losant.com/u/Alexander_Kondrov)\
**Post date:** [October 23, 2019, 12:35pm UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219/15 "2019-10-23T12:35:33Z")

</div>

Taron, I am checking both of the options for deviceID you provided. So far, the behavior changed indeed.  
Still getting the following validation error though…  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/4/477400090aab3d4e8f0e1ef5a7b022b11bbedcae.png)

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [October 23, 2019, 12:39pm UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219/16 "2019-10-23T12:39:11Z")

</div>

Sweet! Different errors mean progress. 🙂

This time, the issue is that `deviceTags` is supposed to be an array .

You can see the details of that request here: [https://docs.losant.com/rest-api/data/#time-series-query](https://docs.losant.com/rest-api/data/#time-series-query)

---

<div class="post-metadata">

**Author:** ![Alexander\_Kondrov](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/alexander_kondrov/32/1392_2.png) [@Alexander\_Kondrov](https://forums.losant.com/u/Alexander_Kondrov)\
**Post date:** [October 23, 2019, 12:44pm UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219/17 "2019-10-23T12:44:29Z")

</div>

Actually, your solution was good enough. I just needed to delete an empty {} deviceTags property to make it work. Super. Thank you for the prompt response:

PS As a recommendation, it would be useful to extend the example you referenced with settings defined by the payload path, but not only constants, as it is now

---

<div class="post-metadata">

**Author:** ![anaptfox](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/anaptfox/32/873_2.png) [@anaptfox](https://forums.losant.com/u/anaptfox)\
**Post date:** [October 23, 2019, 12:49pm UTC](https://forums.losant.com/t/resolution-logic-for-time-series-node/2219/18 "2019-10-23T12:49:31Z")

</div>

@Alexander_Kondrov,

There are some pending improvements coming to the docs around templating. But, that’s a great recommendation!
