For everyone also creating REST-sensors for Paperless-ngx:
You should try to minimize traffic, especially if your document database is huge.
To fetch the document’s count you should for example never send the basic Request to
http://<paperless-ngx_ip>:<port>/api/documents/
as this will return all document-objects containing all data including full text.
Instead you should call the API with modifying arguments like
?page=1&page_size=1&truncate_content=true
This will return an object like this:
{
"count": 3822,
"next": "http://<paperless-ngx_ip>:<port>/api/documents/?page=1&page_size=1&truncate_content=true",
"previous": null,
"all": [ ... ],
"results": [
{ ... } // Only 1 object returned with truncated text inside
]
}
So your REST-sensor should look like this:
sensor:
- platform: rest
name: Paperless-ngx - Number of documents in Total
resource: http://<paperless-ngx_ip>:<port>/api/documents/?page=1&page_size=1&truncate_content=true
method: GET
headers:
Authorization: Token <User-Token>
value_template: "{{ value_json.count }}"
scan_interval: 300