Добрый день.
не могу вывести показания счетчиков в кубических метрах.
счетчик подключен к WB-MWAC (Demokit v3), показывают только импульсы (в Web ui).
создал правило:
var meterCorrection = 1779 // Корректировочное значение счетчика в литрах
var counterCorrection = 1 // Корректировочное значение WB-MCM8 в импульсах
var inpulseValue = 10 // Количество литров на один импульс
defineVirtualDevice("water_meters", { // Создаем виртуальный девайс для отображения в веб интерфейсе.
title: "Счетчики воды",
cells: {
water_meter_1: {
type: "value",
value: 0
},
}
});
defineRule("water_meter_1", {
whenChanged: "wb-mwac_25/P1 counter",
then: function(newValue, devName, cellName) {
if(newValue){
dev["water_meters/water_meter_1"] = ((parseInt(newValue) - counterCorrection) * inpulseValue) + meterCorrection; // Умножаем значение счетчика на количество литров/импульс и прибавляем корректировочное значение.
}
}
});
не помогает.
avspnz
30.Январь.2024 09:39:35
3
Добрый день.
Судя по правилу, у вас осуществляется пересчет импульсов в литры. Чтобы перевести литры в кубические метры — нужно разделить полученное значение на 1000:
dev["water_meters/water_meter_1"] = (((parseInt(newValue) - counterCorrection) * inpulseValue) + meterCorrection) / 1000;
Добрый день.
по Вашему совету получилось, понял что корректировочное значение мне не нужно. теперь значение не меняется.
var inpulseValue = 10 // Количество литров на один импульс
defineVirtualDevice("water_meters", { // Создаем виртуальный девайс для отображения в веб интерфейсе.
title: "Счетчики воды",
cells: {
water_meter_1: {
type: "value",
value: 0
},
}
});
defineRule("water_meter_1", {
whenChanged: "wb-mwac_25/P1 counter",
then: function(newValue, devName, cellName) {
if(newValue){
dev["water_meters/water_meter_1"] = (parseInt(newValue * inpulseValue)) /1000; // Умножаем значение счетчика на количество литров/импульс.
}
}
});
wb-mwac_25/P1 counter
counter - с маленькой буквы
а возможно, чтоб после цифр подписывало м3?
Вот описание доступных типов:
Wiren Board MQTT Conventions
================================
The basic abstractions are *devices* and their *controls*.
Each *device* has some *controls* assigned to it, i.e. parameters that can be controlled or monitored. *Devices* and *controls* are identified by names (arbitrary strings), and have some metadata. Metadata messages are published on device startup with `retained` flag set.
For example, some room lighting control *device* with one input (for wall switch) and one output (for controlling the lamp) *controls* is represented with MQTT topics as following:
* `/devices/RoomLight/meta` - JSON with all meta information about *device*
* `/devices/RoomLight/meta/error` - device-level error state, non-null means there was an error (usable as Last Will and Testament)
* `/devices/RoomLight/controls/Lamp` - contains current lamp state, '0' = off, '1' = on
* `/devices/RoomLight/controls/Lamp/on` - send a message with this topic and payload of '0'/'1' to turn lamp off or on
* `/devices/RoomLight/controls/Lamp/meta` - JSON with all meta information about control
* `/devices/RoomLight/controls/Switch` - contains current wall switch state
* `/devices/RoomLight/controls/Switch/meta` - JSON with all meta information about control
* `/devices/RoomLight/controls/Switch/meta/error` - non-null value means there was an error reading or writing the control. In this case `/devices/RoomLight/controls/Switch` contains last known good value.
Each *device* usually represents the single physical device or one of the integrated peripheral of a complex physical device, although there are some boundary cases where the distinction is not clear. The small and not-so-complex real-world devices (say, wireless weather sensor) are ought to be represented by a single *device* in the MQTT hierarchy.
Each *device* must be handled by a single driver or publisher, though it's not enforced in any way.
This file has been truncated. show original
Тут есть описание API как можно изменить units для контрола
Думаю можно это сделать и без вызова функции, а прямо в описании устройства, но быстро найти пример не смог.
water_meter_1: {
type: "value",
value: 0,
units: "m^3"
},
В документации на wb-rules действительно этого нет, добавим.
1 лайк