Skip to content
Elias Ruemmler edited this page Jul 4, 2024 · 17 revisions

Objects

Define a new device (e.g. "EzoGateway") under userdata with 3 states for the measvalues.

Sample

Device and state tree: ioBroker objects

State settings: ioBroker objects Set the type to numeric and add a unit attribute if needed.

Script

Create a new script:

const url = 'http://<EzoGateway IP>/api/fetch';
const idTemp = '0_userdata.0.EzoGateway.Temperatur';
const idPH = '0_userdata.0.EzoGateway.pH_Wert';
const idRedox = '0_userdata.0.EzoGateway.Redox_Potential';
 

schedule('* * * * *', function() { //every minute
    request(url, function(error, response, result) {
        let obj = JSON.parse(result);
        setState(idTemp, obj['1'].Value, true);
        setState(idPH, obj['2'].Value, true);
        setState(idRedox, obj['3'].Value, true);
    });
});

Many thanks to paul53, for posting the script in ioBroker fourm.

Script with axios.get():

const axios = require('axios');

const url = 'http://<EzoGateway IP>/api/fetch';
const idTemp = '0_userdata.0.EzoGateway.Temperatur';
const idPH = '0_userdata.0.EzoGateway.pH_Wert';
const idRedox = '0_userdata.0.EzoGateway.Redox_Potential';
 

schedule('* * * * *', async function() { //every minute
    try
    {
        let response = await axios.get(url);
        let obj = response.data;
        setState(idTemp, obj['1'].Value, true);
        setState(idPH, obj['2'].Value, true);
        setState(idRedox, obj['3'].Value, true);
    }
    catch (error)
    {
        log(exMsg, 'error');
    }
});

Setup EzoGateway

Please note that the Cyclic Updater must be activated in the EzoGateway, otherwise the measured values would only be updated by trigger: Cyclic updater