# JSON Fetch from Domoticz

**URL:** <https://community.homey.app/t/json-fetch-from-domoticz/129745>\
**Category:** Questions & Help\
**Tags:** homeyscript, domoticz\
**Created:** [February 4, 2025, 12:00pm UTC](https://community.homey.app/t/json-fetch-from-domoticz/129745 "2025-02-04T12:00:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joost\_Else](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/joost_else/32/17360_2.png) [@Joost\_Else](https://community.homey.app/u/Joost_Else)\
**Post date:** [February 4, 2025, 12:00pm UTC](https://community.homey.app/t/json-fetch-from-domoticz/129745/1 "2025-02-04T12:00:59Z")

</div>

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

```auto
// 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:

```auto

———————————————————
❌ 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](https://wiki.domoticz.com/Domoticz_API/JSON_URL's#Authorization), 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):

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/7/b700a047b210edbb80cc1842b90ce883620671f6.png)

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [February 4, 2025, 12:29pm UTC](https://community.homey.app/t/json-fetch-from-domoticz/129745/2 "2025-02-04T12:29:46Z")

</div>

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

> [@Omlet Smart Automatic Chicken Coop Door: Automation using Homey Script](https://community.homey.app/t/omlet-smart-automatic-chicken-coop-door-automation-using-homey-script/115988):
>
> I faced the issue of not being able to control this door through automation since it is only controlled by Google Home normally, and since Google Home wont allow any sort of automation for device type “Door” for security reasons, we simply cannot open/close the door through flows or even Google Home routines, we are stuck with manually opening/closing the door, which kinda sucks. Luckily, Omlet provides an API (Open API 3.0) that we can use inside Homey Scripts to open/close the door and fetch …

> [@Homeyscript for bearer token](https://community.homey.app/t/homeyscript-for-bearer-token/47819/6):
>
> It looks like the issue is with fetch() behaving differently. Here’s a fixed version: // -------- o - Configure these parameters -------- o -------- o let email = 'REPLACEME' let password = 'REPLACEME' let client\_id = REPLACEME let client\_secret = 'REPLACEME' let redirect\_url = 'http://localhost' let cloudid = 'REPLACEME' // -------- o -------- o -------- o -------- o -------- o const between = function(str, strf, strt) { return str.split(strf).pop().split(strt)[0].trim(); } const auth…

I just used this search phrase:

 ![1000042682](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/7/f763f363d07d6c03a348ea6f0fee481d1ef6fd88.jpeg)

---

<div class="post-metadata">

**Author:** ![Adrian\_Rockall](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/adrian_rockall/32/13209_2.png) [@Adrian\_Rockall](https://community.homey.app/u/Adrian_Rockall)\
**Post date:** [February 4, 2025, 12:47pm UTC](https://community.homey.app/t/json-fetch-from-domoticz/129745/3 "2025-02-04T12:47:22Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Jeroen\_Tebbens](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeroen_tebbens/32/62246_2.png) [@Jeroen\_Tebbens](https://community.homey.app/u/Jeroen_Tebbens)\
**Post date:** [February 4, 2025, 1:02pm UTC](https://community.homey.app/t/json-fetch-from-domoticz/129745/4 "2025-02-04T13:02:37Z")

</div>

Whitelist your local subnet in the domoticz setting:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/3/b/3b7bb06ac8f2955f6cb062a9fee3e7f3f7f51539.png)

---

<div class="post-metadata">

**Author:** ![Joost\_Else](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/joost_else/32/17360_2.png) [@Joost\_Else](https://community.homey.app/u/Joost_Else)\
**Post date:** [February 4, 2025, 1:15pm UTC](https://community.homey.app/t/json-fetch-from-domoticz/129745/5 "2025-02-04T13:15:41Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Jeroen\_Tebbens](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeroen_tebbens/32/62246_2.png) [@Jeroen\_Tebbens](https://community.homey.app/u/Jeroen_Tebbens)\
**Post date:** [February 4, 2025, 2:01pm UTC](https://community.homey.app/t/json-fetch-from-domoticz/129745/6 "2025-02-04T14:01:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Eternity](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/eternity/32/102113_2.png) [@Eternity](https://community.homey.app/u/Eternity)\
**Post date:** [February 4, 2025, 3:02pm UTC](https://community.homey.app/t/json-fetch-from-domoticz/129745/7 "2025-02-04T15:02:47Z")

</div>

> [@Jeroen\_Tebbens](#):
>
> Domoticz is a pretty much dead.

Hopefully not!

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

 ![1000121434](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/b/1bf4d9876ef2ea6c66b97fecdb18aa06b3134d72.png)

---

<div class="post-metadata">

**Author:** ![Joost\_Else](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/joost_else/32/17360_2.png) [@Joost\_Else](https://community.homey.app/u/Joost_Else)\
**Post date:** [February 4, 2025, 3:26pm UTC](https://community.homey.app/t/json-fetch-from-domoticz/129745/8 "2025-02-04T15:26:03Z")

</div>

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.
