It works very simple.
1) Create the sensor on the slave using the dummy device or a plugin.
2) Create the same sensor on the master using the dummy device. Make sure you create the same type.
3) Copy this script to the slave
4) Change the URL to the master
5) Edit the mapping table in the script. [slave idx] = {remoteIdx = 'master idx'}
6) Now as soon as the sensor on the slave get's an update the value is pushed to the master.
In the script below only the sensor types used by the Xiaomi Mi Flower Mate are added, but it can be easily extended for other sensor types. Just add an elseif for the correct type/subtype and make sure to use the correct json found here https://www.domoticz.com/wiki/Domoticz ... .2Fsensors
Code: Select all
local server = 'http://192.168.2.10:8080'
local MAPPING = {
[56] = {remoteIdx = 999}, -- Plant 1: Vocht
[22] = {remoteIdx = 703}, -- Plant 1: Temperatuur
[23] = {remoteIdx = 704}, -- Plant 1: Lucht
[24] = {remoteIdx = 705}, -- Plant 1: Voeding
[57] = {remoteIdx = 1000}, -- Plant 2: Vocht
[26] = {remoteIdx = 707}, -- Plant 2: Temperatuur
[27] = {remoteIdx = 708}, -- Plant 2: Lucht
[28] = {remoteIdx = 709}, -- Plant 2: Voeding
[58] = {remoteIdx = 1001}, -- Plant 3: Vocht
[30] = {remoteIdx = 711}, -- Plant 3: Temperatuur
[31] = {remoteIdx = 712}, -- Plant 3: Lucht
[32] = {remoteIdx = 713}, -- Plant 3: Voeding
[59] = {remoteIdx = 1002}, -- Plant 4: Vocht
[34] = {remoteIdx = 715}, -- Plant 4: Temperatuur
[35] = {remoteIdx = 716}, -- Plant 4: Lucht
[36] = {remoteIdx = 717}, -- Plant 4: Voeding
[60] = {remoteIdx = 1003}, -- Plant 5: Vocht
[53] = {remoteIdx = 719}, -- Plant 5: Temperatuur
[54] = {remoteIdx = 720}, -- Plant 5: Lucht
[55] = {remoteIdx = 721}, -- Plant 5: Voeding
[61] = {remoteIdx = 1004}, -- Plant 6: Vocht
[48] = {remoteIdx = 723}, -- Plant 6: Temperatuur
[49] = {remoteIdx = 724}, -- Plant 6: Lucht
[50] = {remoteIdx = 725}, -- Plant 6: Voeding
}
---------- Script starts here ----------
local callbackString = 'RemoteDataPush_callback'
local getTriggerDevices = function()
local tDevs = {}
for idx, _ in pairs(MAPPING) do
tDevs[idx] = idx
end
return(tDevs)
end
return {
on = {
devices = getTriggerDevices(),
httpResponses = { callbackString }
},
logging = {
-- level = domoticz.LOG_DEBUG,
level = domoticz.LOG_INFO,
-- level = domoticz.LOG_ERROR,
marker = "Remote Data Push"
},
execute = function(dz, item, info)
if item.isDevice then
dz.log('Send data to ' .. server .. ' - local idx = ' .. item.idx .. ' - remote idx = ' .. MAPPING[item.idx].remoteIdx ..' - deviceType = ' .. item.deviceType .. ' - deviceSubType = ' .. item.deviceSubType .. ' - nvalue = ' .. item.nValue .. ' - svalue = ' .. item.sValue)
if item.deviceType == 'General' and item.deviceSubType == 'Custom Sensor' then
dz.openURL({url = server .. '/json.htm?type=command¶m=udevice&idx=' .. MAPPING[item.idx].remoteIdx ..'&nvalue=0&svalue=' .. item.sValue, callback = callbackString})
elseif item.deviceType == 'General' and item.deviceSubType == 'Soil Moisture' then
dz.openURL({url = server .. '/json.htm?type=command¶m=udevice&idx=' .. MAPPING[item.idx].remoteIdx ..'&nvalue=' .. item.nValue, callback = callbackString})
elseif item.deviceType == 'General' and item.deviceSubType == 'Percentage' then
dz.openURL({url = server .. '/json.htm?type=command¶m=udevice&idx=' .. MAPPING[item.idx].remoteIdx ..'&nvalue=0&svalue=' .. item.nValue, callback = callbackString})
elseif item.deviceType == 'Lux' and item.deviceSubType == 'Lux' then
dz.openURL({url = server .. '/json.htm?type=command¶m=udevice&idx=' .. MAPPING[item.idx].remoteIdx ..'&svalue=' .. item.sValue, callback = callbackString})
elseif item.deviceType == 'Temp' and item.deviceSubType == 'LaCrosse TX3' then
dz.openURL({url = server .. '/json.htm?type=command¶m=udevice&idx=' .. MAPPING[item.idx].remoteIdx ..'&nvalue=0&svalue=' .. item.sValue, callback = callbackString})
elseif item.deviceType == 'Humidity' and item.deviceSubType == 'LaCrosse TX3' then
dz.openURL({url = server .. '/json.htm?type=command¶m=udevice&idx=' .. MAPPING[item.idx].remoteIdx ..'&nvalue=' .. item.nValue .. '&svalue=' .. item.sValue, callback = callbackString})
else
dz.log('Not implemented devicetype found. Devicetype = ' .. item.deviceType .. ' subtype = ' .. item.deviceSubType, dz.LOG_ERROR)
end
elseif item.isHTTPResponse then
if item.json.status == 'OK' then
dz.log('Updated the remote device succesfully.')
dz.log(item.json)
else
dz.log('Something went wrong updating the remote device', dz.LOG_ERROR)
dz.log(item.json, dz.LOG_ERROR)
end
else
dz.log('Unknown script trigger.', dz.LOG_ERROR)
end
end
}