Device Filter/Search Widget

Hello there,

My client wants to obtain many different business analytics from the data sent to Ubidots. One example is this:

  1. Of all the devices, show only devices with a “City” property = “Mesa”. I will then compute the total performance for the devices that were not filtered out and how much revenue each device made. Then display totals for all those devices. Most of these metrics are computed based on the devices variables
  2. Compute total performance/revenue for all devices within a particular city and display total performance for each month of the last year for those devices.

But in general, I want to make a powerful filter/search widget so they filter all of their devices and only display metrics for those devices.

I was thinking about using an HTML canvas widget since I can make them do anything I want with HTML, CSS and JS.

But in order to create such a device filter, I need to get a list of all devices and delete the ones not within the filter criteria. In the Ubidots REST API I do not see a “List Devices” API like you guys do for datasources and variables.

I can use the https://industrial.api.ubidots.com/api/v1.6/variables/ which will return a list of ALL the variables available to the user. I can then extract all the unique device ids and other parameters I need for the widget. But this seems like a LOT of data to GET every time the dashboard page loads.

Maybe an Ubifunction would be better instead of doing all this in javascript in the widget? But then I would have to load all that data every time the ubifunction is called.

If I have 1000 devices and each has 20 variables, that will be 20000 variables that API will return, plus variables can have lots of “context” data, etc. And if I have more than one widget that needs to do this type of filtering, each widget will have to get this data. Doesn’t scale vary well I don’t think.

I was wondering what Ubidots offers as far as being able to search and filter through all the devices and their data? To filter by device property for example. Then I can use that data to compute specific metrics and analytics. I was looking at something like ElasticSearch with Kibana which has a powerful and fast searching api for lots of data to get an idea of what I’m trying to do.

I was looking at device tables widget, but that is just a table that you can order by column. It does not give me the ability to remove devices by property and let me compute metrics from the filtered devices.

Any ideas on how to do these custom business metrics efficiently?

Hey @guitardenver, I’m glad you brought this up. We’re working on a new API to support these type of calls, and more. While we don’t have a public documentation yet, some endpoints are already working in beta. Let us do some testing beforehand and come back next week with a few request examples that will hopefully enable your use case, at least partially.

Thank you for sharing your perspective; it helps us validate and prioritize features for the new API.

Have a great weekend,
– Agustin.
Product @ Ubidots.

Hi @guitardenver here more info about how the new API will enable your use case. It’s been deployed, so you can start testing it now. We’re working on the official docs before making the announcement.

Devices Endpoint:

https://industrial.api.ubidots.com/api/v2.0/devices/

Here some of the available query filters:

Filter: Field Type

  • id: id
  • label: text
  • name: text
  • description: text
  • description__isempty: boolean
  • tags: array
  • properties: json

Each Field Type will have its own set of allowed queries. In the case of the Properties filter, the field type is JSON, which will support the following:

GET *PATH* ?properties__contains={"color":"black"}
GET *PATH* ?properties__contains_by={"color":"black", "saturation":"0.8"}
GET *PATH* ?properties__has_key="color"
GET *PATH* ?properties__has_any_keys=["color","brightness"]
GET *PATH* ?properties__has_keys=["color","saturation"]
GET *PATH* ?properties__isnull=False

So, following your use case, a sample query would be:

GET https://industrial.api.ubidots.com/api/v2.0/devices/?properties__contains={"city":"Mesa"}

We’ll also have a separate search function, more on this once we release the new API docs.

Hi @AgustinP, Thank you for this. This will help a lot.

I actually just finished a python library to filter devices using the https://industrial.api.ubidots.com/api/v1.6/datasources/ API. Oh well, your new API will be much faster and cleaner.

My client wants to use Ubidots to automate how they pay taxes per city. So they want to get all devices in a particular city and get the data from those devices for a particular time frame. Then we can use those devices variables data to get how much revenue they made for that time frame in that city and export it to a csv for storage and further processing. Or even display those metrics right on the dashboard.

This will also give me the ability to make a widget that displays the best performing city, or best performing device within a particular city, etc. Very powerful, thank you for making this.

Will you be updating your python libraries to support these new features as well?

Hey @guitardenver that’s a great use case…using IoT for faster, more accurate tax payments.

The new API will support initiating a CSV export process, so this might as well speed up your project.

Regarding the our API libraries; I understand the benefit and simplicity of using the Python library, however, we won’t be updating our libraries soon. This is because we opted to focus on exposing as many API endpoints and entities as possible (devices, organizations, users, events, etc…) as opposed to growing in terms of SDK/API libraries support. This decision is also because most programming languages support native HTTP libraries nowadays, like Python’s HTTP requests, which already erases a layer of complexity.

I hope the new API endpoints are working out well for you, and streamlining your work.