Page 25 of 30

Re: dtgbot - Domoticz TeleGram BOT

Posted: Wednesday 12 January 2022 13:11
by mojso
It would be nice if I could, but my knowledge is not that great for sh or lua scripts. it would be nice if there could be a command to get the value of devices

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 13 January 2022 15:07
by jvdz
@mojso, Which version are you running?
It is quite easy to adapt devices.lua and add the status to the end of the found devicename.

This is for the current Master:
Just :

  • make a backup of the current devices.lua
  • replace the content with the below source.
  • Restart DTGBOT
  • Try command devices name st
command devices name will still only give the matching names in a list.

Code: Select all

local devices_module = {}
local http = require "socket.http"
--JSON = assert(loadfile "JSON.lua")() -- one-time load of the routines

function DevicesScenes(DeviceType, qualifier, state)
  switchstatus = ""
  local response = "", ItemNumber, result, decoded_response, record, k
  print_to_log(qualifier)
  if qualifier ~= nil then
    response = "All " .. DeviceType .. " starting with " .. qualifier
    qaulifier = string.lower(qualifier)
    quallength = string.len(qualifier)
  else
    response = "All available " .. DeviceType
  end
  decoded_response = device_list(DeviceType)
  result = decoded_response["result"]
  StoredType = DeviceType
  StoredList = {}
  ItemNumber = 0
  if result ~= nil then
    for k, record in pairs(result) do
      if type(record) == "table" then
        DeviceName = record["Name"]
        -- Don't bother to store Unknown devices
        if DeviceName ~= "Unknown" then
          if qualifier ~= nil then
            if qualifier == string.lower(string.sub(DeviceName, 1, quallength)) then
              ItemNumber = ItemNumber + 1
              if (state or "") ~= ""  then
                -- get dev status when requested
                didx, dDeviceName, dDeviceType, dType, dSwitchType, dMaxDimLevel, switchstatus, LevelNames, LevelInt = devinfo_from_name(0, DeviceName)
                if ChkEmpty(switchstatus) then
                  switchstatus = ""
                else
                  if dSwitchType == "Selector" then
                    switchstatus = " - " .. getSelectorStatusLabel(get.actions, LevelInt)
                  else
                    -- Print_to_Log(0,switchstatus)
                    switchstatus = tostring(switchstatus)
                    switchstatus = switchstatus:gsub("Set Level: ", "")
                    switchstatus = "->" .. switchstatus
                  end
                end
              end
              table.insert(StoredList, DeviceName .. switchstatus)
            end
          else
            ItemNumber = ItemNumber + 1
            table.insert(StoredList, DeviceName)
          end
        end
      end
    end
  end
  table.sort(StoredList)
  if #StoredList ~= 0 then
    for ItemNumber, DeviceName in ipairs(StoredList) do
      response = response .. "\n" .. ItemNumber .. " - " .. StoredList[ItemNumber]
    end
  else
    response = response .. " none found"
  end
  return response
end

function devices_module.handler(parsed_cli)
  local response = ""
  response = DevicesScenes(string.lower(parsed_cli[2]), parsed_cli[3], parsed_cli[4])
  return status, response
end

local devices_commands = {
  ["devices"] = {handler = devices_module.handler, description = "devices - devices - return list of all devices\ndevices - devices qualifier - all that start with qualifier i.e.\n devices St - all devices that start with St"},
  ["scenes"] = {handler = devices_module.handler, description = "scenes - scenes - return list of all scenes\ndevices - devices qualifier - all that start with qualifier i.e.\n scenes down - all scenes that start with down"}
}

function devices_module.get_commands()
  return devices_commands
end

return devices_module

Re: dtgbot - Domoticz TeleGram BOT

Posted: Friday 14 January 2022 0:28
by mojso
jvdz wrote: Thursday 13 January 2022 15:07 @mojso, Which version are you running?
It is quite easy to adapt devices.lua and add the status to the end of the found devicename.

This is for the current Master:
Just :

  • make a backup of the current devices.lua
  • replace the content with the below source.
  • Restart DTGBOT
  • Try command devices name st
command devices name will still only give the matching names in a list.

Code: Select all

local devices_module = {}
local http = require "socket.http"
--JSON = assert(loadfile "JSON.lua")() -- one-time load of the routines

