-
-
Notifications
You must be signed in to change notification settings - Fork 7
ioBroker sample
Elias Ruemmler edited this page Jul 4, 2024
·
17 revisions
Define a new device (e.g. "EzoGateway") under userdata with 3 states for the measvalues.
Device and state tree:
State settings:
Set the type to numeric
and add a unit
attribute if needed.
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');
}
});
Please note that the Cyclic Updater must be activated in the EzoGateway, otherwise the measured values would only be updated by trigger: