03.01.2024, 10:12
Hi, with the above code, you use broadcast topic "shellies". If I use a topic set in a device, eg a ShellyPluss1 (relay) eith add-on module, how can i sort the different values on the same topic?
I made this based on the above, but it only works on th ebinary status object, not temperature:
I made this based on the above, but it only works on th ebinary status object, not temperature:
Code:
function conv_shellyRelay(payload, numberRel, target_s_addr)
local data = require('json').pdecode(payload)
if type(data) == 'table' then
grp.write(target_s_addr, data["params"][numberRel]["output"])
log(data.bat.value)
return data.bat.value
end
end
function conv_shellyTemp(payload, numberTemp, target_t_addr)
local data = require('json').pdecode(payload)
if type(data) == 'table' then
log(data["params"][numberTemp]["tC"])
grp.write(target_t_addr, data["params"][numberTemp]["tC"])
return data.bat.value
end
end
-- topic to object map
mqtt_to_object = {
['Shelly/events/rpc'] = '33/1/8', -- Temperature 1
['Shelly/events/rpc'] = '33/1/9', -- Status relay
['Shelly/events/rpc'] = '33/1/10',-- Temperature 2
}
mqtt_to_object_conv = {
['Shelly/events/rpc'] = function(payload)
return conv_shellyTemp(payload,"temperature:100", '33/1/8')
end,
['Shelly/events/rpc'] = function(payload)
return conv_shellyTemp(payload,"temperature:101", '33/1/10')
end,
['Shelly/events/rpc'] = function(payload)
return conv_shellyRelay(payload,"switch:0", '33/1/9')
end,
}
-- object to topic map
object_to_mqtt = {
['33/1/7'] = 'Shelly/command/switch:0',
}