function DevicesScenes(DeviceType, qualifier, state)
  switchstatus = ""
  local response = "", ItemNumber, result, decoded_response, record, k
  print_to_log(qualifier)
  if qualifier ~= nil then
    response = "All " .. DeviceType .. " starting with " .. qualifier
    qaulifier = string.lower(qualifier)
    quallength = string.len(qualifier)
  else
    response = "All available " .. DeviceType
  end
  decoded_response = device_list(DeviceType)
  result = decoded_response["result"]
  StoredType = DeviceType
  StoredList = {}
  ItemNumber = 0
  if result ~= nil then
    for k, record in pairs(result) do
      if type(record) == "table" then
        DeviceName = record["Name"]
        -- Don't bother to store Unknown devices
        if DeviceName ~= "Unknown" then
          if qualifier ~= nil then
            if qualifier == string.lower(string.sub(DeviceName, 1, quallength)) then
              ItemNumber = ItemNumber + 1
              if (state or "") ~= ""  then
                -- get dev status when requested
                didx, dDeviceName, dDeviceType, dType, dSwitchType, dMaxDimLevel, switchstatus, LevelNames, LevelInt = devinfo_from_name(0, DeviceName)
                if ChkEmpty(switchstatus) then
                  switchstatus = ""
                else
                  if dSwitchType == "Selector" then
                    switchstatus = " - " .. getSelectorStatusLabel(get.actions, LevelInt)
                  else
                    -- Print_to_Log(0,switchstatus)
                    switchstatus = tostring(switchstatus)
                    switchstatus = switchstatus:gsub("Set Level: ", "")
                    switchstatus = "->" .. switchstatus
                  end
                end
              end
              table.insert(StoredList, DeviceName .. switchstatus)
            end
          else
            ItemNumber = ItemNumber + 1
            table.insert(StoredList, DeviceName)
          end
        end
      end
    end
  end
  table.sort(StoredList)
  if #StoredList ~= 0 then
    for ItemNumber, DeviceName in ipairs(StoredList) do
      response = response .. "\n" .. ItemNumber .. " - " .. StoredList[ItemNumber]
    end
  else
    response = response .. " none found"
  end
  return response
end

function devices_module.handler(parsed_cli)
  local response = ""
  response = DevicesScenes(string.lower(parsed_cli[2]), parsed_cli[3], parsed_cli[4])
  return status, response
end

local devices_commands = {
  ["devices"] = {handler = devices_module.handler, description = "devices - devices - return list of all devices\ndevices - devices qualifier - all that start with qualifier i.e.\n devices St - all devices that start with St"},
  ["scenes"] = {handler = devices_module.handler, description = "scenes - scenes - return list of all scenes\ndevices - devices qualifier - all that start with qualifier i.e.\n scenes down - all scenes that start with down"}
}

function devices_module.get_commands()
  return devices_commands
end

return devices_module
I think I have the latest version of dtgbot.
Devices name st works great.
Thank you

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 10:00
by phenix56
Sorry to bump this thread again, but does anyone know how to compile the 64-bit versions of the lua libaries? After upgrading (and re-installing) to Bullseye, I got the 64-bit version. However, the pre-compiled libraries are all 32-bit...

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 10:13
by jvdz
I've worked on another version some time ago which also uses standard install libraries in stead of the manual compiled version.
I am running it now for a year and is is rock solid for me.
Have a look here to see if that also works for you: https://github.com/steps39/dtgbot/tree/ ... ew-install

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 10:17
by phenix56
So it is a complete diffrent version? I cannot use the old 'dtgbot' folder anymore? I have a backup of all my configs etc, and I was hoping I could still use that one. Are there diffrent installation instructions for the new verion?

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 10:19
by jvdz
phenix56 wrote: Saturday 02 April 2022 10:17 So it is a complete diffrent version? I cannot use the old 'dtgbot' folder anymore?
I have rewritten some of the logic to make it more stable. All you need to do is upgrade to this version of scripts, but I recomment always to make a backup first so you can roll back if needed.
phenix56 wrote: Saturday 02 April 2022 10:17 Are there diffrent installation instructions for the new verion?
Did you look at the linked page? ;)

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 10:20
by phenix56
Yes, I tool a look at the link, but there are only instructions to install some components. Can I follow the regular guide for the rest part? Or are the new files located somewhere else?

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 10:26
by phenix56
Okay so I've installed lua-json and lua-socket, and proceeded following the guide. However, when I try to start the service, it instantly stops. When I open the dtb.log.errors file, this is the content:

