Hello,
I would like to read SMS from my Huawei router. I have already integrated my router within HASSIO. It exposes the following entities but impossible to read the SMS received:
I have visibility regarding the number of SMS received within the router but I do not know their content/ their message.
My use case would be to trigger on automation when a special word/phrase is received. For example: “Open door” will open the door of my appartment building. This would allow my girlfriend/ or a friend to enter without the need of having the companion app by just sending a SMS with a specific keyword that then triggers an action !
Thanks for any help !
I would be also interested if someone could help on that
I have a Huawei E8372 and managed to read incoming SMS messages from the device. I thought I would share my findings here - I used the Huawei LTE integration and AppDaemon to achieve this.
Once the Huawei LTE integration was setup I created an AppDaemon app which monitors the SMS inbox count for changes, it also checks to see if the inbox has anything in it every 3 minutes. If it finds a message it stores that value in a input text helper and then deletes it from the device.
You can then use an automation to monitor the input text helper for changes as a trigger.
When setting up AppDaemon you need to include the “huawei-modem-api-client” as a Python package
I’m not really familliar with python but managed to piece this together from various samples and trial/error.
import appdaemon.plugins.hass.hassapi as hass
import huaweisms.api.user
import huaweisms.api.sms
USER = "####"
PASSWORD = "####"
SENSORINBOX = "sensor.e8372_sms_inbox_device"
INPUTTEXT = "input_text.sms_sender"
class haSMS(hass.Hass):
def initialize(self):
self.listen_state(self.hasms, SENSORINBOX)
self.run_every(self.hasms_timer, self.datetime(), 180)
def hasms(self, entity, attribute, old, new, kwargs):
ctx = huaweisms.api.user.quick_login(USER, PASSWORD)
self.log(ctx)
# output: <ApiCtx modem_host=192.168.8.1>
msgs = huaweisms.api.sms.get_sms(ctx, 1, 1, 1)
#format (ctx, Box number, page number, how many to get)
#Box numbers - inbox = 1, outbox = 2
nummsgs = int(msgs['response']['Count'])
if nummsgs > 0:
for k in range(0,nummsgs):
idx=int(msgs['response']['Messages']['Message'][k]['Index'])
content=str(msgs['response']['Messages']['Message'][k]['Content'])
num=str(msgs['response']['Messages']['Message'][k]['Phone'])
self.log("SMS from" + num + " msg=" + content)
self.set_state(INPUTTEXT, state = "SMS from " + num + " - " + content)
huaweisms.api.sms.delete_sms(ctx,idx)
self.log("Message deleted")
# Additional logic that runs every 180 seconds
def hasms_timer(self, kwargs):
ctx = huaweisms.api.user.quick_login(USER, PASSWORD)
self.log(ctx)
msgs = huaweisms.api.sms.get_sms(ctx, 1, 1, 1)
nummsgs = int(msgs['response']['Count'])
if nummsgs > 0:
for k in range(0,nummsgs):
idx=int(msgs['response']['Messages']['Message'][k]['Index'])
content=str(msgs['response']['Messages']['Message'][k]['Content'])
num=str(msgs['response']['Messages']['Message'][k]['Phone'])
self.log("SMS from" + num + " msg=" + content)
self.set_state("input_text.sms_sender", state = "SMS from " + num + " - " + content)
huaweisms.api.sms.delete_sms(ctx,idx)
self.log("Message deleted")