JSON Fetch from Domoticz

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):

Maybe this is helpful (open these posts to view the shared scripts):

I just used this search phrase:

1 Like

You should be able to pass in the headers to fetch:

const response = await fetch("https://example.org/post", {
  headers: {
    "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
  },
  // ...
});
1 Like

Whitelist your local subnet in the domoticz setting:

2 Likes

That is actually not a bad solution. Bit of a security breach, but not too bad since my domoticz server should not be available to the outside world anyway. Thx!

Frankly, Domoticz is a pretty much dead. Still have it for the much stronger 434Mhz frequency hardware (rfxcom).

Hopefully not!

I use it to store my (historical) P1 data.

That is exactly what I use it for though in my case it goes back to 2020. It runs on a RPi3 that doubles as a music server. Unfortunately, Domoticz refuses to fetch information from my PV installation, which was a breeze in Homey. Therefore, the combination of the two.

Anyway, Domoticz has been next to dead for years now. Not much development is going on anymore, things are dormant. As long as i works, it works.