/usr/bin/lua5.2: /home/pi/dtgbot/dtgbot.lua:132: module 'ssl.https' not found:
no field package.preload['ssl.https']
no file '/usr/local/share/lua/5.2/ssl/https.lua'
no file '/usr/local/share/lua/5.2/ssl/https/init.lua'
no file '/usr/local/lib/lua/5.2/ssl/https.lua'
no file '/usr/local/lib/lua/5.2/ssl/https/init.lua'
no file '/usr/share/lua/5.2/ssl/https.lua'
no file '/usr/share/lua/5.2/ssl/https/init.lua'
no file './ssl/https.lua'
no file '/usr/local/lib/lua/5.2/ssl/https.so'
no file '/usr/lib/aarch64-linux-gnu/lua/5.2/ssl/https.so'
no file '/usr/lib/lua/5.2/ssl/https.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './ssl/https.so'
no file '/usr/local/lib/lua/5.2/ssl.so'
no file '/usr/lib/aarch64-linux-gnu/lua/5.2/ssl.so'
no file '/usr/lib/lua/5.2/ssl.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './ssl.so'
stack traceback:
[C]: in function 'require'
/home/pi/dtgbot/dtgbot.lua:132: in main chunk
[C]: in ?

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 10:28
by jvdz
It looks like it still is trying to use your local version of the socket, so guess that needs to be removed. just revert the additions made previously for the downloaded extra files as it now needs to use the installed version of these libraries,

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 10:30
by phenix56
Uhm, what do you mean exactly? Remove the folders created for lua 5.2?

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 10:32
by jvdz
I mean you need to get rid of the files you installed in this step: https://www.domoticz.com/wiki/Remote_Co ... _Libraries

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 10:34
by phenix56
I already did. I removed all the folders, so now there is no /usr/local/share/luz/5.2 folder anymore, for example. But somehow it still tries to use them. If you're talking about JQ: I did not do that. Di I need to remove those folders as well?

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 11:50
by jvdz
/usr/bin/lua5.2: /home/pi/dtgbot/dtgbot.lua:132: module 'ssl.https' not found:
I seems you are still running the "Master version" of the script and not the linked new version? as line 132 in the master version is:

Code: Select all

https = require "ssl.https";

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 11:51
by phenix56
I tried both 'git clone', followed by the link and the instructions, both fail. How should I install the new version?

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 11:57
by jvdz
Probably something like this:

Code: Select all

git clone https://github.com/steps39/dtgbot -b Statility-and-new-install

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 12:00
by phenix56
I ran that command, offcourse removing the old folder before running it, and now the log gives me a diffrent error:

/usr/bin/lua5.2: /home/pi/dtgbot/dtgbot.lua:97: Terminate DTGBOT as the initialisation failed, which frst needs to be fixed.
stack traceback:
[C]: in function 'error'
/home/pi/dtgbot/dtgbot.lua:97: in main chunk
[C]: in ?

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 12:04
by jvdz
There should be more info in the dtgbot.log about the issue it encounters.

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 12:06
by phenix56
Okay. The contents of dtgbot.log are:


### Initialialisation process Failed:
Error-->/home/pi/dtgbot/dtgbot.lua:44: module 'ssl.https' not found:
no field package.preload['ssl.https']
no file '/home/pi/dtgbot/ssl/https.lua'
no file '/home/pi/dtgbot/ssl/https.cfg'
no file '/usr/local/share/lua/5.2/ssl/https.lua'
no file '/usr/local/share/lua/5.2/ssl/https/init.lua'
no file '/usr/local/lib/lua/5.2/ssl/https.lua'
no file '/usr/local/lib/lua/5.2/ssl/https/init.lua'
no file '/usr/share/lua/5.2/ssl/https.lua'
no file '/usr/share/lua/5.2/ssl/https/init.lua'
no file './ssl/https.lua'
no file '/usr/local/lib/lua/5.2/ssl/https.so'
no file '/usr/lib/aarch64-linux-gnu/lua/5.2/ssl/https.so'
no file '/usr/lib/lua/5.2/ssl/https.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './ssl/https.so'
no file '/usr/local/lib/lua/5.2/ssl.so'
no file '/usr/lib/aarch64-linux-gnu/lua/5.2/ssl.so'
no file '/usr/lib/lua/5.2/ssl.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './ssl.so'stack traceback:
/home/pi/dtgbot/dtgbot.lua:24: in function </home/pi/dtgbot/dtgbot.lua:23>
[C]: in function 'require'
/home/pi/dtgbot/dtgbot.lua:44: in function </home/pi/dtgbot/dtgbot.lua:32>
[C]: in function 'xpcall'
/home/pi/dtgbot/dtgbot.lua:31: in main chunk
[C]: in ?


Seems like it is still trying to use the local libraries, that do not work?

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 02 April 2022 12:10
by jvdz
So you did do the install for the 2 extra components as one of those should provide the new ssl libraries?