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.
Gammu seems overkill just to send notifications (and possibly react to notifications)
would you mind posting code or some idiot proof how to’s?
Not at all, I am at work currently, I will try on hassio to make sure it works.
In hassbian you may need to add homeassistant to the dialout group:
sudo adduser homeassistant dialout
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)
You can install chat in hass.io doing:
apk add ppp
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:
notify:
- platform: command_line
name: sms_person1
command: !secret notify_sms_person1
- platform: command_line
name: sms_person2
command: !secret notify_sms_person2
And the screts yaml:
notify_sms_person1: "/home/homeassistant/.homeassistant/send_sms.sh +1NNNNNNNNNN"
notify_sms_person2: "/home/homeassistant/.homeassistant/send_sms.sh +1NNNNNNNNNN"
Replace the NNN for the actual phone numbers
Here is my commit in my config.
this wont work for me because australia doesnt have a 2G network its so hard to find affordable 3G / 4G modules or gps trackers…
Still no way to make it work on hassio?
Visit this it contains a list of dongles compatible with Asus, they should also be compatible with Windows and most Linux distros. It has multiple choices for Australia
After fixing the stdin/stdout issue in the script, I don’t see why the script wont work with hassio, please give it a try and let us know.
Remember to execute this on the hassio shell before:
apk add ppp
Sorry, I missed that!
May I ask you some questions?
Should I use add-on like “ssh server” to install “chat”?
Where should I store that script? In www?
Is really all config I need is “notify:…” (and secret.yaml) and should not I write somewhere in configuration that I use that script in that folder?
And should not I write in which port I have usb gsm?
If you look at my secret sample above, I have encoded the location of the script (and the phone number) there.
In my case I put the script in the Hass config folder.
For hassio this folder is /config
I will suggest to put it there.
I encoded the serial port inside the script it self.
Does anyone knows how to pass a “secret” to the command line? I don’t, that’s why I hard coded it in the script.
did not get it actually
you put the script at config and used "/home/homeassistant/.homeassistant/send_sms.sh"
but it is incorrect location, isn’t it?
I get this
Command failed: /www/send_sms.sh +7900000000
And the script is in www
also I tried to copy your code. Changed the number and serial port. Got same issue
Then your secret should be:
notify_sms_person1: "/www/send_sms.sh +1NNNNNNNNNN"
notify_sms_person2: "/www/send_sms.sh +1NNNNNNNNNN"
Just out of curiosity, why would you want to put a bash script at the root of your www server?
Sounds like a security issue down the road.
I am just a noob. Selected www just because I used to store there custom files for lovelace.
Ok, Now it is again in config folder and I should write this:
notify_sms_person1: "/local/send_sms.sh +7NNNNNNNNNN"
notify_sms_person2: "/local/send_sms.sh +7NNNNNNNNNN"
Should I write here actual number, or I write here nnnnnn and actual number is somewhere else?
Yes, replace the entire first parameter with your phone number starting with the plus sign plus your country code plus your number (no dashes or parenthesis)
If someone could wrap this up into a add-on, many HA nobs like me would be delighted.
I am hoping for, one day, where I have a USB-GSM dongle attached to my Pi, and if internet goes down the dongle takes over until internet is up again. That would be a security system to trust.
Bad practice, www is for the world.
NNNN stands for the actuall number
To run a script you have to whitelist the containing folder
@Tomahawk
Maybe look for an ups where you put on your pi+router
(My internet is only getting down when there is no power)
For the last four months had lighting taking out my internet twice. One time my internet service provider used one week to get internet back. Being able to use GSM as backup, or as a main communication device for a cabin up in the mountain where cable internet is not available, would make HA complete as a security device.
Whilst this work is all great, there are many variables to consider… especially considering the type of dongle/bearer etc…
I would push for a Gammu Addon instead… https://github.com/pajikos/sms-gammu-gateway … use the right tools for the right job and don’t try to re-invent the wheel… or do, but then don’t complain about breaking changes down the line… but as i started off by saying… well done on the hard work and getting this working…