Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 12 January 2022 13:11
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
Open source Home Automation System
https://forum.domoticz.com/
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.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 :
command devices name will still only give the matching names in a list.
- make a backup of the current devices.lua
- replace the content with the below source.
- Restart DTGBOT
- Try command devices name st
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 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.
Did you look at the linked page?
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:/usr/bin/lua5.2: /home/pi/dtgbot/dtgbot.lua:132: module 'ssl.https' not found:
Code: Select all
https = require "ssl.https";
Code: Select all
git clone https://github.com/steps39/dtgbot -b Statility-and-new-install