dtgbot - Domoticz TeleGram BOT

Client tools or tools that can connect with Domoticz. Tools for Windows, iOS, Android, Linux etc.

Moderator: leecollings

mojso
Posts: 86
Joined: Friday 08 November 2019 23:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
mojso
Posts: 86
Joined: Friday 08 November 2019 23:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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
Attachments
20220114_002412.jpg
20220114_002412.jpg (83.12 KiB) Viewed 1684 times
phenix56
Posts: 31
Joined: Sunday 10 October 2021 18:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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...
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
phenix56
Posts: 31
Joined: Sunday 10 October 2021 18:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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?
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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? ;)
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
phenix56
Posts: 31
Joined: Sunday 10 October 2021 18:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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?
phenix56
Posts: 31
Joined: Sunday 10 October 2021 18:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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 ?
Last edited by phenix56 on Saturday 02 April 2022 10:29, edited 1 time in total.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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,
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
phenix56
Posts: 31
Joined: Sunday 10 October 2021 18:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by phenix56 »

Uhm, what do you mean exactly? Remove the folders created for lua 5.2?
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
phenix56
Posts: 31
Joined: Sunday 10 October 2021 18:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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?
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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";
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
phenix56
Posts: 31
Joined: Sunday 10 October 2021 18:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by phenix56 »

I tried both 'git clone', followed by the link and the instructions, both fail. How should I install the new version?
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by jvdz »

Probably something like this:

Code: Select all

git clone https://github.com/steps39/dtgbot -b Statility-and-new-install
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
phenix56
Posts: 31
Joined: Sunday 10 October 2021 18:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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 ?
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by jvdz »

There should be more info in the dtgbot.log about the issue it encounters.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
phenix56
Posts: 31
Joined: Sunday 10 October 2021 18:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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?
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by jvdz »

So you did do the install for the 2 extra components as one of those should provide the new ssl libraries?
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests