Boca
Posts: 14
Joined: Sat Feb 24, 2018 1:25 pm

Pi as heating/elec failure alarm

Sat Mar 03, 2018 5:02 pm

Hi,
as background, I am a complete newbie to Pi and its capabilities. In the past, I have programmed macros/PLC and currently run a Windoze free household as a Linux Mint advocate.

Assuming that I have not burnt bridges with my new community....... :?:

I am looking to set up an alarm so that, if the heating fails while I am on a winter holiday, I can get an alert to my mobile:-

Focusing on Pi options:-
  • Is the on-board ambient temp sensor adequate ?
    In the case of a power-failure, any wi-fi/broadband options would also die, is there an option to directly SMS the alert?
    How easy is it to have a battery backup so that if the power, and hence heating, fails, Pi could still alert me?
Ideally, I would like to be able to order a "packaged solution" which had the above hardware capability/options and "only" required programming.
TIA, Tony

PS future "projects" could be to use Pi as a VPN (?)

wh7qq
Posts: 1314
Joined: Thu Oct 09, 2014 2:50 am

Re: Pi as heating/elec failure alarm

Sun Mar 04, 2018 2:29 am

The built in temp sensor (vcgencmd measure_temp) does not report ambient temperature but the actual chip temperature of the cpu. Depending on cpu activity level and actual ambient temps especially if a case is used, it will not reflect environmental temps well. I would suggest using a ds18b20, especially the version that is packaged in a metal tube with several feet of lead wire attached. It can be positioned to be removed from any heat generated by the RPi.

Presumably, in the event of a power failure, even if you have back-up power for the RPi, your LAN will go down and hence your internet connection. If your internet connection is immune (for example, a DSL line) and you are able to back up the entire chain...modem, router and RPi, you could get out a message, email or whatever.

You would need some non-connected way to sense the power failure if the network chain is kept alive...if the back-up power provides some kind of a AC failure signal, that would be easy but something as simple as a led that could be "seen" by the RPi and a light dependent resistor would work.

I don't think you (or I) burn any bridges by using the RPi alongside Mint. Except for Mintboxes that are 10X more costlly than the RPi, running an x86 is much more power thirsty. Still, for some things, only a full up x86 linux box will do. :D But my Mint desktops don't have GPIO pins or the kind of real world capability of the RPi but when you need a big memory, the 4G of my desktops is going to win every time.

User avatar
rpdom
Posts: 14985
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Pi as heating/elec failure alarm

Sun Mar 04, 2018 7:15 am

It's not something that I've looked at, but you can get GSM modules that use a mobile SIM card and connect to the Pi. I believe they are usually used for internet connections, but I expect it is possible to send an SMS using one. As for the temperature sensing, just use a DS18B20 sensor with a 4.7K Ohm resistor. I don't think there are any "out of the box" solutions that you can buy, but the coding isn't too hard.

Boca
Posts: 14
Joined: Sat Feb 24, 2018 1:25 pm

Re: Pi as heating/elec failure alarm

Sun Mar 04, 2018 10:30 am

wh7qq wrote:
Sun Mar 04, 2018 2:29 am


Presumably, in the event of a power failure, even if you have back-up power for the RPi, your LAN will go down and hence your internet connection. If your internet connection is immune (for example, a DSL line) and you are able to back up the entire chain...modem, router and RPi, you could get out a message, email or whatever.

You would need some non-connected way to sense the power failure if the network chain is kept alive...if the back-up power provides some kind of a AC failure signal, that would be easy but something as simple as a led that could be "seen" by the RPi and a light dependent resistor would work.

Thanks for the speedy reply..
to clarify my comments about power failure.... my primary concern is that this would disable the heating system. Any system to send an alert on low temperature has got to be able to work without mains power ( and hence no wi-fi, no broadband)... hence my thoughts of a Pi with a battery backup and an SMS card.

Thanks, Tony

PingoBags
Posts: 47
Joined: Mon Nov 06, 2017 10:53 pm
Location: NS, Canada

Re: Pi as heating/elec failure alarm

Sun Mar 04, 2018 1:06 pm

Another option..
If you had some way to power your router, my router has a 4hr built in battery backup so my internet keeps working on power failure.

All I did to detect power failure with my pi, I took a 5v 550mah power supply. Made a voltage divider with resistors to drop the voltage to 3v.
Limited the current to under 2mah with a couple more resistors.
Connected it to a pin set as input. When the power is out, the pin reads 0, when on, it reads 1.
Since you use electric heating, you'l only need to detect power failure, not ambient temp.

You can also send an sms to your phone through email if you know your carrier email.
My carrier is telus so to send an sms to my phone, all I need to do is my_phone_number@msg.telus.com.
You can't reply to them but it's perfect for notifications when away.

Boca
Posts: 14
Joined: Sat Feb 24, 2018 1:25 pm

Re: Pi as heating/elec failure alarm

Sun Mar 04, 2018 1:16 pm

PingoBags wrote:
Sun Mar 04, 2018 1:06 pm

Since you use electric heating, you'l only need to detect power failure, not ambient temp.
Thank you for your suggestions.

Unfortunately, I am using gas heating which relies on an electric circulating pump.
I would still need temp. detection to detect a failure of the heating system which wasn't related to the incoming electrical supply ( eg faulty thermostat)

Thanks, Tony

RDS
Posts: 712
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Pi as heating/elec failure alarm

Sun Mar 04, 2018 1:36 pm

I don't have exact instructions on how to do it but:
I would use the DS18B20 Temperature sensor, as has already been mentioned.
Then for the SMS side, I would be using an old mobile phone with a Pay As You Go simcard and connected (somehow) to the USB on the Pi.
Keep the mobile connected to the mains, so that it is always charged up.

Alternately and preferably, again using the DS18B20 to log the temperature, get the Pi to send you an email say once every 2 hours with the current temperature and you will see it drop when power goes off. You could also have a Pi Camera pointed at your boiler or something else that indicates the power is still on and again get it to send emails regularly. If the emails stop, maybe you have a problem.

Incidentally, what will you do if a Power cut does occur?

Boca
Posts: 14
Joined: Sat Feb 24, 2018 1:25 pm

Re: Pi as heating/elec failure alarm

Sun Mar 04, 2018 2:03 pm

RDS wrote:
Sun Mar 04, 2018 1:36 pm

I would use the DS18B20 Temperature sensor, as has already been mentioned.
Then for the SMS side, I would be using an old mobile phone with a Pay As You Go simcard and connected (somehow) to the USB on the Pi.
Keep the mobile connected to the mains, so that it is always charged up.

Incidentally, what will you do if a Power cut does occur?
Thanks for your thoughts..
the option of using an old phone is quite appealing especially if it's battery could support the Pi during a power outage. The devil is in the detail of " mobile .. ( somehow) to the USB".

If I do get alerted to a power failure or heating fault, I can then ask neighbours to pop in and check. ( I know they could do this as a routine but if I can find a way to avoid this, I would like to)

Tony

RDS
Posts: 712
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Pi as heating/elec failure alarm

Sun Mar 04, 2018 2:20 pm

@Boca
Yes, I agree about the detail.

The other thing I would do (and I already do this with a Pi I have running 24/7) is to use Crontab to run your program when the Pi boots up.
That way, when the power is restored your Pi will automatically start up and run your program. I assume that your router and therefore WiFi will start up again when the power is restored, so your emails would restart.

Thinking more about this, I would go for the alternate solution I proposed.

Boca
Posts: 14
Joined: Sat Feb 24, 2018 1:25 pm

Re: Pi as heating/elec failure alarm

Sun Mar 04, 2018 2:43 pm

RDS wrote:
Sun Mar 04, 2018 2:20 pm
@Boca
Yes, I agree about the detail.

The other thing I would do (and I already do this with a Pi I have running 24/7) is to use Crontab to run your program when the Pi boots up.
That way, when the power is restored your Pi will automatically start up and run your program. I assume that your router and therefore WiFi will start up again when the power is restored, so your emails would restart.

Thinking more about this, I would go for the alternate solution I proposed.
This is beginning to make a nice simple solution without the need for sms or ups.

