SOLVED On/Off Switch->Telegram Cam snapshot + text

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

SOLVED On/Off Switch->Telegram Cam snapshot + text

Post by McJohn »

Could somebody please help me with this script.
What I want is when:
Switch is On -> Telegram Cam snapshot + Text: Security ON
Switch is Off -> Telegram Cam snapshot + Text: Security OFF

This script below is working well. But it works only when the switch "AlarmLed" goes on.
And there is no text above or below the picture.

So, what should be added to the script?

Thanks in advance for all the support.

John


Code: Select all

return {
    on = { 
       devices = {'AlarmLed'},
    },

    execute = function(domoticz, device)
        if(device.state == 'On') then
            local teleTok   = '111111111111111111111BBBBBBBBBBBBBBBBB'
            local chatId    = '-1234567890'
            local snapFile  = '/home/pi/domoticz/scripts/camera_'
            local domoReq   = 'http://192.168.178.231:8080/raspberry.cgi'
            local camName   = 'Frontdoor'
            os.execute('wget -O "'..snapFile..camName..'.jpg" "'..domoReq..'"')
            os.execute('curl -s -X POST "https://api.telegram.org/bot'..teleTok..'/sendPhoto?chat_id='..chatId..'" -F photo="@'..snapFile..camName..'.jpg"')
os.execute("rm " ..snapFile..camName..'.jpg')
        end
    end
}
Last edited by McJohn on Monday 24 May 2021 16:11, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: On/Off Switch->Telegram Cam snapshot + text

Post by waaren »

McJohn wrote: Monday 24 May 2021 13:02 This script below is working well. But it works only when the switch "AlarmLed" goes on.
And there is no text above or below the picture.
No idea how to add text to the snapshot but below version should send something on state == 'On' and on state == 'Off'

Code: Select all

return {
    on = { 
       devices = {'AlarmLed'},
    },

    execute = function(domoticz, device)
		local teleTok   = '111111111111111111111BBBBBBBBBBBBBBBBB'
		local chatId    = '-1234567890'
		local snapFile  = '/home/pi/domoticz/scripts/camera_'
		local domoReq   = 'http://192.168.178.231:8080/raspberry.cgi'
		local camName   = 'Frontdoor'

		os.execute('wget -O "'..snapFile..camName..'.jpg" "'..domoReq..'"')

        if device.state == 'On' then
            os.execute('curl -s -X POST "https://api.telegram.org/bot'..teleTok..'/sendPhoto?chat_id='..chatId..'" -F photo="@'..snapFile..camName..'.jpg"')
        elseif device.state == 'Off' then
		    os.execute('curl -s -X POST "https://api.telegram.org/bot'..teleTok..'/sendPhoto?chat_id='..chatId..'" -F photo="@'..snapFile..camName..'.jpg"')
        end
		
		os.execute("rm " ..snapFile..camName..'.jpg')

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: On/Off Switch->Telegram Cam snapshot + text

Post by McJohn »

Thank you sooo much for the very quick reply, On/Off with sending the Telegram snapshot works perfect!

I have an URL for an HTTP command to add the text but I don't know where it has to insert into the script (and which command it has to be)
(This URL works in a browser; it send the text to a Telegram device)

Code: Select all

https://api.telegram.org/bot11111111111111BBBBBBBBB/sendMessage?chat_id=1234567890&text=Security ON
and

Code: Select all

https://api.telegram.org/bot11111111111111BBBBBBBBB/sendMessage?chat_id=1234567890&text=Security OFF
Do you have an idea where I have to place this text and what command I have to use?

Thanks in advance!
McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: On/Off Switch->Telegram Cam snapshot + text

Post by McJohn »

Got the text addition working!
The method with the HTTP URL is I think not the best solution (in comparison with with the os.execute('curl command) but it's working now.
Edit the script with:

Code: Select all

local url1		= 'https://api.telegram.org/bot111111BBBB/sendMessage?chat_id=1234567890&text=Security ON'
local url2		= 'https://api.telegram.org/bot111111BBBB/sendMessage?chat_id=1234567890&text=Security OFF'
and further on with:

Code: Select all

if device.state == 'On' then
            domoticz.openURL(url1)

elseif device.state == 'Off' then
            domoticz.openURL(url2)
Thanks for listening and your terrific support.
McJohn
Posts: 91
Joined: Wednesday 10 October 2018 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: On/Off Switch->Telegram Cam snapshot + text

Post by McJohn »

PS: instead of the above code for text addition, this one is also working well into the script:

Code: Select all

elseif device.state == 'Off' then
os.execute('curl -s -X POST "https://api.telegram.org/bot111111111BBBBBBB/sendMessage?chat_id=123456789&text=Security OFF"')
(and also for the ON state).
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest