JSON Fetch from Domoticz

Joost_Else
Tue, 04 Feb 2025 12:00:59 +0000
Questions & Help

I’m trying to fetch my P1 energy data from a Domoticz installation using a script.

// Create the request
const res = await fetch( 'http://192.168.1.81:8080/json.htm?type=command&param=getdevices&idx=29');
if (!res.ok) {
  throw new Error(res.statusText);
}

// Get the body JSON
const body = await res.json();

When I try to run this, Domoticz seems to deny the request because of authorization issues:

———————————————————
❌ Script Error
⚠️ Error: Unauthorized
    at fetch-domoticz-p1.js.js:4:9
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async HomeyScriptApp.runScript (/app.js:364:22)
    at async Object.runScript (/api.js:30:22)

Reading up in the Domoticz documentation, it says I should encode username & password in the “Authorization” HTTP request header. Encoding username/password is no problem, but how do I get these in the request from Homey?

In the end, I want to connect this data to the data from my solar panels to create something like this (screenshot from domoticz, don’t need the graphs but do need the data):

8 posts - 5 participants