Created
January 9, 2022 17:28
-
-
Save stas-dovgodko/e471b2ccedaa778fb42c474c8c12b097 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let proxy = require('openhab-proxy-pattern'); | |
/* | |
proxy.bind(proxy_item_name, hardware_item_name).update([callback]).forward([callback]); | |
*/ | |
// проксирование от железа в виртуалку | |
proxy.bind('Equipment_WF_OutTemperature', 'SmartMAC_D105_1_T2').update(); | |
// проксирование в обе стороны | |
proxy.bind("GF_Toilet_MirrorLight", "Shelly_25R_3_1Output") | |
.forward() | |
.update(); | |
// проксирование с преобразованием значения | |
proxy.bind('Equipment_ElectricityInverterBattery_Voltage', 'PZEM_1_Voltage') | |
.update(function(value) { | |
if (typeof value == 'string') { | |
const v = parseInt(value) / 100; | |
return `${v} V`; | |
} else { | |
return undefined; | |
} | |
}); | |
// расширенный пример проксирования списка элементов | |
let phases = ['A', 'B', 'C']; | |
const v = function(value) { | |
if (typeof value == 'string') { | |
const v = parseInt(value); | |
return `${v} V`; | |
} else return undefined; | |
}; | |
phases.forEach(function(phase) { | |
proxy.bind(`Equipment_ElectricityHomeV${phase}`, `Shelly_EM3_2_${phase}Voltage`) | |
.update(v); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment