# \[App\]\[Pro\] Local API

**URL:** <https://community.homey.app/t/app-pro-local-api/70840>\
**Category:** Apps\
**Tags:** app, flow, homey-pro\
**Created:** [October 19, 2022, 3:50pm UTC](https://community.homey.app/t/app-pro-local-api/70840 "2022-10-19T15:50:01Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![Teddy](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/teddy/32/13818_2.png) [@Teddy](https://community.homey.app/u/Teddy)\
**Post date:** [March 24, 2023, 8:56am UTC](https://community.homey.app/t/app-pro-local-api/70840/41 "2023-03-24T08:56:44Z")

</div>

The 1.1.2 resulted in the not found status… now with 1.1.3 it just return a white screen with no return at all.

// Ted

---

<div class="post-metadata">

**Author:** ![ilpaolino](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ilpaolino/32/49565_2.png) [@ilpaolino](https://community.homey.app/u/ilpaolino)\
**Post date:** [March 24, 2023, 9:08am UTC](https://community.homey.app/t/app-pro-local-api/70840/42 "2023-03-24T09:08:38Z")

</div>

reverted.  
Try 1.1.4

---

<div class="post-metadata">

**Author:** ![Jonathan\_Draper](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jonathan_draper/32/33978_2.png) [@Jonathan\_Draper](https://community.homey.app/u/Jonathan_Draper)\
**Post date:** [March 24, 2023, 9:19am UTC](https://community.homey.app/t/app-pro-local-api/70840/43 "2023-03-24T09:19:11Z")

</div>

Thanks. Back to working again. As I say, very happy to help testing with experimental versions. I’m not a developer so can’t offer more practical help. Have sent you a donation to thank you for your ongoing work on the app though.

---

<div class="post-metadata">

**Author:** ![ilpaolino](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ilpaolino/32/49565_2.png) [@ilpaolino](https://community.homey.app/u/ilpaolino)\
**Post date:** [March 25, 2023, 6:21pm UTC](https://community.homey.app/t/app-pro-local-api/70840/44 "2023-03-25T18:21:28Z")

</div>

Thank you @Jonathan_Draper .

Can you test that version (1.1.4)? In the next beta version I want to try a different approach, but testing with a real case like yours it’s better.

Now I’m reading some documentation, because I want to understand what’s going wrong with that code.

Paolo

---

<div class="post-metadata">

**Author:** ![ilpaolino](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ilpaolino/32/49565_2.png) [@ilpaolino](https://community.homey.app/u/ilpaolino)\
**Post date:** [March 25, 2023, 6:24pm UTC](https://community.homey.app/t/app-pro-local-api/70840/45 "2023-03-25T18:24:07Z")

</div>

Hi, what kind of homey are you using?  
(The “old one” like mine or the new version?)

---

<div class="post-metadata">

**Author:** ![Teddy](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/teddy/32/13818_2.png) [@Teddy](https://community.homey.app/u/Teddy)\
**Post date:** [March 25, 2023, 7:45pm UTC](https://community.homey.app/t/app-pro-local-api/70840/46 "2023-03-25T19:45:39Z")

</div>

HP2023. It works on the old once i have.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Draper](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jonathan_draper/32/33978_2.png) [@Jonathan\_Draper](https://community.homey.app/u/Jonathan_Draper)\
**Post date:** [March 27, 2023, 7:03am UTC](https://community.homey.app/t/app-pro-local-api/70840/47 "2023-03-27T07:03:41Z")

</div>

Yes have been using 1.1.4 for past 3 days now. I have tweaked my dashboard design so that it now only refreshes (and therefore sends an API request to Local API) once a minute (except when someone interacts with it when it sends other requests too). I have also been keeping the memory leak under control by having a flow restart the Local API app every 2 hours. By doing this, the app is very responsive and doesn’t eat too much memory before it gets restarted each time so keeps everything stable.

When previously I had the dashboard index page refreshing more frequently (every 10s) then it was eating up memory a LOT faster so it’s clearly some memory usage with each API call that’s building up. The API requests I am sending return a JSON structure containing 22 values from various variables / device statuses - so not a large amount of data each time. Not sure whether that’s related to the problem anyway.

Here’s a screenshot showing most recent 24 hours of memory usage for Local API app where you can clearly see the 2 hourly restarts. Overnight it was very smooth then this morning there was more interaction with it so a bit more variable.

 ![Screenshot 2023-03-27 at 08.01.25](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/e/5e4493ea6755eb5d0cbc6007b1c0ddd5e78d5f35.jpeg)

---

<div class="post-metadata">

**Author:** ![Jonathan\_Draper](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jonathan_draper/32/33978_2.png) [@Jonathan\_Draper](https://community.homey.app/u/Jonathan_Draper)\
**Post date:** [March 27, 2023, 8:04am UTC](https://community.homey.app/t/app-pro-local-api/70840/48 "2023-03-27T08:04:08Z")

</div>

Also noticed this - interestingly there are some occasions when the app does clear up some memory usage when not being restarted. The first and last large drops here were restarts; the two smaller drops in the middle weren’t. Also, the reduction in memory usage on each restart isn’t the same.

![Screenshot 2023-03-27 at 09.01.54](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/4/3/4316e199784e27c3aef9b5f199583be6ce958277.png)

---

<div class="post-metadata">

**Author:** ![ilpaolino](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ilpaolino/32/49565_2.png) [@ilpaolino](https://community.homey.app/u/ilpaolino)\
**Post date:** [March 30, 2023, 7:03pm UTC](https://community.homey.app/t/app-pro-local-api/70840/49 "2023-03-30T19:03:57Z")

</div>

Ok, some updates:  
1 -  
for all those who have the new version of homey:  
Unfortunately I don’t have a new device, so I can’t conduct tests and developments directly.  
At the moment the error I get is directly dependent on homey’s API.

```auto
Error: Circular Reference "socket"
     at walk (/node_modules/@athombv/homey-serializer/src/traverse.js:24:40)

```

Unfortunately, I can’t touch the homey-serializer API/module in any way, so I’m forced to wait for the Homey developers to do something about it.

2 -  
@Jonathan_Draper first of all thanks for the support and useful information.

The size of the JSON could actually make it worse. In the graphs, those little decreases in occupied memory are due to the javascript garbage collector (which intervenes autonomously).

Can I ask you to share with me the screenshot of the flow , and if possible a complete example of the generated JSON?

I’m still reading some possible solutions to this problem, then I’d like to try to make a test version available for download (I’ll leave the link here in the forum) I’d ask you if you could try that too and give feedback about it.

Sorry if I’m not very responsive, I try to do everything possible!

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [March 31, 2023, 5:38am UTC](https://community.homey.app/t/app-pro-local-api/70840/50 "2023-03-31T05:38:59Z")

</div>

> [@ilpaolino](#):
>
> At the moment the error I get is directly dependent on homey’s API.

It sounds like you’re trying to store an instance of something (HTTP request/response?) as a setting, which can only store plain objects. Is that the full stack trace?

---

<div class="post-metadata">

**Author:** ![ilpaolino](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ilpaolino/32/49565_2.png) [@ilpaolino](https://community.homey.app/u/ilpaolino)\
**Post date:** [March 31, 2023, 5:55am UTC](https://community.homey.app/t/app-pro-local-api/70840/51 "2023-03-31T05:55:44Z")

</div>

Hi @robertklep here is the complete stack-trace:

```auto
Error: Circular Reference "socket"
    at walk (/node_modules/@athombv/homey-serializer/src/traverse.js:24:40)
    at walk (/node_modules/@athombv/homey-serializer/src/traverse.js:32:23)
    at walk (/node_modules/@athombv/homey-serializer/src/traverse.js:32:23)
    at walk (/node_modules/@athombv/homey-serializer/src/traverse.js:32:23)
    at walk (/node_modules/@athombv/homey-serializer/src/traverse.js:32:23)
    at walk (/node_modules/@athombv/homey-serializer/src/traverse.js:32:23)
    at traverse (/node_modules/@athombv/homey-serializer/src/traverse.js:42:10)
    at HomeySerializer.serialize (/node_modules/@athombv/homey-serializer/src/index.js:136:12)
    at /node_modules/@athombv/homey-apps-sdk-v3/lib/HomeyClient.js:51:32
    at new Promise (<anonymous>)

```

If you can help, any PR on the code is welcome, here ( [GitHub - ilpaolino/homeylocalapi](https://github.com/ilpaolino/homeylocalapi) ) you find the sources, in order to check what is done at the application level

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [March 31, 2023, 6:04am UTC](https://community.homey.app/t/app-pro-local-api/70840/52 "2023-03-31T06:04:30Z")

</div>

Do you know when exactly the issue occurs?

---

<div class="post-metadata">

**Author:** ![ilpaolino](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ilpaolino/32/49565_2.png) [@ilpaolino](https://community.homey.app/u/ilpaolino)\
**Post date:** [March 31, 2023, 6:43am UTC](https://community.homey.app/t/app-pro-local-api/70840/53 "2023-03-31T06:43:54Z")

</div>

No, sorry, there is nowhere where it highlights in the app that help me to identify where the error is raised.

Additionally I can’t try the code in the new Homey (2023), so I can’t try to identify where the errors occurs.

If anyone had any idea, is appreciated.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [March 31, 2023, 7:01am UTC](https://community.homey.app/t/app-pro-local-api/70840/54 "2023-03-31T07:01:44Z")

</div>

Then do you know if the issue occur for every HP2023 user? Random “strange” errors are a fact of life and don’t necessarily mean they are related to your app.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Draper](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jonathan_draper/32/33978_2.png) [@Jonathan\_Draper](https://community.homey.app/u/Jonathan_Draper)\
**Post date:** [March 31, 2023, 7:05am UTC](https://community.homey.app/t/app-pro-local-api/70840/55 "2023-03-31T07:05:31Z")

</div>

Hi @ilpaolino - thanks for your ongoing efforts. Happy to keep testing and providing what info you need. I attach a screenshot of the flow for the request that gets fired every minute from my dashboard. There are some other requests from the dashboard as well but only in response to button clicks so almost all of the traffic is this one request.

 ![API call](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/d/9d0105eaf888494b8d9c8a6e1f6f7949d0f9bbcb.jpeg)

The JSON response looks like this:

```auto
{
  "status": "success",
  "url": "/dashboard/homepage",
  "method": "GET",
  "data": {
    "sunrise": "06:40",
    "sunset": "19:31",
    "today_min": "9.4",
    "today_max": "10.3",
    "feels_like": "9.3",
    "wind_speed": "33",
    "weather_condition": "Drizzly",
    "current_temp": "10.2",
    "inside_temp": "18.5",
    "downstairs_secure": "true",
    "house_secure": "false",
    "jon_home": "true",
    "xxxx_home": "true",
    "xxxx_home": "true",
    "xxxx_home": "true",
    "xxxx_home": "false",
    "house_state": "Day",
    "term_time": "true",
    "holiday_mode": "false",
    "today_weather": "300",
    "bin_day": "neither",
    "milk": "false"
  }
}

```

I’ll happily try a new test version whenever it’s ready.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [March 31, 2023, 7:33am UTC](https://community.homey.app/t/app-pro-local-api/70840/56 "2023-03-31T07:33:29Z")

</div>

> [@ilpaolino](#):
>
> If anyone had any idea, is appreciated.

This is the issue:

```auto
requestReceivedTrigger.trigger({}, { request: req, response: res });

```

`req` and `res` cannot be serialized, which is causing the error (I guess that the way triggers are handled differs between HP2019 and HP2023).

To fix this, you should only pass the properties of `req` and `res` that are required (and make sure that these properties are either scalar or just plain arrays/objects that don’t contain any instances).

---

<div class="post-metadata">

**Author:** ![ilpaolino](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ilpaolino/32/49565_2.png) [@ilpaolino](https://community.homey.app/u/ilpaolino)\
**Post date:** [March 31, 2023, 11:44am UTC](https://community.homey.app/t/app-pro-local-api/70840/57 "2023-03-31T11:44:15Z")

</div>

Thank you @robertklep

I will try over the weekend to integrate this solution and put it in beta.

Thanks for your help

---

<div class="post-metadata">

**Author:** ![ilpaolino](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ilpaolino/32/49565_2.png) [@ilpaolino](https://community.homey.app/u/ilpaolino)\
**Post date:** [March 31, 2023, 10:33pm UTC](https://community.homey.app/t/app-pro-local-api/70840/58 "2023-03-31T22:33:23Z")

</div>

Here in beta the last version with the @robertklep solution.

> **[Local API](https://homey.app/en-us/app/dev.dadda.localapi/Local-API/)**
>
> Local API Creator directly hosted and served from your Homey Hub

@Jonathan_Draper @Teddy  
Let me know if this version is better.

Thank you all

Paolo

---

<div class="post-metadata">

**Author:** ![Teddy](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/teddy/32/13818_2.png) [@Teddy](https://community.homey.app/u/Teddy)\
**Post date:** [April 1, 2023, 6:52am UTC](https://community.homey.app/t/app-pro-local-api/70840/59 "2023-04-01T06:52:02Z")

</div>

Good morning Paolo

It works for me on my HP2023 now 🙂

I had one of my flows that i had to recreate for some odd reason it didnt work. It seam to have been in relation to the Respons flow card for JSON return. But after recreating specificly that card it worked. The rest worked without problems after install.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Draper](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jonathan_draper/32/33978_2.png) [@Jonathan\_Draper](https://community.homey.app/u/Jonathan_Draper)\
**Post date:** [April 1, 2023, 6:58am UTC](https://community.homey.app/t/app-pro-local-api/70840/60 "2023-04-01T06:58:14Z")

</div>

Thank you for this! I have it in testing now on my HP2019. Early signs are good on memory usage too but I will keep an eye on it over the next few hours and report back.

[Previous page](https://community.homey.app/t/app-pro-local-api/70840.md?page=2)

[Next page](https://community.homey.app/t/app-pro-local-api/70840.md?page=4)