Pi with a DS18B20 Temperature sensor,
crontab to start programme on reboot which will issue email with ambient temp every hour
if power fails, absence of email indicates a possible issue.

Thanks, Tony

Boca
Posts: 14
Joined: Sat Feb 24, 2018 1:25 pm

Re: Pi as heating/elec failure alarm

Sun Mar 04, 2018 10:33 pm

Hi,

I have started my Pi journey and have now ordered Pi + temp sensor.

Thank for all the suggestions to date.

I may ( will?) be returning to the forum as I embark on this first project.

Thanks, Tony

RDS
Posts: 712
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Pi as heating/elec failure alarm

Sun Mar 04, 2018 11:07 pm

Good luck Tony.
Probably best to update this thread to let us know how you get on.
I regularly receive emails from one of my Pi's (a Pi Zero W) with data.
I know it can also send pictures but I have just never needed that feature myself.

I use smtplib for emails.
Look for smtplib using your favourite search engine to find details.

jbudd
Posts: 946
Joined: Mon Dec 16, 2013 10:23 am

Re: Pi as heating/elec failure alarm

Mon Mar 05, 2018 1:36 am

An old smartphone seems like a better option than a GSM add-on board for the PI.

With an old Android you could:

Use an app such as Power Outage SMS to send a notification when mains power goes down or comes back on.
Run an MQTT client to receive temperature warnings from the Pi and send them as SMS or email.
(Not sure exactly how, but maybe you could do this with IFTTT or Termux and Node-Red on the phone.)
Provide a wifi hotspot for the Pi to connect to.
Notify you if the Pi is not running / connected.


You should still look for a UPS of some sort to shut the Pi down safely when the power goes down.
The phone of course is it's own UPS.

Boca
Posts: 14
Joined: Sat Feb 24, 2018 1:25 pm

Re: Pi as heating failure alarm

Thu Mar 08, 2018 5:14 pm

Hi ,

a quick update .... then, inevitably, a question..

Pi set up and can now SSH into it.
UFW set up
Email comms set up to issue an hourly "heartbeat" from Pi's dedicated gmail account.
waiting for delivery of probe.

Q:- In terms of connecting the probe, is the consensus to solder directly onto the GP10 pins?

Tony

scotty101
Posts: 3671
Joined: Fri Jun 08, 2012 6:03 pm

Re: Pi as heating failure alarm

Thu Mar 08, 2018 5:38 pm

