# \[APP\]\[Pro\] Power by the Hour: Insights per hour, day, month and year

**URL:** <https://community.homey.app/t/app-pro-power-by-the-hour-insights-per-hour-day-month-and-year/20535>\
**Category:** Apps\
**Tags:** app, tools\
**Created:** [November 10, 2019, 10:06pm UTC](https://community.homey.app/t/app-pro-power-by-the-hour-insights-per-hour-day-month-and-year/20535 "2019-11-10T22:06:03Z")\
**Posts on this page:** 1\
**Showing post:** 3353

<div class="post-metadata">

**Author:** ![Rrrr](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rrrr/32/629_2.png) [@Rrrr](https://community.homey.app/u/Rrrr)\
**Post date:** [November 16, 2025, 1:01pm UTC](https://community.homey.app/t/app-pro-power-by-the-hour-insights-per-hour-day-month-and-year/20535/3353 "2025-11-16T13:01:10Z")

</div>

> [@Rrrr](#):
>
> But if I look at the 15 min device, the prices in the +1H, +2H seem to be the 15 min prices.
> 
> ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/a/fa72500a071d501543c2ae0a7f71d5f1610264d7.png)
> 
> > [@Gruijter](#):
> >
> > No, they are indeed the +1H, +2H etc.

Two questions for @Gruijter

1. Unfortunately, the 15 min device still shows the wrong headings for the prices (in the test version). These are +15M, +30M, +45M prices, but the heading reads Price +1H, Price +2H, etc. Do you agree or do I misunderstand?

2. If I manipulate the prices to reflect taxes, weekends, nights, will the prices for +15M, +30M, etc automatically be corrected?  
I am using for example the flow card for Time of Day markup: 7:0.1;22:0  
Eg. When night tariff starts at 22:00, then the Price Now reflects that, but will the +15M price still reflect day tariff until it is 22:15pm?

Many thanks

PS For those that want to work with hour prices based on the average of 15 min prices, here is a Homey script that calculates the average of 4 consecutive prices, starting from a period (0 or higher) that you need to provide as numerical input. The script will return a number tag Result with the average.

Note that it requires that all “New Prices Received for Next Hours“ from the DAP are stored in Homey variable EnergyPricesJSON

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

```auto
// --- Homey SCRIPT V2.1 --- Average EnergyPrices 4 periods---
// IMPORTANT: Change this to the exact name of your Homey variable 
// that holds the energy price JSON data.
const ENERGY_PRICE_VARIABLE_NAME = 'EnergyPricesJSON';
// --- SCRIPT LOGIC (No need to edit below this line) ---

// 1. Get the starting period from the input argument of the Flow card.
const startPeriodInput = args[0];

// 2. Convert the input argument to an integer.
const startPeriod = parseInt(startPeriodInput, 10);

// 3. Validate that the conversion resulted in a valid number.
if (isNaN(startPeriod)) {
  const errorMsg = `Error: Input must be a number. Received: '${startPeriodInput}'`;
  log(errorMsg);
  throw new Error(errorMsg);
}

// 4. Get all logic variables from Homey. (CHANGED)
const allVariables = await Homey.logic.getVariables();

// 5. Find your specific variable from the list by its name. (CHANGED)
const priceVariable = Object.values(allVariables).find(
  variable => variable.name === ENERGY_PRICE_VARIABLE_NAME
);

// 6. Check if the variable was found.
if (!priceVariable) {
  const errorMsg = `Error: Variable '${ENERGY_PRICE_VARIABLE_NAME}' not found. Please check the name in the script configuration.`;
  log(errorMsg);
  throw new Error(errorMsg);
}

// 7. Get the JSON string from the variable's 'value' property.
const priceDataJSON = priceVariable.value;

// 8. Check if the variable contains data.
if (!priceDataJSON || typeof priceDataJSON !== 'string') {
  const errorMsg = `Error: Variable '${ENERGY_PRICE_VARIABLE_NAME}' is empty or not a string.`;
  log(errorMsg);
  throw new Error(errorMsg);
}

// 9. Parse the JSON string into a JavaScript object.
let priceDataObject;
try {
  priceDataObject = JSON.parse(priceDataJSON);
} catch (e) {
  const errorMsg = `Error parsing JSON from variable '${ENERGY_PRICE_VARIABLE_NAME}'. Please check its content.`;
  log(errorMsg);
  throw new Error(errorMsg);
}

// 10. Calculate the sum of the prices for the 4 consecutive periods.
let sumOfPrices = 0;
const numberOfPeriods = 4;

for (let i = 0; i < numberOfPeriods; i++) {
  const currentPeriodKey = String(startPeriod + i);
  const price = priceDataObject[currentPeriodKey];

  if (price === undefined || typeof price !== 'number') {
    const errorMsg = `Error: Price for period '${currentPeriodKey}' not found or is not a number.`;
    log(errorMsg);
    throw new Error(errorMsg);
  }
  
  sumOfPrices += price;
}

// 11. Calculate the average price.
const averagePrice = sumOfPrices / numberOfPeriods;

// 12. Log the result for debugging in the Homey Script editor.
log(`Starting at period ${startPeriod}, the sum is ${sumOfPrices.toFixed(4)} and the average price over 4 periods is ${averagePrice.toFixed(4)}.`);

// 13. Return the calculated average so it can be used in your Flow.
return averagePrice;

```

---

_[View the full topic](https://community.homey.app/t/app-pro-power-by-the-hour-insights-per-hour-day-month-and-year/20535)._
