PVPC hourly Spanish energy prices API

FREEMIUM
Por willyfromtheblock | Atualizado 2ヶ月前 | Energy
Popularidade

7.4 / 10

Latência

80ms

Nível de serviço

100%

Health Check

N/A

Voltar para todos os tutoriais (3)

Sample script for openHAB

Following these steps will allow you to integrate this API into the openHAB home automation system.
This enables you to make decisions based on the current or future energy price.

Steps

  1. Create the three required openHAB items PVPCServer_current_price, PVPCServer_Currentpricerating and PVPCServer_Timestampforcurrentprice
  2. Add this script in the “Scripts” section of the settings, make sure to update your credentials (API-Key and API-Host)
  3. Run it hourly and at start up.

Script

(function() {
const response = actions.HTTP.sendHttpGetRequest('https://pvpc-hourly-spanish-energy-prices-api.p.rapidapi.com/price/0/peninsular', {
    'X-RapidAPI-Key': '**YOUR-RAPID-API-KEY**',
    'X-RapidAPI-Host': '**YOUR-RAPID-API-HOST**'
}, 10000);
const parsed = JSON.parse(response);

const currentPriceItem = items.getItem('PVPCServer_current_price');
currentPriceItem.postUpdate(parseFloat(parsed['price']));

const currentPriceRating = items.getItem('PVPCServer_Currentpricerating');
currentPriceRating.postUpdate(parsed['price_rating']);

const currentPriceTimeStamp = items.getItem('PVPCServer_Timestampforcurrentprice');
currentPriceTimeStamp.postUpdate(parsed['time']);
})();

Update rule

configuration: {}
triggers:

  • id: "1"
    configuration:
    cronExpression: 0 0 * * * ? *
    type: timer.GenericCronTrigger
  • id: "3"
    configuration:
    startlevel: 100
    type: core.SystemStartlevelTrigger
    conditions: []
    actions:
  • inputs: {}
    id: "2"
    configuration:
    considerConditions: true
    ruleUIDs:
    - YOUR_RULE_ID
    type: core.RunRuleAction