17.10.2022, 10:00
Try this:
Code:
mqtt_to_object = {
['shellies/shellytrv-14B457E5C2C8/info'] = '1/1/1', -- battery level
['shellies/shellytrv-ABC/info'] = '2/1/1', -- battery level
['shellies/shellytrv-DEF/info'] = '3/1/1', -- battery level
}
function conv_therm(payload, target_t_addr)
local data = require('json').pdecode(payload)
if type(data) == 'table' then
grp.write(target_t_addr, data.thermostats[1].target_t.value)
return data.bat.value
end
end
mqtt_to_object_conv = {
['shellies/shellytrv-14B457E5C2C8/info'] = function(payload)
return conv_therm(payload, '1/1/2') -- target temp
end,
['shellies/shellytrv-ABC/info'] = function(payload)
return conv_therm(payload, '2/1/2') -- target temp
end,
['shellies/shellytrv-DEF/info'] = function(payload)
return conv_therm(payload, '3/1/2') -- target temp
end
}