Subversion Repositories rld.domoticz

Rev

Blame | Last modification | View Log | Download

local myResponse

return {
  on = {
    devices = {
      'test'
    },
    shellCommandResponses = {
      'myResponse', -- must match with the callback passed to the executeShellCommand
    },
  },
  logging = {
    level = domoticz.LOG_INFO,
    marker = 'template',
  },
  execute = function(domoticz, item)

    if (item.isDevice) then
      domoticz.executeShellCommand({
        command = 'speedtest-cli --json',   -- just an example
        callback = 'myResponse', -- see shellCommandResponses above.
        timeout = 50, -- Max runtime 50 seconds
      })
    end

    if (item.isShellCommandResponse) then

      if (item.statusCode==0) then
        if (item.isJSON) then

          domoticz.log('Download speed is '.. item.json.download,domoticz.LOG_INFO)  -- just an example

          -- update some device in Domoticz
          domoticz.devices('myTextDevice').updateText(someValue)
        end
      else
        domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
        domoticz.log(item, domoticz.LOG_ERROR)
      end

    end

  end
}