I purchased a Huawei E3531 not realising that is has problems receiving texts when using Gammu. I have it now working on a raspberry pi and had created the following that runs as a daemon:
#!/usr/bin/python
import shutil
import requests, sys
import xml.etree.ElementTree as ET
import paho.mqtt.client as paho
import os
import time
broker = "192.168.7.1" #MQTT broker IP address
port = 1883 #MQTT broker port
topic = "alarm/sms-incoming" #MQTT topic
ip = "192.168.1.1" #Dongle IP address
newloc = "/home/pi/alarmsms/temp" #Location to store new.txt for comparison
oldloc = "/home/pi/alarmsms/temp" #Location to store old.txt for comparison
client1=paho.Client("control1") #create MQTT client object
# os.system("sudo usb_modeswitch -v 12d1 -p 1f01 -M '55534243123456780000000000000a11062000000000000100000000000000'")
while True:
#Get token
r = requests.get("http://"+ip+"/api/webserver/token")
root = ET.fromstring(r.content)
token = root[0].text
print "token", token
if not os.path.exists(newloc+"/new.txt"):
file(newloc+"/new.txt", 'w').close()
shutil.move(newloc+"/new.txt", oldloc+"/old.txt")
#Check SMS received
headers = { "__RequestVerificationToken": token, "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "X-Requested-With": "XMLHttpRequest", "Referer": "/html/smsinbox.html?smsinbox" }
data = "<request><PageIndex>1</PageIndex><ReadCount>1</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>"
r = requests.post( "http://"+ip+"/api/sms/sms-list", data=data, headers=headers )
print "send-sms", r.headers, r.content
text_file = open(newloc+"/new.txt", "w")
text_file.write(r.content)
text_file.close()
#compare
with open(newloc+"/new.txt") as newfile:
with open(oldloc+"/old.txt") as oldfile:
if newfile.read() == oldfile.read():
time.sleep(2)
else:
client1.connect(broker,port) #establish connection
ret= client1.publish(topic,r.content)
time.sleep(2)
I am not a coder so this was bodged together, but it does work.
Basically, when a new SMS is received, if it’s different from the last SMS received then the data will be sent to the specified MQTT topic. I then use nodered to manipulate the data and send on to my alarm system to arm etc
One thing I had to do, was make sure the Huawei E3531 was set to the right mode. It should be the following for the above to work:
ID 12d1:14dc Huawei Technologies Co., Ltd. E33372 LTE/UMTS/GSM HiLink Modem/Networkcard
To do this, I had to run the following:
sudo usb_modeswitch -v 12d1 -p 1f01 -M ‘55534243123456780000000000000a11062000000000000100000000000000’
The Amazon reviews include buyers who have successfully used the device on their Pi. I have it plugged into a USB hub that connects to a USB3 port on my Pi. Earlier, I installed/tested the modem on my Windows laptop and when the network connection had been established, a blue led was constantly flashing on the modem. This same blue led is flashing while the modem is currently plugged into my Pi, so I suspect that a proper connection has been established with my Pi. Here is what my Pi displays on the screen when I plug in the modem:
notice the final IPv6 line. usb0: link becomes ready
So, I have reason to believe this modem should work. I have run the lsusb command and added a USB drive with volume label CONFIG and /udev/10-gsm-modem.rules with the appropriate IDs from my lsusb results (19d2:1405).
Hi,
In my case, also with a E3531 the AT command that did the trick was : AT^SETPORT=“FF;10,12” as seen on the following website : https://blog.le-vert.net/?p=196
Can’t believe how hard it was to set this up… Had to install Hilink, install COM support in Windows 10 as it is considered legacy, launch a special curl command to go in COM mode, find a correct unlock code, change firmware, find and install drivers in Windows, set-up Putty correctly yo be able to launch AT commands, test various AT commands… But it seems I was successful at last :-p
There is a known issue in gammu where the API that deletes old messages fails.
This has already been fixed, and we need to update of the hass os to get the fix.
I just picked up an E3372h-510 and followed a hybrid of the steps provided in this link and this link to switch it to “stick mode”.
This method works! I am sending SMS with no need for a modeswitch file. It requires that you open your modem with a Torx screwdriver and ground out the connection (as shown in the below video), then proceed with the commands to flash the proper firmware (as described in the links I provided above).
@Oscar_Calvo linked to this page in an earlier post, but I think that method no longer works. @kslb perhaps you are still interested. I’m entirely new to Linux and I was able to get this method to work.
Twilio is very affordable. See my post about Twilio costs here.
The SIM is tied to my Twilio account, and the phone number is purchased separately in my Twilio account. So, I can cancel the SIM whenever I’d like, but keep the number so I can still place calls over the internet without a SIM. For sending SMS with a SIM, configuration is simple. Just use the SMS integration configuration. Otherwise, you can send Twilio SMS over the internet.
Sure. I have a Twilio account (referral code in link, if you’d be so kind), in which I have subscribed to a phone number for $1/mo and a SIM for $2/mo. The account is prepaid, funded with a credit card, and I have it setup such that a balance of less than $10 will top it back up to $20.
The Twilio SIM is in my Huawei E3372h-510 (flashed with serial firmware) and is configured with the SMS integration. It can send an SMS to my cell phone like any SIM. Twilio uses the T-Mobile network in the US. The cost is 0.01 per message, it seems. So, if I send 100 messages per month, my Twilio costs for the month are $1 for the phone number + $2 for the SIM + (100 messages x $0.01) = $4.
Twilio also offers a text-to-speech telephone call service, for which there is a HA integration. After achieving success with the SMS integration over an Internet connection, my next objective was to setup this Twilio Call integration to place calls via the Huawei modem. It worked fine over the Internet, but my intent is to use my RPi in a location that has no Internet connection, so event tiggers should call my cell phone via Twilio Call over the Huawei. It worked by my adding the device: /ttyUSB0 line to my twilio_call configuration in the yaml file. The cost for a Twilio call is $0.013 per minute.
In short, the SMS and the Twilio Call are both being sent through my Twilio SIM.
I’ve been wanting to do the seem thing as a backup for my alarm system when the Internet is down. Can you provide more detailed info on your hardware and software setup? Going to re-look at doing this integration with HA again. Thanks
At the moment I’m on a Pi4-64/8gb running 64-bit Raspberry OS (2020-08-20-raspios-buster-arm64). I have hassio running in Docker. Actually, I plan to pick up a used (new to me) Win10 i5 from my computer guy, when he has it ready, for a virtual Debian environment / Docker / Hassio. I presume retracing my steps to arrive at this same point on the virtual machine will be straightforward.
@kslb: Like you, it seems that I am unable to receive incoming SMS via the E3372h. @Oscar_Calvo I did try /dev/ttyUSB0 and /dev/ttyUSB1, and both can send outgoing but neither show any Events when I am listening to sms.incoming_sms in HA. I did install sudo apt-get install libgammu-dev in my Raspberry OS CLI. However, since the SMS integration specifies that “When running Home Assistant, you need to install the SSH add-on.”, I wonder whether I am supposed to install sudo apt-get install libgammu-dev via the SSH add-on for HA? Admittedly, I am a bit confused (noob here); I am unable to execute sudo apt-get install libgammu-dev when I use Putty to SSH into HA (apparently sudo and apt-get are both unrecognized). Am I doing something incorrectly?
I’m really going to town with replies today. I think this warrants a new post, and not an edit.
After trying to get incoming SMS to work to no avail, by switching to ttyUSB1 and back, and installing sudo apt-get install libgammu-dev, I have tried to send a Twilio Call through the modem and it’s not working. I’m trying to resolve it (feel free to help a noob if you have ideas). Outgoing SMS still works fine. Just trying to get Twilio Call to work again. I uninstalled libgammu-dev and restarted, which didn’t seem to have any effect.
@Oscar_Calvo Hello, I am testing HassOS V5.5 64 bits on a Pi4B and I am trying to use SMS integration with a Huawei E3531… I can change the modem to serial modem and see 3 ttyUSB… but when I try to send SMS, I have the following error:
2020-11-25 19:58:53 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.gsm_signal_imei_8611430357XXXXX is taking over 10 seconds
2020-11-25 19:58:55 ERROR (MainThread) [homeassistant.components.sms.notify] Sending to 0484XXXXXX failed: ERR_UNKNOWN
Based on what I see on the modem, it is not connected to the SMS provider (led flashing twice every 2 seconds), but if I move this modem on another raspberry pi with Raspbian 32 bits, it is able to connect to the provider… Driver issue ? 64 bits issue ?
Do you know if this modem is working with HassOS V5.5 64 bits ? Any recommendation for a compatible modem ? Thanks !
@Oscar_Calvo I found the root cause of the problem… Power issue !.. I had to add a powered USB hub and that fixed the issue… I can now send SMS with Huawei E3531 on HassOS V5.5 64 bits (Pi4B 2GB) !
Update: SMS reception is still problematic… It worked once (for the first SMS in the inbox) but no reaction to the other SMS received… I had two other SMS going to the Inbox and intercepted by HA… I don’t know why those two… Strange …
As the SMS integration is not able to receive SMS (bug in Gammu ?), I decided to customize two python scripts using python-gsmmodem_new (version 0.12)… One to read new SMS from inbox, the other one to send SMS… Working fine sofar with a Huawei E3531 configured as serial modem (12d1:1001) on hassos V5.5 64 bit (Pi4B 2B)…
Hello, i have a Huawei key 4g (on hass.io and vmware esxi) and i want to send sms for my alarm notifications. I installed “Send SMS with USB GSM” and this in my configurations.yaml :
sms:
device: /dev/ttyUSB0
notify:
platform: sms
name: Tel
recipient: ‘06xxxxxxxx’
But in the tutorial he say : Set this content in file udev\10-gsm-modem.rules
I don’t find the udev folder in hass.io
And the second question is : can i configure pin code or i disable it ?
@Akhethan Hello, the “10-gsm-modem.rules” file is used by storing the file on a USB key to change to status of the modem stick from storage to modem mode… I think yours is already in modem mode as a serial modem based on what I see in your post…
To send a sms, look at your services, you should use the service “notify.tel” in your case or something like that…
Than in the automation or test in the “development menu” > “services”, add the following action this should send your SMS if everything is OK (if something wrong, look at home-assistant.log for any error message related to SMS platform):
Hi, i’m using huawei 3531, with HA in docker env.
i’ve configured the integration. I can’t recieve messages while sending works fine. There is no sms.incoming_sms event in logs. Any one could help?