SOLVED: Telegram chatid and api key available to scripts ? Topic is solved

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
User avatar
psubiaco
Posts: 233
Joined: Monday 20 August 2018 9:38
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Italy
Contact:

SOLVED: Telegram chatid and api key available to scripts ?

Post 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.
Last edited by psubiaco on Monday 15 March 2021 19:04, edited 3 times in total.
Paolo
--
I use DomBus modules to charge EV car, get a full alarm system, control heat pump, fire alarm detection, lights and much more. Video
Facebook page - Youtube channel
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Telegram chatid and api key available to scripts ?

Post by waltervl »

The settings are available with an API call for Lua with curl. See also viewtopic.php?t=35048
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Telegram chatid and api key available to scripts ?

Post 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
}


Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
psubiaco
Posts: 233
Joined: Monday 20 August 2018 9:38
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Italy
Contact:

Re: Telegram chatid and api key available to scripts ?

Post 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
Paolo
--
I use DomBus modules to charge EV car, get a full alarm system, control heat pump, fire alarm detection, lights and much more. Video
Facebook page - Youtube channel
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Telegram chatid and api key available to scripts ?

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest