Добрый день, Александр.
Вот все мои правила, где крон используется:
defineVirtualDevice('hardnode', {
title: 'Hardnode',
cells: {
'CPU temperature' : {
type : 'temperature',
value: ''
},
'Fan1 speed' : {
type : 'text',
value: ''
},
'Fan2 speed' : {
type : 'text',
value: ''
}
}
});
defineRule("hardnode.status", {
when: cron("@every 10s"),
then: function () {
runShellCommand("/etc/wb-rules/services/dio sensors", {
captureOutput: true,
exitCallback: function (exitCode, capturedOutput) {
var data = JSON.parse(capturedOutput);
dev['hardnode']['CPU temperature'] = data['cpu_temp'];
dev['hardnode']['Fan1 speed'] = data['fans'][0] || "0";
dev['hardnode']['Fan2 speed'] = data['fans'][1] || "0";
}
});
}
});
defineVirtualDevice('ups', {
title: 'UPS',
cells: {
'Battery charge' : {
type : 'text',
value: ''
},
'Input voltage' : {
type : 'voltage',
value: ''
},
'Load' : {
type : 'text',
value: ''
},
'Status' : {
type : 'text',
value: ''
}
}
});
defineRule("ups.status", {
when: cron("@every 10s"),
then: function () {
runShellCommand("/etc/wb-rules/services/dio ups", {
captureOutput: true,
exitCallback: function (exitCode, capturedOutput) {
var data = JSON.parse(capturedOutput);
dev['ups']['Battery charge'] = data['battery.charge'].toString() || 0;
dev['ups']['Input voltage'] = parseFloat(data['input.voltage']) || 0;
dev['ups']['Load'] = data['ups.load'] ? data['ups.load'] + '%' : 0;
if (data['ups.status']) {
if (data['ups.status'] == 'OL' || data['ups.status'] == 'OL CHRG' || data['ups.status'] == 'OL CHRG LB') {
dev['ups']['Status'] = 'Online';
} else if (data['ups.status'] == 'OB' || data['ups.status'] == 'OB DISCHRG') {
dev['ups']['Status'] = 'Battery';
} else {
dev['ups']['Status'] = 'Low battery';
}
} else if (data['error']) {
dev['ups']['Status'] = data['error'];
}
}
});
}
});
defineVirtualDevice('util', {
title: 'Util', //
cells: {
'Alive': {
type: 'text',
value: ''
},
}
});
defineRule("_keep_alive", {
when: cron("1 * * * *"),
then: function () {
var d = new Date();
dev.util['Alive'] = Math.floor(d.getTime() / 1000).toString();
}
});
defineVirtualDevice('weather', {
title: 'Weather',
cells: {
'LIM AQ' : {
type : 'text',
value: ''
},
'ULN wind' : {
type : 'text',
value: ''
},
'ULN wind direction' : {
type : 'text',
value: ''
},
'ULN temperature' : {
type : 'temperature',
value: 0
}
}
});
defineRule("weather.status", {
when: cron("@every 15m"),
then: function () {
runShellCommand("/etc/wb-rules/services/dio weather", {
captureOutput: true,
exitCallback: function (exitCode, capturedOutput) {
var data = JSON.parse(capturedOutput);
dev['weather']['LIM AQ'] = data['air_quality'].toString() || 0
dev['weather']['ULN wind'] = data['wind'].toString() || 0;
dev['weather']['ULN wind direction'] = data['wind_direction'].toString() || 0;
dev['weather']['ULN temperature'] = data['temperature'] || 0;
}
});
}
});