Get status with Telegram Bot

Hi!

I finished a home security alarm a couple of weeks ago but I think there is still something missing.

I want the system to send me some kind of status report when I use a command in Telegram Messenger.

The status report should say something like:
The system has been active for X hours X minutes, last detection was on X date and the total amount of detections.

I have no idea how i can get started with this,
Anyone a good idea?

I’d start by looking at flows.nodered.org which contains many telegram flows you can import to see how they work

Is there a way I can view these flows on my Windows pc without having Node-Red installed or is this impossible?

If your alarm system has an api available and/or can be talked to via http(s) then you can use node-red to accomplish this quite easily*
*(depending on your technical knowledge)

You can't really do that. If they are formatted, you do get a feel for what's going on if you read a few.

But best to run up Node-RED on your Windows PC. That's what I do for all my development as it is a lot easier than messing with remote servers.

I use Telegram bots extensively. I get Node-RED to send me all sorts of messages automatically and have a couple of groups so that I can have one that is very "chatty" for me to use to monitor what is going on and then another that isn't chatty, just the important things, that the family can use and that has notifications turned on for my phone. I also have commands set up so that I can query things and so that I can control things like lights and temperature.

1 Like

Depends what you mean.

If Node-RED is inactive because something is wrong - that might be difficult since you are relying on Node-RED to activate the bot.

If you mean that the bot tells you how loaded (how much CPU/RAM/etc is in use) your system is - then absolutely, that is pretty straight-forwards once you've set up a bot since all you need to do is send it the data. I've even set up flows that let me use MQTT to control the input/output to the bot. So I don't need to keep messing with the bot.

1 Like

I see, I will just leave it like this then scince the bot won't be able to respond if the system is inactive.

Thanks for your help :slight_smile:

Well no system can respond if it is dead! You would need a parallel system in order to do that. Indeed, that is exactly what I do. I have 2 Pi's, each with their own MQTT brokers. They each send heartbeats to each other and both are on a UPS to keep them running - at least for a while - even if the power goes out (obviously the router and switch also have to be on the UPS). That way, I am notified if Node-RED stops working on one of them. I'm also notified if one of them is no longer reachable over the network. I could set it up so that I get informed of other services going down but, to be honest, with a decent SD-Card, power supply and UPS, the Pi's keep running just fine for years on end so not really worth much effort.

So unless I use another Pi I wont be able to send information if the power falls out?

With node-red you can ping your alarm system, if no response > telegram message

You can also build a command interface (like /status) that returns a status like armed/disarmed etc: as long as you can interface with your alarm system.

1 Like

I was thinking, maybe I could use a powerbank as ups? Would this work?

The best solution would be too use another machine that’s off-site. That machine could be in the cloud, etc. and have a heart beat between them. This way you’ll be notified if the system is no longer able to communicate for one reason or another. If you planning another alarm system at another place you could just use that.

Or some other device, yes. If the primary device isn't running, there is nothing to send from any service. You need another service on a different device to be monitoring. Not hard to set up.

If you build a bot with a request status command, when you request the status and you don't get any response, you will know that there is a problem but not where or why unless there is another service somewhere that your primary sends updates to.

Maybe. Unfortunately, most powerbanks can't deliver power while they themselves are receiving power (e.g. plugged into the mains) so that wont work. Also many powerbanks struggle to return to delivering power once they have gone below a certain % charge. Since powerbanks have no data interface, the Pi can't know when power is running out and cannot shut down gracefully.

Really a UPS, while more expensive, is by far the best option. Don't forget that it isn't just the Pi that you need to power if you need external access, it is also your router at the very least. In addition, a UPS should have a data interface that your Pi can use to shut itself down once the batteries are reaching their limit.

"best" may be overstating it a little. It is arguably the best from a resilience point of view but certainly not the best from a security perspective. But yes, that is an option for the secondary. That server needs to also run Node-RED of course in order to be able to make use of that to run a bot.

You also will want to ensure that connections between your Pi and the external server are well secured.

Commercial alarm systems are expensive for a reason. They (should!) take much of this into account for you.

It's best because if your Internet went down you wouldn't be alerted, and that's kinda one of the main points for a alarm system.

As alternative you could buy a used notebook (i got one for 50€), where you would have:

  • a lot more bogomips
  • a screen + keyboard
  • a ups (battery only lasts 20 minutes, but thats enough for me)
  • a detector for power loss (you can react, if the notebook switches to battery - some pi ups dont provide that)
  • maybe also an internal sim slot, which allows to send an alarm sms or even backup internet
  • sata drives and all the connectors it has (gigabit eth., esata,...)

It,s a lot cheaper and probably more reliable than a pi.
The biggest drawback is a higher power consumption (20W idle in my case).

2 Likes

I use a cheap Android phone and pre-paid service ~$10/month, to provide emergency notifications via SMS.

I use Termux and Termux-api on the phone to install node-red on the phone

All the various bits and pieces communicate via MQTT.

2 Likes

Just in case anyone hasn't seen them, there are now "mini" ups boards that can be fitted to RPi, Arduino and many other devices. They are based on the 18650 battery so that may be problematic for some I guess. But they do work. I have powered a Pi Zero + camera for a few hours off a single 18650 in this configuration.

2 Likes

Thanks for that. Also worth checking out Pete Scargill's blog as he has tried out a number of solutions and has discussed the issues most of them have.

Yes, Pete has done a fair bit of research in this area, although I think things have moved on a bit since he last looked at these devices. Even since I bought some a couple of months ago there appears to be a design incorporating 2 x 18650s now. I assume a balancing circuit is included. The beauty of a single battery was not needing to balance. Anyhow, this has become OT. Hope the NR gods aren't watching. :worried: