An unofficial wrapper for Iberdrola API in NodeJS based on zoilomora version.
npm install --save iberdrola-api
Iberdrola API is based on cookie sessions, so before making any request, you have wait until the request fisnishes.
var iberdrola = require('iberdrola-api').login({
email: '',
password: ''
});
iberdrola.ready.then(() => {
// Make requests
});
Alternativelly you can skip the Select Contract
method by simply adding it to the credentials
var iberdrola = require('iberdrola-api').login({
email: '',
password: '',
contract: ''
});
iberdrola.ready.then(() => {
// Login & Contract selected
}).catch((error) => {
if (error === 'no-access') console.error('Unable to login');
else if (error === 'no-contract') console.error('Unable to select contract');
else console.error('Unexcepted error', error);
});
Every method returns a Promise
:
An account may have 0 to N contracts, most method require to have a selected contract.
iberdrola.getContracts().then((result) => {
console.log({
constracts: result
})
}).catch(() => {
console.error('Unable to list contracts')
});
// Output:
{
direccion: 'False street 123',
cups: 'ES0000000000000000XX',
tipo: '',
tipUsoEnergiaCorto: '',
tipUsoEnergiaLargo: '',
estContrato: 'Alta',
codContrato: '0000000',
esTelegestionado: true,
presion: '0.00',
fecUltActua: '01.01.2019',
esTelemedido: false,
tipSisLectura: 'TG',
estadoAlta: true
}
Once you have selected to contract to operate, pick the codContrato
value, this step is required in order to proceed with the following method.
iberdrola.selectContract('<codContrato>').then(() => {
console.log('Contract selected');
// Execute the following methods
}).catch(() => {
console.error('Unable to select contract')
});
This method obtains your actual consumption (may take a while).
iberdrola.getReading().then((result) => {
console.log({
reading: result
});
}).catch(() => {
console.error('Unable to get reading');
});
// Output
{
hour: 19,
consumption: 238.95
}
This method gets the min
and max
(JS) dates in which you will be able to retreive data.
iberdrola.getDateLimits().then((result) => {
console.log({
limits: result
});
}).catch(() => {
console.error('Unable to get date limits');
});
// Output
{
min: 2018-06-20T00:00:00.000Z,
max: 2019-01-01T00:00:00.000Z
}
This method obtains the consuption (watts/hour) of every hour of a given day.
iberdrola.getReadingsOfDay('2019-02-08').then((result) => {
console.log({
readings: result
});
}).catch(() => {
console.error('Unable to get readings of day');
});
// Output
[
{ hour: 0, consumption: 123 },
{ hour: 1, consumption: 213 },
[...]
{ hour: 23, consumption: 253 }
]
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.