Boca wrote:
Thu Mar 08, 2018 5:14 pm
Q:- In terms of connecting the probe, is the consensus to solder directly onto the GP10 pins?
You mean GPIO not GP10.
Generally soldering directly to the pins is not recommended. You could solder directly to something like a PermaProto or use some [urlhttps://www.adafruit.com/product/1950]jumper wires[/url]. With the jumper wires, I used to just cut off one end and solder what i wanted to the other. The end with the connector plugs in to the Pi.
(I now have a crimp tool for making my own cables)
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Boca
Posts: 14
Joined: Sat Feb 24, 2018 1:25 pm

Re: Pi as heating/elec failure alarm

Thu Mar 08, 2018 6:17 pm

Thanks.

I have checked and a ribbon connector from an old desktop pc works a treat. It does not,however, have any mistake-proofing orientation pegs so I will have to mark it and be careful on re-connecting. Also, the wire gauge may make soldering more tricky.

Tony

RDS
Posts: 712
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Pi as heating/elec failure alarm

Thu Mar 08, 2018 7:11 pm

It sounds like you are making very good progress Tony.

As scotty has already stated, I too would not recommend soldering directly to the GPIO pins.

I purchased some header sockets in 2 different lengths (4 pins x 2 pins and 8 pins x 2 pins) that I have found ideal.
I tend to choose GPIO pins that are close to each other so that I can use the 4 x 2's wherever possible.
It also means that you can just unplug it if you want to run a different program or just experiment with something else.

Boca
Posts: 14
Joined: Sat Feb 24, 2018 1:25 pm

Re: Pi as heating/elec failure alarm

Fri Mar 16, 2018 7:36 pm

Hi,

I have now received my temperature probe ( it had been lost in the post due to snow!) So I hope to have some time to work on this over the weekend.

I have been doing as much of the software as I can while waiting for the probe and have been following this excellent link
( https://www.raspberrypi-spy.co.uk/2013/ ... er-sensor/). This will,hopefully, get me the temperature via the python script and “assign” it to the gettemp(id) variable

I have a crontab setting which emails me hourly with
echo " " | mail -s Room temperature is mymail@Gmail.com.

How do I add the gettemp(id) value into the email subject ?

Thanks, Tony

RDS
Posts: 712
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Pi as heating/elec failure alarm

Fri Mar 16, 2018 11:05 pm

Are you using smtplib for your emails?

Boca
Posts: 14
Joined: Sat Feb 24, 2018 1:25 pm

Re: Pi as heating/elec failure alarm

Sat Mar 17, 2018 8:55 am

Hi,

sorry I should have mentioned that.... I am using ssmtp.

thanks, Tony

pcmanbob
Posts: 6630
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pi as heating/elec failure alarm

Sat Mar 17, 2018 10:27 am

I use ssmtp and mail utils on several of my Pi's to send IP on boot and send data files daily.

I have not yet found a way to get variables in to the email subject , because you can't it seems pipe a file in for the email subject it has to be typed directly on the send line.

you can pipe a file in for the email body content like this.

Code: Select all

mail -s "Zero Pi IP"  < /home/pi/ipmessage.txt $email_address
the pipe file can be created in any way you want so for example this on is created by these line in the script.

Code: Select all

echo "Zero Pi IP Address " > ipmessage.txt
hostname -I >> ipmessage.txt
but I have another pi that sends out data every day and the text file that is piped in is created by a python program and is just saved to the /home/pi directory and piped in the same way.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

RDS
Posts: 712
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Pi as heating/elec failure alarm

Sat Mar 17, 2018 10:45 am

I do something similar using smtplib.
In my case I am sending an email with the results of variables, both in the subject and the body of the email.
I convert the variables to strings using str(my_variable) and add it to the code for sending the email, either as the subject or in the body of the message.

jbudd
Posts: 946
Joined: Mon Dec 16, 2013 10:23 am

Re: Pi as heating/elec failure alarm

Sat Mar 17, 2018 12:23 pm

An example of using environment variables in the message subject and body in a Bash script:

Code: Select all

#! /bin/bash

RECIPIENT=myname@gmail.com

# set a subject - eg my external ip address
SUBJECT="My IP Address is "$(wget -qO- http://bot.whatismyipaddress.com/ )  

#BODY is a multi line environment variable (enclosed in quotes " " )
BODY="When shall we three meet again?                         
In thunder, lightning or in rain?"

# send email
# Because $BODY & $SUBJECT may contain spaces, new lines,... 
#  put quotes round the variable names
echo "$BODY" | mail -s "$SUBJECT" "$RECIPIENT"           

Boca
Posts: 14
Joined: Sat Feb 24, 2018 1:25 pm

Re: Pi as heating/elec failure alarm

Thu Mar 22, 2018 3:43 pm

quick update.. the probe is now connected and pi is emailing me each hour with the room temperature... so it's achieving the basic functionality I wanted. :D I do, however, have to open each email and read the temperature to make sure it's ok. :roll:

(echo " " | mail -s Pi_hourly_heartbeat_with_room_temperature_in_email_body < /sys/bus/w1/devices/28-051702709dff/w1_slave ****@Gmail.com)

thank you to all for your assistance.

Next steps:- learn how to programme so that if the room temperature drops.. it sends an email titled "URGENT !!"

Thanks, Tony

RDS
Posts: 712
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Pi as heating/elec failure alarm

Thu Mar 22, 2018 11:19 pm

Can you post the portion of your program that sends the email (without your personal details of course) and I will see how it compares with mine because I send variable data within the title of the message, so I know it can be done, which would save you having to open your emails.

The 'failure' email is easy to set up. You just need an if statement, where the consequences of it are to send you an email.

Return to “Beginners”