I wanted home assistant to be able to send SMS alarm messages from a USB stick in case the internet was off-line. I bought a Huawei E169 gsm stick, installed a program called chat with: “sudo apt-get install ppp”.
A simple bash script in /home/homeassistant/.homeassistant:
It turned out that I had made a mistake with my script. It would only work if I had first established a screen terminal session with the usb GSM stick before sending SMS from home assistant. Apparently the screen program sets the baud serial port settings needed for the GSM stick.
Here is the correct version for the sendSMS.sh bash script:
Not so perfect after all: if I start home assistant from a command line with: sudo -u homeassistant -H /srv/homeassistant/bin/hass, the sms messages will be sent.
But if I start home assistant with sudo systemctl start [email protected], no message gets sent.
It turns out that the command I use (chat) is not suitable for this type of script. I have now a new script that works fine, using a program called “gammu”.
Here is the new version:
#!/bin/bash
read count < /home/homeassistant/.homeassistant/smsCounter.txt
gammu sendsms TEXT 0123456789 -text "$1"
let 'count++'
echo $count > /home/homeassistant/.homeassistant/smsCounter.
For some reason, the script is best placed in /usr/bin, because (at least my) home assistant has trouble calling bash scripts from other directories.
Sorry to raise an old thread, but I was wondering if you had considered making an official Hassio Add-on for Gammu?
I am trying to receive sms notifications into HA to trigger various automation. I am looking to use GAMMU on a separate RPI, but was thinking if anyone knew how to create an add=-on that would be awesome.
While that looks awesome, I wanted to use my existing spare RPI3… for those of you that want to know how to do this, I managed to fire a webhook into HA (and therefore trigger my automations) on receipt of an SMS using this method:
I have no idea how to make a Hassio Add-on. I use home assistant, installed in a python virtual environment. But using the script is fairly easy and straightforward in a normal linux environment. Not sure about Hassio though.
stty is available in hass.io but chat is not available in hass.io, it comes from the ppp package.
Do you know how to modify hass.io to install the ppp package?
I suspect that the best way to support hassio is to replace the script and chat with a home assistant notification component built on top of pyserial
This should not be hard for an expert in python (which I am not, but willing to learn)
So I figure out how to fix the error “Can’t get terminal parameters: Inappropriate ioctl for device” discussed here
Turns out that chat is trying to read the response from STDIN, but in the context of Home Assistant this is incorrect as STDIN contains the message we want to send. It is also incorrect in that chat wont be able to verify if we got the correct response from the modem (e.g.: “OK” )
Here is a working script that can be executed from home-assistant:
#!/bin/bash
DEST=$1
# Modify the MD variable to match your hardware configuration
MD="/dev/ttyUSB2"
if [ -z "$2" ]
then
read message
else
message="$2"
fi
echo "Sending $message to $DEST"
stty -F $MD 9600 min 100 time 2 -hupcl brkint ignpar -opost -onlcr -isig -icanon -echo
chat TIMEOUT 10 "" "AT+CMGF=1" "OK" > $MD < $MD
chat TIMEOUT 10 "" "AT+CMGS=\"$DEST\"" "OK" > $MD < $MD
chat TIMEOUT 10 "" "$message^Z" "OK" > $MD < $MD
In home assistant you need to configure your yaml notification as: