Can you change an actions' conditions with an analysis?

Hello,

I have this dashboard:

Currently my device reads data every 3 minutes, and depending on temperature, will trigger an action to push a notification. The temperature threshold is adjusted using a form that runs an analysis to adjust it in the bucket.

Currently I expect that I will need 2 analyses to run every time the device sends data, one for the open/close widget and one to compare the temperature to the threshold and push the notification. But I would like to reduce this number in order to not have to run 60 analyses every hour.

Lets say I also have this action:

Is it possible that whenever I change the threshold from the dashboard that in the analysis, to also change the conditions in the above action to match those of the threshold? Say if I change the threshold from the form to -16, then the analysis should also change the action to this:

That way I would not need to run an analysis to compare the temperature and the threshold and instead directly compare the temperature to the number in the action.

Also, I doubt it is possible, but is there a way to handle the open/close widget without using an analysis? The color metadata are not important to me by the way.

Thanks in advance for your help.

Regards,
Nicolas

1 Like

Yes. You can create, edit and delete actions through analysis.

https://js.sdk.tago.io/classes/actions.html

It is quite confusing to understand how action structure works. I recommend you to get a info of a existing one and try to edit it. If you have any question, please feel free to ask.

Regarding the Open Close widget, I’m not sure what you’re doing in your analysis. Are you just changing the value to a human readable format ? If it is so, you can use the formula option in the widget. It should have some examples there for you to try.

The Opened/Closed analysis checks if the temperature is above or below the threshold and updates the variable in the bucket. Above gives Opened and below gives Closed.

I put it in an analysis instead of the decoder because the decoder doesn’t know what the threshold is, since it depends on the user. If there is a way to do this with formulas then I will give them a go.

1 Like

Is there an example anywhere for editing actions with an analysis?

1 Like

We actually have a tutorial on hold, that were waiting for the blueprint distribute to be available. Let me check if it needs update, I’ll paste the link here.

It is available here: How to create Actions from a dashboard - How to - TagoIO Community

2 Likes

Hello @vitor,

I am a bit confused on how to push the changes in the analysis to a pre-existing action.

From the example analysis, if I understand correctly you add the fields of the action to the bucket of the device and then make changes by pushing them to the bucket?

So if I have a pre-existing action, what is the command to push the changes to it. Or do I have to create the action from the dashboard to be able to edit it?

Also considering the only thing I want to change are the values of the lock and unlock conditions, is it fine to just change those. Or are there other fields that are mandatory to be also included (like variable,condition etc)?

image

1 Like

The example I sent you do perform several features:

  • It stores the Action parameters as data inside a Bucket. This is because to show something in a Dashboard, it need to be inside a bucket.
  • It does have Create, Edit and Delete proccess inside the Analysis related to the Action.
  • It understands all commands performed by the User when editing the Dynamic Table, Deleting a row and receiving the data form the Input Widget.

For editing an existing action, check the function editAction at line 35.
You will want to use the function await account.actions.edit(action_id, action_info) to edit your action.

Since you’re editing the trigger, you need to check the Action Structure at line 104.

  const action_structure = {
    active: true,
    name: `Action trigger ${device_id}`,
    tags: [],
    type: 'condition',
    trigger: [
      {
        is: action_condition.value,
        value: String(action_value.value),
        value_type: 'number', // This analysis presume that the value is always a number. You can improve this by yourself.
        variable: action_variable.value,
        device: device_id,
      },
      {
        is: action_unlock_condition.value,
        unlock: true,
        value: String(action_unlock_value.value),
        value_type: 'number',
        variable: action_unlock_variable.value,
        device: device_id,
      },
    ],
  };

The trigger need to be send with all it’s parameters. The scripts does show how to do this very easy by getting the action at line 49 and then editing it at line 72

2 Likes

Hello @vitor,

I have another question regarding the above dashboard. It is possible to change a specific widgets’ color conditions through an analysis?

Say for example, the color conditions on the temperature widget are greater than -5.99 for orange and less than -6 for blue. Those conditions are manually changed whenever I change the threshold.

So if I change the threshold to -10 and the analysis to change the threshold triggers. Is it to possible to switch the conditions to greater -9.99 for orange and -10 for blue in that analysis?

Thanks in advance for your help.

1 Like

I believe you would find easier to edit your data, by deleting it and adding back again to the device, adding the { metadata: { color: "red" } } to your data.

If you want to change the color conditions inside your widget, you can do that by analysis, but you it is a quite expensive work to do. You would need to understand the JSON of your widget, which you can do by clicking in the three dots of the widget in edit mode, and then copy the JSON structure.

Then you build your analysis editing the specific fields related to the color of the widget. You can edit a widget as described in the SDK documentation: Dashboards | TagoIO SDK for JavaScript and TypeScript

account.dashboards.widgets.edit(dashboard_id, widget_id, widget_json);