(03.01.2024, 10:19)admin Wrote: You have duplicate keys in mqtt_to_object and mqtt_to_object_conv - this won't work. If multiple devices share the same topic then you need to manually implement logic for distinguishing what kind of data is received and which object must be updated.
Ok, I was afraid of that. So i need to make logic that only reads topic once, and then sorts out the different values I'm looking for.
So I made a function to look up certain names in the table, is there any way to have the mqtt_to_object run without a GA attached? It will only run the first grp.write:
Code:
function conv_shellyTemp(payload)
local data = require('json').pdecode(payload)
if type(data) == 'table' then
function tableHasKey(table, prefix)
for key, _ in pairs(table) do
--log(key)
if string.match(key, prefix) then
return true
end
end
return false
end
if tableHasKey(data["params"],"temperature") then
grp.write('33/1/8', data["params"]["temperature:100"]["tC"])
grp.write('33/1/10', data["params"]["temperature:101"]["tC"])
elseif
tableHasKey(data["params"],"switch") then
grp.write('33/1/9', data["params"]["switch:0"]["output"])
else
log("no data")
end
end
end