Electronout
Electronout

Reputation: 11

Why are the ThingsBoard buttons not working correctly when using 'Entity Alias' instead of 'Device?

i am experiencing an issue with the Command Button in ThingsBoard. When setting a value for multiple devices using an entity alias (in my case, a list of devices), the button only affects one device (likely the last in the list). It works fine when a single device is selected as the source.

Has anyone else encountered this problem or can confirm it? If it works for you, please share any extra steps you took. If it doesn't work, do you know any workarounds or have any ideas on how to apply a single value to all devices in an entity alias without building a custom widget (as this should be the button's functionality)? For further clarification, I’ve added a trace log below to explain my reasoning. The code seems to be TypeScript, hence the relevant tag.


First to verify that this is really supposed to work i checked what the official release notes say about the Command Button:

You can specify a single device to carry out your chosen action, such as receiving a command. For those familiar with the platform, there’s an option to use entity aliases for targeting. This means you’re not limited to devices; you can target assets, users, or other entities capable of supporting attribute updates or time series data additions.

Source: Thingsboard button introduction.


Reproduce the Problem:

I was running Thingsboard v.3.8.1, but it should occur on any version after the button release on v3.6.3 (Mar 18, 2024). Go Dashboards->add new Dashboard->add widget->buttons bundle->command button->Here select as Target Device "Entity alias" -> Create a new alias: Select Entity alias instead of Device and Options for the Alias -> onclick: set Attribute / Scope: Server / Choose a key and value -> then [Add] the widget -> Save the dashboard.

Now check the devices you selected in the alias -> click the button -> check the devices again and only one will be updated.

I was expecting the button to work with an entity alias too. I checked the Internet for some time, but somehow nobody else mentioned this problem. So I checked the official repository to find out if there was a mistake in the code, and I think I found one. If this is true, it at least applies to all of those released buttons.


Sources for the tracelog

Here is my tracelog (why i think it's a code issue):

Note: this.settings.onClickState is defined as this.settings = {...commandButtonDefaultSettings, ...this.ctx.settings};, but commandButtonDefaultSettings only holds the default or later the user-defined action that is called upon the object. File: command-button-widget.models.ts. The source seems not to be defined there. Let's look at the function called

Check out these classes that are already named, like the actions available for the button, the ExecuteRpcValueSetter, AttributeValueSetter, and TimeSeriesValueSetter, to find how the source is managed

Okay, so in my opinion, the problem is in the class TelemetryValueSetter<V>. Have a look at this part: const entityInfo = this.ctx.defaultSubscription.getFirstEntityInfo(); Why would you always get the info of the first entity if a list is allowed?

Shouldn't the implementation should check if the source is an entity asset and, based on that, work on one device or resolve the entities and apply the action to all of them in a loop?

I'm grateful to hear your views on this. Many Thanks

Upvotes: 1

Views: 94

Answers (0)

Related Questions