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…
The problem with Gammu is that it does not uses an async approach to talk to the modem, it locks
for every single call to the modem.
The goals will be to use the async serial interface for python to make sure we don’t use the global python lock which if used in Home Assistant will block.
I do agree, however, maybe we should create another python async friendly library to abstract SMS commands and then have a hass specific extension on top of that.
Today I completed my migration to hassio.
However, I ran into a problem in how Alpine recognizes the Hauwei USB stick, it refuses to install the usb serial driver for it.
In other Linux distros you are supposed to run usb_switch, however running this in hass.io give me the following error:
This is a version of a python script compatible with hassio:
import serial
import sys
import getopt
import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
DEST=sys.argv[1]
#MD="/dev/ttyUSB2"
MD="COM10"
if (len(sys.argv) > 2):
message=sys.argv[2]
else:
message = ''
for line in sys.stdin:
message+=line
logging.debug('Sending message '+message+' to '+DEST)
logging.debug('Opening serial port '+MD)
ser = serial.Serial(MD) # open serial port
ser.write(b'\x1a') # Flush any previuos attempts to send message
ser.flush()
logging.debug('Sending AT+CMGF command')
line = b''
ser.write(b'AT+CMGF=1\r')
while line!=b'OK\r\n':
line = ser.readline()
logging.debug('Response '+str(line))
ser.flush()
logging.debug('Sending AT+CMGS command')
line = b''
phoneAsAscii = bytes(DEST, 'ascii')
ser.write(b'AT+CMGS="'+phoneAsAscii+b'"\r')
while line!=b'> \r\n':
line = ser.readline()
logging.debug('Response '+str(line))
ser.flush()
logging.debug('Sending message')
messageAsAscii = bytes(message, 'ascii')
ser.write(messageAsAscii + b'\x1a')
line = b''
while line!=b'OK\r\n':
line = ser.readline()
logging.debug('Response '+str(line))
ser.close()
Another good reason to have a native SMS integration.
Invalid config for [sms]: No device at /dev/ttyUSB3 found for dictionary value @ data['sms']['device']. Got '/dev/ttyUSB3'. (See /config/configuration.yaml, line 210).
Do you see your modem? Then make sure you are sharing that serial device with the container. (I am not an expert in docker but there is a way to do this)
If this work please share the solution to update the documentation
SOLVED I needed libgammu-dev installed at the base system level.
Leaving my post below for reference…
================================
Thanks for your work on this @Oscar_Calvo.
I’m looking forward to replacing my existing sms integration call gammu through a parameterised shell_command.
Unfortunately I’m unable to get python-gammu installed on my Python3.7 venv running on Ubuntu 18.04 when the sms integration is configured.
Running the install command under the homeassistant user within the activated venv gives me some clues as to what is going on:
(homeassistant) homeassistant@moxon:~/.homeassistant$ python3.7 -m pip install python-gammu
Collecting python-gammu
Using cached python-gammu-2.12.tar.gz (135 kB)
ERROR: Command errored out with exit status 100:
command: /srv/homeassistant/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ea2vl0z7/python-gammu/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ea2vl0z7/python-gammu/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-ea2vl0z7/python-gammu/pip-egg-info
cwd: /tmp/pip-install-ea2vl0z7/python-gammu/
Complete output (9 lines):
Package gammu was not found in the pkg-config search path.
Perhaps you should add the directory containing `gammu.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gammu' found
Package gammu-smsd was not found in the pkg-config search path.
Perhaps you should add the directory containing `gammu-smsd.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gammu-smsd' found
Can not find supported Gammu version using pkg-config!
----------------------------------------
ERROR: Command errored out with exit status 100: python setup.py egg_info Check the logs for full command output.
gammu-smsd is installed (with sudo apt install gammu-smsd) but I’m guessing that the above is related to permissions?
I’m rather out of my depth at this point so would appreciate any pointers you could provide.
hi,
I’m a noob with home assistant, and I’m coming from domoticz. I installed hass.io, and I’m trying to install gammu (I write a python script to control domoticz via SMS : start alarm, stop alarm, send SMS when something happened etc… and I need to do something like this). But I don’t understand what is my problem, and what I need to do to install this addon. Only modification in configuration.yaml? must I install some script? must I install gammu (apk)?
If somebody can help, it will be really nice
Thanks a lot
my conf: hassos 3.9 on rasberry pi 3B home assistant 0.105.2