Sending multiple pictures with Telegram Action

Hi Everyone!

I have a rule which sends me a Telegram message when Alarm is detected in my home. Basically it uses the members.filter method to filter switches which are ON.
I have added some cameras to my setup and I want to include them in that rule.
What I want to achieve is to Telegram should send the same message as now (Message with zones in alarm) and after send each camera snapshot picture where zones are on (with caption of the name of the zone).

Cameras are simple Xiaomi cameras, I view it in openHAB by an rtsp URL.
I’m looking for the cleanest solution for this. Easiest would be to make a switch case or if statements and it will send each seperately. However is there a better solution for this?

Thanks!

If statements is the way since it could be any combination of zones turned on. A case/switch would work only if one zone needed to match.

Btw the latest build of the Ipcamera Binding can create a animated gif from your RTSP stream and that would be nicer than a static snapshot.

Another way could be to generate a single gif that contains footage from each of your cameras. It could rotate through all camera views, search the forum for pushover gif and there is a script you could use as a starter that takes inputs from snapshots

I have a similar setup at my home, I use MotionEye as my server to manage my cameras, so you will have to figure out how to get the image from the camera to a place you can send it via telegram. I use the motion detection in MotionEye that sends a get request to turn on a proxy motion switch in OpenHAB. If my “alarm” system is turned on, my rule will send me a telegram image of the motion when detected. I use groups for the cameras and motion sensors. I have a small script that handles copying the image from MotionEye to the “tmp/” directory in OpenHabThis is the code that I have been using for the past 6 months or so:

rule "interior motion detected"
when
	Member of gMotion changed from OFF to ON
then
    if(Fault.state==ON)	{
        var String motion = triggeringItem.name.toString.split("_").get(0)
        var CommandM = "/etc/openhab2/scripts/./"+motion+".sh"
		    executeCommandLine(CommandM)
            sendTelegram("bot1","ALERT - Motion in the "+motion+"!")
            logInfo("motion.rules","ALERT - Motion in the "+motion+"!")
			Status.postUpdate("ALERT _ Motion detected in the "+motion+"!")}
    else if(Fault.state==OFF){
        var String motionD = triggeringItem.name.toString.split("_").get(0)
	    Status.postUpdate("Motion has been detected in the " +motionD)
        logInfo("motion.rules", "Motion detected in the "+motionD)}
end

Here is the script:

#!/bin/bash
wget http://[IP ADDRESS]:[PORT]/picture/6/current -O /etc/openhab2/tmp/ypogeio.png
curl -s -X POST "https://api.telegram.org/[TELEGRAM TOKEN]/sendPhoto" -F chat_id=[CHAT ID NUMBER] -F photo="@/etc/openhab2/tmp/ypogeio.png"
rm -r ypogeio.png

The “ypogeio.png” is for the image from the camera in the basement, so you will have to make adjustments for your camera names, I have a separate script for each camera. I will have to check out the IP Camera Binding, I like the idea of getting an animated gif from my camera feeds. I hope this helps!

~John

I do not understand exactly what you already have and what you want.

I use some Xiaomi Dafang cameras with some hacked firmware. If you use the same, i would be interested how you view the rtsp stream in openHAB.

if (CAM01_MOTION.state==ON) {
   sendTelegramPhoto("bot1", "http://<cam01-ip>/cgi-bin/currentpic.cgi", "CAM01", "<user>", "<pw>")
}

This is hardcoded, but you may as always use the appropriate Design Pattern: Design Pattern: Associated Items and Design Pattern: Working with Groups in Rules.

I used the guide here. I don’t really show the video but a still image updated every second, like in the first post…

Thanks. So we use exactly the same cameras. Could you explain in detail, what you want to achieve in contrary to what you are already doing?

I understand you want to send a text message with telegram listing your zones and motion yes/no accompanied with the image of cameras with motion detected? Did i get this right?

If you want to send multiple images in one message you need to use the api function sendMediaGroup. I just googled about this, i do not know how to use this. I just read you can group multiple images, i do not know, if you can group a text with multiple images.

Sadly, the sendMediaGroup function is not supported by the openHAB library, so i can’t do a quick test.

You could use the Ipcamera Binding to watch your RTSP stream in HLS format which works great in iOS and can work in chrome if the right add on is installed to the browser. At the moment you will need to set it up as a ONVIF thing type to get your camera working even if it is not an onvif camera.

Waiting for it.
I wanted also to send a gif when motion detected…

Hi @matt1, love the GIF creation in the ipcamera binding - thank you.

I was trying to send the GIF using Telegram. This is supported in the telegram API.

https://api.telegram.org/bot[your_API_key]/sendAnimation?chat_id=[your_chatId]&animation=http://gif.server.ip/gif_animation.gif

It also works as a video type.

https://api.telegram.org/bot[your_API_key]/sendVideo?chat_id=[your_chatId]&video=http://gif.server.ip/gif_animation.gif

I have verified that both of these API calls work. But… the Telegram addon does not support either sendAnimation or sendVideo.

Thanks, its great to hear it is apricated and others use it as that is why I share to help others get a system working quickly.

The binding now supports MP4 recording much the same way as the GIF and the telegram API allows the sending of mp4. Need some people to raise an issue on GitHub asking for the features to be added if it makes sense to. People are already doing it by calling scripts and such so thanks for posting calls that you have tested to work, always good when people give back.

GIF = great for watching things move faster than realtime as you can specify the playback speed.
MP4 = great for high resolution, but you have to watch in realtime.

You mean raise an issue on the Telegram binding in GitHub?

Yes If it makes sense to have it added. I don’t use telegram so not sure if it makes sense to add it to the binding or if having the API call advertised in the forum is enough like you have already done.

I may have missed it, but I do not see a way to issue an API call straight through from the Telegram add-on (maybe that is a better solution than continuing to chase the Telegram API as it is changed). Do you have a way you send either the .gif or .mp4 files to an iOS device based upon rules?

@thisisIO , @bgilmer
I successfully added the ability to send GIF and MP4 to a custom build of the binding. A jar for openHAB 3 is found here if you would like to test.

2 Likes