i'am working with thingsboard as a plateform to supervise my sensors ,and i want to know if there is any way to add in my dashboard a field that allow me to write comments and those comments will be written in postgresql database ?
i Tried to use input widget but it dosent work
it's a bit harder to make comments that will not overwrite previous comments since you would keep those comments under server attributes (you can't work with postgreSQL directly from ThingsBoard).
Solution to that is that you have input widget and then RPC call to rule chain where you would need to have some script that would put new comment as new field to the JSON array. This obviously requires a bit advanced knowledge about TB.
Also you could probably do that thru "Custom action (with HTML template)".
UPDATE: The easiest way you can have comments :
Create JSON server attribute on entity (Device, Asset)
(Optional) Create filter that will return only one entity
Create "Update JSON attribute" widget and point it to the server attribute of entity on which you have done first step (help your self with step 2.)
a. have something like this in that window: {"comments":[{"ts":1665472792000,"value":"My comm1"},{"ts":1668163473000,"value":"My comm2"}]}
Create "HTML Value Card" widget, which also points to that entity and it's server attribute
In "HTML Value Card" widget use this code in server attribute post-processing function:
var comm = parsed["comments"]
var returnValue = '';
if (comm){
var commLength = comm.length;
}
for (var i=0;i<commLength;i++){
returnValue += "<span>"+comm[i]["value"]+"<span><br>";
}
return returnValue;
${nameOfYourServerAttribute}
Yes, you will have to manually add comments directly to JSON, I don't have time to write some widget for that.