Page 1 of 1

SOLVED: Telegram chatid and api key available to scripts ?

Posted: Sunday 14 March 2021 16:37
by psubiaco
Hi,
I'd find very useful for Domoticz to export a global variable within settings to scripts.
I use several LUA scripts, and it will be great if scripts can get a variable table within the Telegram API key and chat_id defines in Setup -> Settings -> Notifications, so it's not needed to duplicate those variables inside external configuration files.

Re: Telegram chatid and api key available to scripts ?

Posted: Sunday 14 March 2021 17:21
by waltervl
The settings are available with an API call for Lua with curl. See also viewtopic.php?t=35048

Re: Telegram chatid and api key available to scripts ?

Posted: Sunday 14 March 2021 17:31
by waaren
psubiaco wrote: Sunday 14 March 2021 16:37 Hi,
I'd find very useful for Domoticz to export a global variable within settings to scripts.
I use several LUA scripts, and it will be great if scripts can get a variable table within the Telegram API key and chat_id defines in Setup -> Settings -> Notifications, so it's not needed to duplicate those variables inside external configuration files.
With sufficient authorization it's quite easy to get these values from domoticz via the API.

See below dzVents (100% Lua) example

Code: Select all

local scriptVar = 'settings'
return
{
    on =
    {
        timer =
        {
            'every minute'
        },
        httpResponses =
        {
            scriptVar,
        }
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)

        if item.isTimer then
            dz.openURL({
                url =  dz.settings['Domoticz url'] .. '/json.htm?type=settings',
                callback = scriptVar,
            })
            return
        end

        if item.isHTTPResponse and item.json then
            -- dz.utils.dumpTable(item.json) -- Dumps all values to log
            dz.log('TelegramAPI: '.. item.json.TelegramAPI, dz.LOG_DEBUG )
            dz.log('TelegramCHAT ID: ' ..item.json.TelegramChat, dz.LOG_DEBUG )

        else
            dz.log('There was a problem handling the request', dz.LOG_ERROR)
            dz.log(item, dz.LOG_DEBUG)

        end

    end
}



Re: Telegram chatid and api key available to scripts ?

Posted: Sunday 14 March 2021 18:11
by psubiaco
Hi waaren,
thanks a lot for your reply. I didn't know that settings were available in json!
Having a table/dict variable with all settings is easier to access, but json is a good workaround as well.
Paolo

Re: Telegram chatid and api key available to scripts ?

Posted: Sunday 14 March 2021 19:56
by waaren
psubiaco wrote: Sunday 14 March 2021 18:11 Hi waaren,
thanks a lot for your reply. I didn't know that settings were available in json!
Having a table/dict variable with all settings is easier to access, but json is a good workaround as well.
Paolo
Have a look at this wiki page to see what else is available via the API in json returns