# Solar system from APsystems

**URL:** <https://community.homey.app/t/solar-system-from-apsystems/74759>\
**Category:** Questions & Help\
**Created:** [January 8, 2023, 1:12pm UTC](https://community.homey.app/t/solar-system-from-apsystems/74759 "2023-01-08T13:12:33Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Festini](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/festini/32/46348_2.png) [@Festini](https://community.homey.app/u/Festini)\
**Post date:** [June 1, 2024, 10:57am UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/23 "2024-06-01T10:57:40Z")

</div>

I’m also getting this error. Tried it with or without adding port 8899  
I’m on the older ECU-R (2160xxxxxxxx series)  
Please advise.

———————————————————  
✅ Script Success  
↩ Returned: undefined  
Error fetching the URL: FetchError: request to [http://192.168.1.82:8899/index.php/realtimedata](http://192.168.1.82:8899/index.php/realtimedata) failed, reason: socket hang up  
at ClientRequest. (/app/node\_modules/node-fetch/lib/index.js:1501:11)  
at ClientRequest.emit (node:events:517:28)  
at Socket.socketOnEnd (node:\_http\_client:525:9)  
at Socket.emit (node:events:529:35)  
at endReadableNT (node:internal/streams/readable:1400:12)  
at process.processTicksAndRejections (node:internal/process/task\_queues:82:21) {  
type: ‘system’,  
errno: ‘ECONNRESET’,  
code: ‘ECONNRESET’  
}

---

<div class="post-metadata">

**Author:** ![Patrick\_Van\_Deursen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/patrick_van_deursen/32/56539_2.png) [@Patrick\_Van\_Deursen](https://community.homey.app/u/Patrick_Van_Deursen)\
**Post date:** [June 1, 2024, 4:34pm UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/24 "2024-06-01T16:34:23Z")

</div>

@Festini , how did you come to port 8899?

With that port, I get the same result:

———————————————————  
✅ Script Success  
↩ Returned: undefined  
Error fetching the URL: FetchError: request to [http://192.168.0.175:8899/index.php/realtimedata](http://192.168.0.175:8899/index.php/realtimedata) failed, reason: socket hang up  
at ClientRequest. (/app/node\_modules/node-fetch/lib/index.js:1501:11)  
at ClientRequest.emit (node:events:517:28)  
at Socket.socketOnEnd (node:\_http\_client:525:9)  
at Socket.emit (node:events:529:35)  
at endReadableNT (node:internal/streams/readable:1400:12)  
at process.processTicksAndRejections (node:internal/process/task\_queues:82:21) {  
type: ‘system’,  
errno: ‘ECONNRESET’,  
code: ‘ECONNRESET’  
}

---

<div class="post-metadata">

**Author:** ![Ostys](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ostys/32/71829_2.png) [@Ostys](https://community.homey.app/u/Ostys)\
**Post date:** [June 26, 2024, 4:00pm UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/25 "2024-06-26T16:00:38Z")

</div>

Hello,

Can someone post the full code for me, please. So i don’t have to do it myself.  
Or can you publish the code as an app at the homey-pro - store?

btw… i’ve a manuel from APsystems for the EZ1 inverter. There is the correct port :8050 …

Thanks a lot.  
Osty

---

<div class="post-metadata">

**Author:** ![Peter\_van\_Werkhoven](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_van_werkhoven/32/101322_2.png) [@Peter\_van\_Werkhoven](https://community.homey.app/u/Peter_van_Werkhoven)\
**Post date:** [August 22, 2024, 8:01am UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/26 "2024-08-22T08:01:13Z")

</div>

Hi Ostys,

I agree with you because not everyone has the capability to programming code and I’ll hope if there’s anybody who can develop an APP for the ApSystems EMA to use it in Homey to control and use the appliances while the sun is shining.  
Hope someone pick this up.

Best regards Peter.

---

<div class="post-metadata">

**Author:** ![Mombasa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mombasa/32/113225_2.png) [@Mombasa](https://community.homey.app/u/Mombasa)\
**Post date:** [August 29, 2024, 6:43pm UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/27 "2024-08-29T18:43:45Z")

</div>

I have the following developed:

### Homey Script for APsystems ECU-R Setup

**Initial Setup:**

1. **Create Two Variables:**

- **Text Variable:** Used for troubleshooting.
- **Number Variable:** Stores the calculated power.

1. **Create a Virtual Device (requires virtual devices app) :**

- This device will display the power value from the **number variable**.

1. **Set Up the Homey Script:**

- Copy the script provided below.
- Modify the `urlAPsystems` constant to match the IP address of your APsystems ECU-R (replace `0.0.0.0` with the correct address).
- Adjust the `variableStatus` constant to match the name of your **text variable**.
- Adjust the `variablePower` constant to match the name of your **number variable**.

1. **Create a Flow:**

- **Trigger:** Set it to run at a regular interval (e.g., every 2 minutes).
- **Action 1:** Execute the Homey script.
- **Action 2:** Update the virtual device with the value from the **number variable**.

```auto
const vars = await Homey.logic.getVariables();
const startTime = Date.now();

// Define the URL of the webpage to scrape
const urlAPsystems = 'http://0.0.0.0/index.php/realtimedata';
const variableStatus = 'solarStatus';
const variablePower = 'solarPower';

// Function to fetch the webpage content
async function fetchWebPage(urlAPsystems) {
    const response = await fetch(urlAPsystems);
    if (!response.ok) {
        throw new Error(`HTTP error! Status: ${response.status}`);
    }
    return await response.text();
}

// Function to parse the HTML content and extract the power values
function extractPowerValues(html) {
    const regex = /<td>\s*(\d+)\s*W\s*<\/td>/g;
    let match;
    const powerValues = [];

    while ((match = regex.exec(html)) !== null) {
        // This is necessary to avoid infinite loops with zero-width matches
        if (match.index === regex.lastIndex) {
            regex.lastIndex++;
        }

        const powerValue = parseInt(match[1], 10);
        if (!isNaN(powerValue)) {
            powerValues.push(powerValue);
        }
    }

    return powerValues;
}

async function main() {
    try {
        const htmlContent = await fetchWebPage(urlAPsystems);
        const powerValues = extractPowerValues(htmlContent);

        // Sum the power values
        const totalPower = powerValues.reduce((sum, value) => sum + value, 0);
        const SolarPowerDevice = _.find(vars, (o) => o.name === variablePower)

        await Homey.logic.updateVariable({id: SolarPowerDevice.id, variable: {value: -totalPower}});

        const elapsedTime = Date.now() - startTime

        // Get current date and time
        const currentDate = new Date();

        // Get day, month, year, hours, and minutes
        const day = String(currentDate.getDate()).padStart(2, '0');
        const month = String(currentDate.getMonth() + 1).padStart(2, '0');
        const year = currentDate.getFullYear();
        const hours = String(currentDate.getHours()).padStart(2, '0');
        const minutes = String(currentDate.getMinutes()).padStart(2, '0');

        const SolarStatusMessage = `${day}-${month}-${year} ${hours}:${minutes} | ms ${elapsedTime} | `;

        const SolarErrorMessage = _.find(vars, (o) => o.name === variableStatus)
        await Homey.logic.updateVariable({id: SolarErrorMessage.id, variable: {value: `${SolarStatusMessage} Status: OK`}});
        console.log('Total power: ', totalPower, 'W');
        console.log('Status: ', SolarStatusMessage);

    } catch (error) {
        console.error(`${SolarStatusMessage} Status:`, error.message);
        const SolarErrorMessage = _.find(vars, (o) => o.name === variableStatus)
        await Homey.logic.updateVariable({id: SolarErrorMessage.id, variable: {value: error.message}});
    }
}

main();

```

Please note that I initially used the APsystems ECU-R via a Wi-Fi connection, but it was very unstable and unreliable. After switching to a LAN connection, everything started working fine.

---

<div class="post-metadata">

**Author:** ![Steven\_Bareman](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/steven_bareman/32/31404_2.png) [@Steven\_Bareman](https://community.homey.app/u/Steven_Bareman)\
**Post date:** [August 30, 2024, 10:18am UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/28 "2024-08-30T10:18:42Z")

</div>

Great work, at the end of September i wil have a APSystem and wil install check your script to my Homey 🙂

---

<div class="post-metadata">

**Author:** ![Festini](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/festini/32/46348_2.png) [@Festini](https://community.homey.app/u/Festini)\
**Post date:** [September 1, 2024, 7:46am UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/30 "2024-09-01T07:46:32Z")

</div>

@Mombasa Thanks for developing the script! I followed your instructions but it doesn’t seem to update my virtual device with correct Power value. It doesn’t overwrite the default value “0” that I used to create the Number Variable.

This is my script:

```auto
const vars = await Homey.logic.getVariables();
const startTime = Date.now();

// Define the URL of the webpage to scrape
const urlAPsystems = 'http://192.168.1.82/index.php/realtimedata';
const variableStatus = 'solarStatus';
const variablePower = 'solarPower';

// Function to fetch the webpage content
async function fetchWebPage(urlAPsystems) {
    const response = await fetch(urlAPsystems);
    if (!response.ok) {
        throw new Error(`HTTP error! Status: ${response.status}`);
    }
    return await response.text();
}

// Function to parse the HTML content and extract the power values
function extractPowerValues(html) {
    const regex = /<td>\s*(\d+)\s*W\s*<\/td>/g;
    let match;
    const powerValues = [];

    while ((match = regex.exec(html)) !== null) {
        // This is necessary to avoid infinite loops with zero-width matches
        if (match.index === regex.lastIndex) {
            regex.lastIndex++;
        }

        const powerValue = parseInt(match[1], 10);
        if (!isNaN(powerValue)) {
            powerValues.push(powerValue);
        }
    }

    return powerValues;
}

async function main() {
    try {
        const htmlContent = await fetchWebPage(urlAPsystems);
        const powerValues = extractPowerValues(htmlContent);

        // Sum the power values
        const totalPower = powerValues.reduce((sum, value) => sum + value, 0);
        const SolarPowerDevice = _.find(vars, (o) => o.name === variablePower)

        await Homey.logic.updateVariable({id: SolarPowerDevice.id, variable: {value: -totalPower}});

        const elapsedTime = Date.now() - startTime

        // Get current date and time
        const currentDate = new Date();

        // Get day, month, year, hours, and minutes
        const day = String(currentDate.getDate()).padStart(2, '0');
        const month = String(currentDate.getMonth() + 1).padStart(2, '0');
        const year = currentDate.getFullYear();
        const hours = String(currentDate.getHours()).padStart(2, '0');
        const minutes = String(currentDate.getMinutes()).padStart(2, '0');

        const SolarStatusMessage = `${day}-${month}-${year} ${hours}:${minutes} | ms ${elapsedTime} | `;

        const SolarErrorMessage = _.find(vars, (o) => o.name === variableStatus)
        await Homey.logic.updateVariable({id: SolarErrorMessage.id, variable: {value: `${SolarStatusMessage} Status: OK`}});
        console.log('Total power: ', totalPower, 'W');
        console.log('Status: ', SolarStatusMessage);

    } catch (error) {
        console.error(`${SolarStatusMessage} Status:`, error.message);
        const SolarErrorMessage = _.find(vars, (o) => o.name === variableStatus)
        await Homey.logic.updateVariable({id: SolarErrorMessage.id, variable: {value: error.message}});
    }
}

main();

```

This is the output:

```auto

———————————————————
✅ Script Success
↩️ Returned: undefined

```

My variables:

```auto
Number: variablePower = 0
Text: variableStatus = null

```

Virtual device:  
`virtualdevice = Device > Solar Panel > Measure_Power`

Trigger flow:

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

Do you see anything wrong? Please advise

---

<div class="post-metadata">

**Author:** ![Festini](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/festini/32/46348_2.png) [@Festini](https://community.homey.app/u/Festini)\
**Post date:** [September 1, 2024, 8:02am UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/31 "2024-09-01T08:02:04Z")

</div>

@ARTNOW44 Please write your question in English

---

<div class="post-metadata">

**Author:** ![ARTNOW44](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/artnow44/32/69544_2.png) [@ARTNOW44](https://community.homey.app/u/ARTNOW44)\
**Post date:** [September 1, 2024, 8:27am UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/32 "2024-09-01T08:27:18Z")

</div>

> [@ARTNOW44](#):
>
> 1. **Créer deux variables :**
> 
> - **Variable de texte :** utilisée pour le dépannage.
> - **Variable numérique :** stocke la puissance calculée.
> 
> 1. **Créer un périphérique virtuel (nécessite une application pour périphériques virtuels) :**
> 
> - Cet appareil affichera la valeur de puissance à partir de la **variable numérique**.
> 
> **Bonjour , pourriez-vous détailler les opérations à faire ci-dessus ?**  
> **MERCI**
> 
> **Arnaud**

YOU WROTE Create two variables:  
Text variable: Used for troubleshooting.  
Numeric variable: stores the calculated power.  
Create a virtual device (requires a virtual device app):  
This device will display the power value from the numeric variable.

Hello, could you detail the operations to be done above?  
THANK YOU

Arnaud

---

<div class="post-metadata">

**Author:** ![Mombasa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mombasa/32/113225_2.png) [@Mombasa](https://community.homey.app/u/Mombasa)\
**Post date:** [September 1, 2024, 10:46am UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/33 "2024-09-01T10:46:47Z")

</div>

> [@Festini](#):
>
> `http://192.168.1.82/index.php/realtimedata`

Can you make a printscreen from the following:

[http://192.168.1.82/index.php/realtimedata](http://192.168.1.82/index.php/realtimedata)

In the script, `variableStatus` and `variablePower` are placeholders. They represent the actual variables names in your code, which in this example are `solarStatus` and `solarPower`. You can customize these names to fit your specific needs. Rename your variables to `solarStatus` and `solarPower`, or choose your own names. If you opt for different names, remember to update the script accordingly to reflect these changes.

---

<div class="post-metadata">

**Author:** ![Mombasa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mombasa/32/113225_2.png) [@Mombasa](https://community.homey.app/u/Mombasa)\
**Post date:** [September 1, 2024, 6:26pm UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/34 "2024-09-01T18:26:00Z")

</div>

A virtual device can be created directly from the home screen by clicking the ‘+’ sign in the web browser. I use this app for that purpose: [Virtual Devices](https://homey.app/en-us/app/com.arjankranenburg.virtual/Virtual-Devices/).

Variabels can be created inside the flows section

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

Example flow:

---

<div class="post-metadata">

**Author:** ![ARTNOW44](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/artnow44/32/69544_2.png) [@ARTNOW44](https://community.homey.app/u/ARTNOW44)\
**Post date:** [September 2, 2024, 11:40am UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/35 "2024-09-02T11:40:33Z")

</div>

Hello, I’m sorry but I don’t understand at all how to do it, please give me more details which will surely be useful for the whole community, thank you in advance Arnaud

---

<div class="post-metadata">

**Author:** ![Festini](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/festini/32/46348_2.png) [@Festini](https://community.homey.app/u/Festini)\
**Post date:** [September 2, 2024, 11:58am UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/36 "2024-09-02T11:58:14Z")

</div>

![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/d/fdc2fe0dd3f625d0e422198000779779c9c94919.png)  
It doesn’t seem to connect to this URL, although my ECU-R is perfectly accessible via the EMA App. Furthermore, I have recently set up an active API connection via HomeWizard’s Energy App that works perfectly, although it only updates every 15 minutes. When I try to ping the IP everything looks good. Very strange.

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

---

<div class="post-metadata">

**Author:** ![Patrick\_Van\_Deursen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/patrick_van_deursen/32/56539_2.png) [@Patrick\_Van\_Deursen](https://community.homey.app/u/Patrick_Van_Deursen)\
**Post date:** [September 2, 2024, 12:32pm UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/37 "2024-09-02T12:32:17Z")

</div>

This has been my problem from the beginning. The website is not accessable from within my home (eventhough the ip address is visible in my ubiquity system). Also adding the varios mentioned ports here and on Github do not give me access. hence any and all script fails, as they cannot get any data from the website…

Anybody getting data from their ECU-R through the internal IP address?

---

<div class="post-metadata">

**Author:** ![Festini](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/festini/32/46348_2.png) [@Festini](https://community.homey.app/u/Festini)\
**Post date:** [September 2, 2024, 12:59pm UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/38 "2024-09-02T12:59:41Z")

</div>

Same here. In addition, I do have access via this external address:  
[https://apsystemsema.com/ema/index.action](https://apsystemsema.com/ema/index.action)

---

<div class="post-metadata">

**Author:** ![Mombasa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mombasa/32/113225_2.png) [@Mombasa](https://community.homey.app/u/Mombasa)\
**Post date:** [September 2, 2024, 1:20pm UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/39 "2024-09-02T13:20:46Z")

</div>

How is your ECU-R connected to your network via cable or wireless?

---

<div class="post-metadata">

**Author:** ![Mombasa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mombasa/32/113225_2.png) [@Mombasa](https://community.homey.app/u/Mombasa)\
**Post date:** [September 2, 2024, 1:27pm UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/40 "2024-09-02T13:27:21Z")

</div>

This is a little bit to general. Could you clarify where you need assistance?

Setting up a Homey script requires a basic understanding of JavaScript and how to implement it within the Homey environment.

---

<div class="post-metadata">

**Author:** ![Patrick\_Van\_Deursen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/patrick_van_deursen/32/56539_2.png) [@Patrick\_Van\_Deursen](https://community.homey.app/u/Patrick_Van_Deursen)\
**Post date:** [September 2, 2024, 2:19pm UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/41 "2024-09-02T14:19:57Z")

</div>

some here, I can also connect to that external address. Unfortunately I was also not able to scrape the information through a direct connection to the website, as it does not represent in an easy number anywhere on the site, the current amount of power being produced

My ECU-R is connected wirelessly through my router.

Just tried it wired, same result

---

<div class="post-metadata">

**Author:** ![Festini](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/festini/32/46348_2.png) [@Festini](https://community.homey.app/u/Festini)\
**Post date:** [September 2, 2024, 6:42pm UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/42 "2024-09-02T18:42:39Z")

</div>

It’s connected via Wifi and seems stable

---

<div class="post-metadata">

**Author:** ![Mombasa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mombasa/32/113225_2.png) [@Mombasa](https://community.homey.app/u/Mombasa)\
**Post date:** [September 2, 2024, 6:46pm UTC](https://community.homey.app/t/solar-system-from-apsystems/74759/43 "2024-09-02T18:46:21Z")

</div>

I noticed that the ECU-R has a poor uptime when connected via wireless. The moment I switched to a wired connection, the uptime was 100%. Please note that the IP adress will change the moment you switch to a cabel connection, so the url needs to be adjusted accordingly.

Please note that my script crawls this page and calculates all values from the Current Power column. If the page is inaccessible, the script will fail to function. Therefore, it is essential that this page loads correctly.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/1/1157cd431a3096974e4fca5d77cc5c7a8d6cb788.png)  
Since it almost dark right now you will not see any power

[Previous page](https://community.homey.app/t/solar-system-from-apsystems/74759.md?page=1)

[Next page](https://community.homey.app/t/solar-system-from-apsystems/74759.md?page=3)
