Bryan Mayland
TVWBB Hall of Fame
The information in this post is outdated please refer to the Alarm Script Recipes wiki page for up-to-date information.
As of last weekend, LinkMeter has the ability to fire off user scripts when an alarm goes off. This is in addition to beeping the piezo buzzer. While I get the documentation together, I figured I'd start with some script recipes and information on how it works. Note this requires some degree of linux shell scripting expertise, but using some of these recipes might make things a little easier to understand.
First of all, alarm scripts are located in /usr/share/linkmeter/. Do not edit the script named "alarm", as this file will be replaced every time linkmeter is upgraded and you will lose all changes. Instead, create new files for your scripts. The system looks for a file named alarm-{probeidx}{alarmtype}. For example if the Pit probe high alarm is going off, it will look for alarm-0H. If this file is not found, then a generic alarm-all is called. These files can be a shell scripts, lua scripts, or a regular ARM ELF binaries. These recipes can be used for either an alarm-specific or alarm-all file. The files must be executable, i.e. `chmod +x` or they will not be run.
There are many variables available to use in your scripts. From a command prompt execute `lmclient LMCF` for a list. In addition, the alarm system adds al_probe, al_type, al_thresh variables.
NOTE: msmtp is only available on RasberryPi firmware due to size limitations.
Common Code
Most recipes are going to start with the same code. #1 turn the alarm off. #2 get the name and current value of the probe that's causing the alarm. All the recipes below start with this common code.
Sending an Email
This requires that /etc/msmtprc be configured with the proper email server information. Note that many ISPs will block regular email traffic (on port 25) so you'll probably need to use SMTP over SSL on port 465.
SMS Message
SMS relies on going through your cell provider's email to SMS gateway so, again, the /etc/msmtprc must be configured for proper email delivery.
HeaterMeter Control - Shutdown
Often you want to turn off the Pit when your food is done. This is easily done using lmclient to send a command to HeaterMeter to change the setpoint.
HeaterMeter Control - Ramp Down
You can do more complicated setpoint control with a ramp down script.
HeaterMeter Control - Super Ramp Down
10 degrees too much? That's ok you can ramp down one degree for every degree the meat climbs if you like
Time Delays
Often you may not want be notified when the alarm happens but some time after it happens. Cron can be used. Note cron only has per-minute resolution so don't try to make things happen every N seconds.
As of last weekend, LinkMeter has the ability to fire off user scripts when an alarm goes off. This is in addition to beeping the piezo buzzer. While I get the documentation together, I figured I'd start with some script recipes and information on how it works. Note this requires some degree of linux shell scripting expertise, but using some of these recipes might make things a little easier to understand.
First of all, alarm scripts are located in /usr/share/linkmeter/. Do not edit the script named "alarm", as this file will be replaced every time linkmeter is upgraded and you will lose all changes. Instead, create new files for your scripts. The system looks for a file named alarm-{probeidx}{alarmtype}. For example if the Pit probe high alarm is going off, it will look for alarm-0H. If this file is not found, then a generic alarm-all is called. These files can be a shell scripts, lua scripts, or a regular ARM ELF binaries. These recipes can be used for either an alarm-specific or alarm-all file. The files must be executable, i.e. `chmod +x` or they will not be run.
There are many variables available to use in your scripts. From a command prompt execute `lmclient LMCF` for a list. In addition, the alarm system adds al_probe, al_type, al_thresh variables.
NOTE: msmtp is only available on RasberryPi firmware due to size limitations.
Common Code
Most recipes are going to start with the same code. #1 turn the alarm off. #2 get the name and current value of the probe that's causing the alarm. All the recipes below start with this common code.
Code:
#!/bin/sh
# Silence all alarms
lmclient LMST,al,0,0,0,0,0,0,0,0
# Get current ringing name and temperature
PN=`eval echo \\$pn${al_probe}`
PCUR=`eval echo \\$pcurr${al_probe}`
Sending an Email
This requires that /etc/msmtprc be configured with the proper email server information. Note that many ISPs will block regular email traffic (on port 25) so you'll probably need to use SMTP over SSL on port 465.
Code:
sendmail bmayland@myemail.net << EOF
From: Bryan Mayland <bmayland@myemail.net>
To: Bryan Mayland <bmayland@myemail.net>
Subject: [HM] $PN Alert
Alarm $al_type outside threshold $al_thresh, currently $PCUR.
$pn0: $pcurr0
$pn1: $pcurr1
$pn2: $pcurr2
$pn3: $pcurr3
--
http://your.heatermeter.address/luci/lm/
EOF
SMS Message
SMS relies on going through your cell provider's email to SMS gateway so, again, the /etc/msmtprc must be configured for proper email delivery.
Code:
echo "$PN Alert -- $PCUR \($al_type\)" | sendmail 2125551212@messaging.sprintpcs.com
HeaterMeter Control - Shutdown
Often you want to turn off the Pit when your food is done. This is easily done using lmclient to send a command to HeaterMeter to change the setpoint.
Code:
# Lower the setpoint to 100
lmclient LMST,sp,100
HeaterMeter Control - Ramp Down
You can do more complicated setpoint control with a ramp down script.
Code:
case $al_thresh in
180) NEWSP=215; NEWAL=190; ;;
190) NEWSP=205; NEWAL=200; ;;
200) NEWSP=100; NEWAL=0; ;;
esac
lmclient LMST,sp,$NEWSP
# Assumes food probe 1 is the alarm generator
lmclient LMST,al,,,$NEWAL
HeaterMeter Control - Super Ramp Down
10 degrees too much? That's ok you can ramp down one degree for every degree the meat climbs if you like
Code:
if [ "$al_thresh" -gt 199 ] ; then
# done
lmclient LMST,sp,100
exit
fi
NEWSP=$((sp-1)
NEWAL=$((al_thresh+1))
lmclient LMST,sp,$NEWSP
# Assumes food probe 1 is the alarm generator
lmclient LMST,al,,,$NEWAL
Time Delays
Often you may not want be notified when the alarm happens but some time after it happens. Cron can be used. Note cron only has per-minute resolution so don't try to make things happen every N seconds.
Code:
# If no parameter, this is a regular alarm
if [ -z "$1" ] ; then
NOW=`date +%s`
# Set target for 1 hour from now 3600=seconds
WHEN=$((NOW+3600))
TARGET=`date -D "%s" -d $WHEN +"%M %H %d %m"`
echo "$TARGET * /usr/share/linkmeter/alarm-all RING${al_probe}" | crontab -
else
# This is the cron callback
# Don't fire again
crontab -r
# Do whatever you want here, using another recipe
fi
Last edited: