This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Shelly - WiFi IoT-Devices
#29
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:

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',
}
Reply


Messages In This Thread
Shelly - WiFi IoT-Devices - by Todayslife - 24.11.2020, 13:27
RE: Shelly - WiFi IoT-Devices - by admin - 24.11.2020, 13:35
RE: Shelly - WiFi IoT-Devices - by Todayslife - 28.11.2020, 14:31
RE: Shelly - WiFi IoT-Devices - by admin - 28.11.2020, 14:55
RE: Shelly - WiFi IoT-Devices - by Todayslife - 28.11.2020, 15:41
RE: Shelly - WiFi IoT-Devices - by admin - 30.11.2020, 07:21
RE: Shelly - WiFi IoT-Devices - by admin - 26.12.2020, 16:28
RE: Shelly - WiFi IoT-Devices - by admin - 28.12.2020, 07:49
RE: Shelly - WiFi IoT-Devices - by a455115 - 20.06.2022, 13:14
RE: Shelly - WiFi IoT-Devices - by a455115 - 13.10.2022, 14:26
RE: Shelly - WiFi IoT-Devices - by admin - 22.06.2022, 09:27
RE: Shelly - WiFi IoT-Devices - by a455115 - 24.06.2022, 10:21
RE: Shelly - WiFi IoT-Devices - by admin - 27.06.2022, 12:24
RE: Shelly - WiFi IoT-Devices - by a455115 - 29.06.2022, 13:45
RE: Shelly - WiFi IoT-Devices - by a455115 - 30.06.2022, 15:12
RE: Shelly - WiFi IoT-Devices - by admin - 30.06.2022, 15:19
RE: Shelly - WiFi IoT-Devices - by a455115 - 05.07.2022, 06:17
RE: Shelly - WiFi IoT-Devices - by admin - 01.07.2022, 06:09
RE: Shelly - WiFi IoT-Devices - by admin - 05.07.2022, 06:36
RE: Shelly - WiFi IoT-Devices - by a455115 - 05.07.2022, 10:40
RE: Shelly - WiFi IoT-Devices - by admin - 14.10.2022, 06:17
RE: Shelly - WiFi IoT-Devices - by a455115 - 17.10.2022, 09:53
RE: Shelly - WiFi IoT-Devices - by admin - 17.10.2022, 10:00
RE: Shelly - WiFi IoT-Devices - by a455115 - 17.10.2022, 14:51
RE: Shelly - WiFi IoT-Devices - by a455115 - 20.10.2022, 06:48
RE: Shelly - WiFi IoT-Devices - by admin - 20.10.2022, 07:44
RE: Shelly - WiFi IoT-Devices - by tomnord - 03.01.2024, 10:12
RE: Shelly - WiFi IoT-Devices - by admin - 03.01.2024, 10:19
RE: Shelly - WiFi IoT-Devices - by tomnord - 03.01.2024, 10:26
RE: Shelly - WiFi IoT-Devices - by tomnord - 03.01.2024, 14:46
RE: Shelly - WiFi IoT-Devices - by admin - 03.01.2024, 15:00
RE: Shelly - WiFi IoT-Devices - by tomnord - 16.01.2024, 08:51
RE: Shelly - WiFi IoT-Devices - by admin - 16.01.2024, 09:03
RE: Shelly - WiFi IoT-Devices - by tomnord - 16.01.2024, 09:49
RE: Shelly - WiFi IoT-Devices - by admin - 16.01.2024, 09:50
RE: Shelly - WiFi IoT-Devices - by tomnord - 16.01.2024, 09:54

Forum Jump: