Send SMS with USB GSM modem when alarm triggered

Thanks Petrica,
I finaly made some update in the source code by creating a custom component as explained in a previous post:

  1. Create a custom_components folder in your HA config (if you don’t have one already) and in that > create a sms folder and place the SMS github files in the folder
  2. Edit notify.py line 62 to encoded_message["SMSC"] = {"Number": "+4474XXXXXXX"} adding in your carriers Message Centre number (also called a service centre number)
  3. Edit the manifest.json file adding in "version": "0.0.1", between lines 2 and 3
    Restart HA and it should work. Do note that the integration will no longer update automatically.

As it is working for me, I proposed a modification to Oscar throw a fork :slight_smile: (hope I did it properly…)

SMS wont send after update to 2022.7.1

File “/usr/src/homeassistant/homeassistant/components/sms/notify.py”, line 56, in async_send_message

encoded = gammu.EncodeSMS(smsinfo)

SystemError: PY_SSIZE_T_CLEAN macro must be defined for ‘#’ formats

Logger: homeassistant.helpers.script.websocket_api_script
Source: components/sms/notify.py:56
First occurred: 12:05:20 (1 occurrences)
Last logged: 12:05:20

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 447, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 680, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/components/notify/legacy.py", line 229, in _async_notify_message_service
    await self.async_send_message(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/sms/notify.py", line 56, in async_send_message
    encoded = gammu.EncodeSMS(smsinfo)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

I’ve reloaded integration, restarted, readed integration… nothing helped.

2 Likes

Same

Logger: homeassistant.components.automation.arrosage_ligne2
Source: components/sms/notify.py:56 
Integration: Automatisation (documentation, issues) 
First occurred: 22:50:00 (2 occurrences) 
Last logged: 22:50:00

Arrosage ligne2: Error executing script. Unexpected error for call_service at pos 1: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
While executing automation automation.arrosage_ligne2
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 447, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 680, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/components/notify/legacy.py", line 229, in _async_notify_message_service
    await self.async_send_message(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/sms/notify.py", line 56, in async_send_message
    encoded = gammu.EncodeSMS(smsinfo)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

I have the same problem after update to 2022.7.0, sending and receiving SMS does not work after updating (event: sms.incoming_sms does not work too). In Node Red I have information after calling the API error notification. The modem parameters (device info) are read correctly in the HA. I’ve restored the backup to version 2022.6.7 and everything works fine so it’s not the modem’s fault.

1 Like

It is connected with implementation of new version Python 3.10. I’m using ha os on pi but I know to resolve this issue needed is to make Installation some additional modules. Did somone try it or has another workaround?

Indeed it reworks this morning. I notice there are some new entities likes « cell_id » or « network_name » present but not accessible.

You have to enable them.
HA :slight_smile: 2022.7.3 - SMS are working again :slight_smile:
Thank You!

1 Like

Hello,
Thank you for the reactivity to correct the problem.

I still can’t get the sms to work again.
When I return to version 2022.6.7 the sms work again.

Here is my setup.

Version	core-2022.7.3
Type d'installation	Home Assistant Supervised
Développement	false
Supervisor	true
Docker	true
Utilisateur	root
Environnement virtuel	false
Version de Python	3.10.5
Famille du système d'exploitation	Linux
Version du système d'exploitation	5.10.0-15-amd64
Architecture du processeur	x86_64
Fuseau horaire	Europe/Paris
Configuration Directory	/config

I use a 3g dongle Huawei

With version 2022.7.3
I have the integration that starts but not the sending of sms.
I tried removing the embed.
I tried restarting.

Thanks for any help you can give me.
Good night


I answer myself since after all the tests that I had been able to do the SMS did not work.
but again the sms works.
why:

  • I had misconfigured some “call service” like that of my SMS sending test.

Thanks to the programmers for their speed of correction.

good day to all

Hello, is there a plan to support modem connected to remote gammu server?
I consider moving my Huawei E3272s modem to OpenWRT router and use it like an LTE modem.
Can the remote modem be used somehow to also send SMS messages from hassio?

1 Like

Sorry about digging up an old thread.

I would however be wary of sending any personal data over Twilio…

Twilio uses “Grey Routes” to route sms messages around the world. To get the best rates/costs, the routes followed are unregulated and your message may pass through many many many, unregulated and unscrupulous hands before it gets to you with messages in plain text visible to all that handle the message…

You always get what you pay for, this is especially true in the murky world of SMS brokers and aggregators…

For our applications we actually use a carrier with direct links into a tier 1 global telco. We therefore know the routes our messages take and delivery is fast, reliable and private… have a look here for example → https://ezoconnect.com that is who we use…

1 Like

I use Gammu on a vm (outside Hassio) Have a look here: https://github.com/pajikos/sms-gammu-gateway

2 Likes

Hello, I have the same serial modem as you but I can’t figure out how to make it work.
I have the same thing in my configuration file except for the notify because I’m getting an invalid configuration file of that.
But I have the feeling he can’t connect to my modem but if I do the same command as you I have the same response which I use in my configuration file.
Any ideas what I can try?
I also don’t see the SMS integration in the list of integrations.

Do you have to install drivers for those serial devices?
If so, can I just use any linux command or so to install that in a home assistant VM?

When I connect the device to a windows machine it isn’t reconigzed.

I have the same modem. It uses a ch341 serial to USB converter chip. This is a very common chip in cheap Chinese devices, it’s basically a Chinese clone of the well known FTDI 232 chip. Most Linux distributions come with a driver in the kernel and will automatically recognize it (I’m on Debian and the modem maps to ttyUSB0). On Windows you’ll need a driver.

If you use HAOS, then I have no idea. It’s a very bare bones OS.

yeah I found the correct tty but the SMS integration failed to connect with it.
But when I use cat on the device and another ssh window to send commands I get a response but I’m getting like 100s of lines of response from only the AT commands which is odd.

also when doing the creg command, I’m getting 0,2 back so apparently it can’t connect with the network so will have to figure that one out as well.

Keep in mind that the SIM800 chip can only handle GSM / 2G networks, so make sure that such a network is available in your area and that your SIM card and service plan supports it. Sadly a lot of countries and operators have opted to close down GSM service over the last years. If you are certain to have such service available in your area, plug the SIM card into your phone and force it into GSM / 2G mode. Make a call using the 2G network. Then put the card back into the modem and see if it registers.

In my testing the sim800c chip requires to specify the baud speed

If he can issue AT commands and gets responses that aren’t gibberish (like the reponse to AT+CREG he mentioned), then the baud rate is correct at least on the OS and modem level. But maybe the SMS integration requires explicit baud rate config, I don’t know, I don’t use this integration.

I’m not using Gammu or anything like that either. If all you want is to send SMS (not receive) then this whole stuff is overkill. I just wrote a quick and dirty executable that will directly communicate with the SIM800 chip and send any text you supply as arguments to the shell command as an SMS to a predefined number. This can then be integrated into HA as a shell command. I can post the source if there’s interest, it’s really not very complicated.

Yeah I have done that, I’m able to send a sms on my phone on 2g.
So it’s very strange that the sim800 module can’t connect to the network.

Also it spits out a lof of response when executing a simple AT command.

Indeed my response isn’t gibbisch, I see the OK response and so on but it does it like 300 times for 1 command.

HeylmAlex would you want to share your script because I only want to send SMS for now.
It’s just that I want to use this for my home security system when notifications are down due internet loss or power loss (server is on a backup battery).