# General Homey Script development questions

**URL:** <https://community.homey.app/t/general-homey-script-development-questions/85225>\
**Category:** Developers\
**Tags:** homeyscript, javascript, homey-pro\
**Created:** [July 25, 2023, 7:33am UTC](https://community.homey.app/t/general-homey-script-development-questions/85225 "2023-07-25T07:33:47Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Wout\_van\_den\_Dool](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/wout_van_den_dool/32/391_2.png) [@Wout\_van\_den\_Dool](https://community.homey.app/u/Wout_van_den_Dool)\
**Post date:** [January 22, 2024, 9:54pm UTC](https://community.homey.app/t/general-homey-script-development-questions/85225/3 "2024-01-22T21:54:09Z")

</div>

Hi Robert or others,  
I have this script and output, now I want to store the variables in a virtual device and that worked for me with my [Qingping](https://community.homey.app/t/qingping-air-monitor-lite-homeyscript/44222) …

However I am doing something wrong for my Eplucon (Ecoforest) Heatpump, since these variables do not appear in my flow as tags. What should I change?

This is the

```auto
// Login and get access token
var result = await fetch("https://portaal.eplucon.nl/api/v2/auth/login", {
  method: 'post',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  },
  body: JSON.stringify({
    username: 'PASSWORD',
    password: 'PASSWORD'
  }),
});

if (!result.ok) throw new Error(result.statusText);

const body = await result.json();
console.log(body)

var access_token = body.access_token;
await tag("eplucon_access_token", access_token);

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

// Fetch statistics
const urlStats = `https://portaal.eplucon.nl/api/v2/econtrol/modules/1000704/statistics?range=day&day=${currentDate.getDate()}&month=${currentDate.getMonth() + 1}&year=${currentDate.getFullYear()}`;
const optionsStats = {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${access_token}`,
    'Accept': 'application/json'
  }
};

try {
  const responseStats = await fetch(urlStats, optionsStats);
  const dataStats = await responseStats.json();
  
  // Get the latest data point
  const latestDataStats = dataStats.data.data[dataStats.data.data.length - 1];
  
  // Create an object with the desired structure
  const output = {
    Binnentemperatuur: { value: latestDataStats.Binnentemperatuur },
    WW_temperatuur: { value: latestDataStats['WW temperatuur'] },
    Actuele_temp_DG1: { value: latestDataStats['Actuele temp. DG1'] },
    Brine_in_temperatuur: { value: latestDataStats['Brine in temperatuur'] },
    Brine_out_temperatuur: { value: latestDataStats['Brine out temperatuur'] },
    Heating_in_temperatuur: { value: latestDataStats['Heating in temperatuur'] },
    Heating_out_temperatuur: { value: latestDataStats['Heating out temperatuur'] },
    Buitentemp: { value: latestDataStats['Buitentemp.'] },
    Timestamp: { value: latestDataStats.created_at },
  };
  
  // Log the output
  console.log(output);
} catch (error) {
  console.error(error);
}

```

That result in this output in Homeyscript:

{  
login: true,  
access\_token: ‘XXXXXXXXXXXXXXXXXXXXXX’,  
error\_code: 200  
}  
{  
Binnentemperatuur: { value: 18.6 },  
WW\_temperatuur: { value: 47.3 },  
Actuele\_temp\_DG1: { value: 27.1 },  
Brine\_in\_temperatuur: { value: 6.4 },  
Brine\_out\_temperatuur: { value: 6.2 },  
Heating\_in\_temperatuur: { value: 30.3 },  
Heating\_out\_temperatuur: { value: 27.1 },  
Buitentemp: { value: 6.1 },  
Timestamp: { value: ‘2024-01-22T21:20:00’ }  
}

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

---

_[View the full topic](https://community.homey.app/t/general-homey-script-development-questions/85225)._
