Viswanath95
Viswanath95

Reputation: 21

Show thingsboard device attribute latest value on customized control widget dashboard on thingsboard

I'm using thingsboard V1.3.1.Now i'm working on customized control widget on thingsboard.I received values in thingsboard device attributes. I want dynamic on and off button by passing 1 and 0 values.But my problem is how to show this latest values on my customized created on/off switch control widget on thingsboard dashboard.

Any help would be Appreciated.

Thanks in Advance,

Viswa

Upvotes: 2

Views: 2035

Answers (1)

Nathan Almeida
Nathan Almeida

Reputation: 199

You can set the parameters you wanna pass into the widget by configuring it in here first !

Passing Parameter

  1. attributeService = $scope.$injector.get('attributeService'); inside self.onIni function, this will get the Attributes you just set on the widget datasource.

  2. After this, you gotta recover this info inside the widget. I would suggest you to do this into the self.onDataUpdated function (thingsboard uses AngularJS) so the button will update with the value.

self.onDataUpdated = function () {
        for (let i=0;i<subscription.data.length;i++) {
            let attributeValue = subscription.data[i].data[0][1];
            let dataKey = subscription.data[i].dataKey.name;
            if (dataKey === 'active') {
                $scope.activeVal = (attributeValue === 'true');
            }
        }
    };

The is here constantly going thru every single attribute, checking if the name matches with 'active', if yes, $scope attribute activeVal = active values you passed to the widget.

Thank it.

Upvotes: 1

Related Questions