home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.78k stars 30.49k forks source link

The sms integration “SMS notifications via GSM-modem” doesn't work ob core 2021.7 (2021.7.0 - 2021.7.2) #53072

Closed scxs001 closed 3 years ago

scxs001 commented 3 years ago

The problem

The sms integration “SMS notifications via GSM-modem” doesn't work on core 2021.7 (2021.7.0 - 2021.7.3), but it works fine on 2021.6.6. Please check, thanks

What is version of Home Assistant Core has the issue?

2021.7.3

What was the last working version of Home Assistant Core?

2021.6.6

What type of installation are you running?

Home Assistant OS

Integration causing the issue

SMS notifications via GSM-modem

Link to integration documentation on our website

https://www.home-assistant.io/integrations/sms

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.sms.gateway
Source: components/sms/gateway.py:167
Integration: SMS notifications via GSM-modem (documentation, issues)
First occurred: 20:32:50 (1 occurrences)
Last logged: 20:32:50
Failed to initialize, error ERR_NOTSUPPORTED

Logger: homeassistant.components.sms.notify
Source: components/sms/notify.py:24
Integration: SMS notifications via GSM-modem (documentation, issues)
First occurred: 20:32:50 (1 occurrences)
Last logged: 20:32:50
SMS gateway not found, cannot initialize service

Logger: homeassistant.components.notify
Source: components/notify/init.py:311
Integration: notify (documentation, issues)
First occurred: 20:32:50 (1 occurrences)
Last logged: 20:32:50
Failed to initialize notification service sms

Additional information

No response

probot-home-assistant[bot] commented 3 years ago

sms documentation sms source (message by IssueLinks)

prigal commented 3 years ago

I think it's a duplicate of https://github.com/home-assistant/core/issues/52674

scxs001 commented 3 years ago

still doesn't work on core 2021.7.3

dolenec commented 3 years ago

Jp.. still not solved in 2021.7.3

dolenec commented 3 years ago

Still no solution?

scxs001 commented 3 years ago

let's wait if this error fixed with the next update

dolenec commented 3 years ago

By itself?

scxs001 commented 3 years ago

of course by @frenck and the other manito hopefully

dolenec commented 3 years ago

Do you see any other activity here, except us? Nobody cares..

scxs001 commented 3 years ago

unfortunately yes, compared with other integration, the SMS is probably rare to be used

jujumo commented 3 years ago

From source code, its seems that is Octavio that is the author. Some activity on the integration is listed in april/march, but it looks like it is only cosmetics changes.

Anyway, the error appears while calling external lib (gammu?). It would be very hard to debug it without the actual hardware and debugger dont you think ?

I would be happy to do it, but I really dont know how to attach a debugger on a running integration. Anyone can help on this ?

scxs001 commented 3 years ago

maybe @ocalvo can help us

dolenec commented 3 years ago

Also I can debug, if somebody tell step by step what it need to be done..

ocalvo commented 3 years ago

I am on vacation until August. For the time being can you attach a debug log. This is a setting you change in your yaml configuration.

Can someone help here with pasting the details to do that here. I am away from a desktop at the moment.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Simon Dolenec @.> Sent: Tuesday, July 20, 2021 6:22:16 PM To: home-assistant/core @.> Cc: Oscar Calvo @.>; Mention @.> Subject: Re: [home-assistant/core] The sms integration “SMS notifications via GSM-modem” doesn't work ob core 2021.7 (2021.7.0 - 2021.7.2) (#53072)

Also I can debug, if somebody tell step by step what it need to be done..

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fhome-assistant%2Fcore%2Fissues%2F53072%23issuecomment-883524726&data=04%7C01%7C%7C7b62bbf095d94a894d7708d94b9a8ab7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637623949383742530%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=bhekusToRaON4L39VOemI6f8EvehxcqQUR3sfqDXBV4%3D&reserved=0, or unsubscribehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAAP6UPTKLLQRY3COOLM77ITTYWPDRANCNFSM5AOXVXJA&data=04%7C01%7C%7C7b62bbf095d94a894d7708d94b9a8ab7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637623949383752529%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Fgl8BMSrrXd2Iaq04GXxADV9627eS%2BkniCRy9fskPH0%3D&reserved=0.

scxs001 commented 3 years ago

@ocalvo thanks,

# Example configuration.yaml entry logger: default: info #or critical logs: homeassistant.components.sms.gateway: debug homeassistant.components.sms.notify: debug

https://www.home-assistant.io/integrations/logger/ did I understand correctly?

scxs001 commented 3 years ago

guys, I give up with SMS integration.

I am currently using twilio trial for free to implement sms function,

simply register on https://www.twilio.com/try-twilio?promo=qLyrBG with promotion or directly https://www.twilio.com

There are of course restrictions on the trial version, but it is more than enough for me at the moment

for more infomation: https://support.twilio.com/hc/en-us/articles/360036052753-Twilio-Free-Trial-Limitations

after registration, setting in configuration.yaml file: twilio: account_sid: ACCOUNT_SID_FROM_TWILIO auth_token: AUTH_TOKEN_FROM_TWILIO> notify: - name: NOTIFIER_NAME platform: twilio_sms from_number: E164_PHONE_NUMBER or SENDER_ID

https://www.home-assistant.io/integrations/twilio_sms/

maybe this can help you.

glith commented 3 years ago

Twilio is dependent on internet connectivity. GSM modem is not. Not a valid solution to the GSM modem problem :/ 2021.6.6 is working until ocalvo is back and maybe can have a look.

scxs001 commented 3 years ago

you are right, it's no required for hardware such as a modem or SIM card , but you need a constant Internet connection, i.e. this solution is not intended for emergencies without the Internet

jujumo commented 3 years ago

Twilio is not relevant here, it does not compare. Do you know how to dynamically switch to the 3G network when landline broke-down ? Metering does not seem to do the trick.

dolenec commented 3 years ago

I'm using this function in serious events aka fire and so on and in this case we can not depend if internet is On or Off - solution must be working and via SMS HW it is working (+ UPS and some other must have HW).

Also - in case of that internet stop working this is the only good way to report it via SMS... All other internet protocols are just wanna be stuff which never will be.. just my humble opinion..

bistek22 commented 3 years ago

I am using this feature as well, I will be very grateful to fix the bug

scxs001 commented 3 years ago

as I already said, there are limitations with twilio, it must have a internet connection at all time, for those who simply want to receive the SMS as notify like me, it is fully sufficient, for those who also want to have the notify in an emergency without internet, the SMS integration is irreplaceable. you just have to wait, the SMS integration will certainly work again in August at the latest, until @ocalvo comes back, but a debugging will definitely be helpful for him to check the bug.

ocalvo commented 3 years ago

as I already said, there are limitations with twilio, it must have a internet connection at all time, for those who simply want to receive the SMS as notify like me, it is fully sufficient, for those who also want to have the notify in an emergency without internet, the SMS integration is irreplaceable. you just have to wait, the SMS integration will certainly work again in August at the latest, until @ocalvo comes back, but a debugging will definitely be helpful for him to check the bug.

Yes. If someone could paste the logs, I may be able to infer where the problem is, and save a lot of time. I suspect this could be an unexpected breaking change in core, if so, you won't need to wait for me. But we need the logs.

jujumo commented 3 years ago
2021-07-25 16:10:57 ERROR (MainThread) [homeassistant.components.sms.gateway] Failed to initialize, error ERR_NOTSUPPORTED
2021-07-25 16:10:57 INFO (MainThread) [homeassistant.components.notify] Setting up notify.sms
2021-07-25 16:10:57 INFO (MainThread) [homeassistant.components.notify] Setting up notify.sms
2021-07-25 16:10:57 ERROR (SyncWorker_5) [homeassistant.components.sms.notify] SMS gateway not found, cannot initialize service
2021-07-25 16:10:57 ERROR (SyncWorker_5) [homeassistant.components.sms.notify] SMS gateway not found, cannot initialize service
2021-07-25 16:10:57 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.mqtt
2021-07-25 16:10:57 ERROR (MainThread) [homeassistant.components.notify] Failed to initialize notification service sms
2021-07-25 16:10:57 ERROR (MainThread) [homeassistant.components.notify] Failed to initialize notification service sms
Logger: homeassistant.components.sms.notify
Source: components/sms/notify.py:24
Integration: SMS notifications via GSM-modem (documentation, issues)
First occurred: 4:10:57 PM (2 occurrences)
Last logged: 4:10:57 PM
SMS gateway not found, cannot initialize service
Logger: homeassistant.components.sms.gateway
Source: components/sms/gateway.py:167
Integration: SMS notifications via GSM-modem (documentation, issues)
First occurred: 4:10:57 PM (1 occurrences)
Last logged: 4:10:57 PM
Failed to initialize, error ERR_NOTSUPPORTED
TazUk commented 3 years ago

Similar issues here running HomeAssistant container in Docker on Ubuntu 18.04 LTS.

I attempted an upgrade from 2021.6.6 directly to 2021.7.4 and SMS failed to initialise after the install of python-gammu failed with

ERROR: Command errored out with exit status 101:
     command: 
     /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-j9ofbzup/python-gammu/setup.py'"'"'; __file__='"'"'/tmp/pip-install-j9ofbzup/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-pip-egg-info-rx9d33ew
    cwd: /tmp/pip-install-j9ofbzup/python-gammu/
    Complete output (5 lines):
    Failed to find Gammu!
    Either it is not installed or not found.
    After install Gammu ensure that setup finds it by any of:
     * Specify path to it using GAMMU_PATH in environment.
     * Install pkg-config.
    ----------------------------------------
ERROR: Command errored out with exit status 101: python setup.py egg_info Check the logs for full command output.

Connecting into the container I was able to install python-gammu after the following installs (not all of which may be relevant - the errors I saw on trying to manually install python-gammu within the container suggested gcc (and possibly other components) were missing. NB: I have no real knowledge in this area and was just poking around before reverting so take all this with a pinch of salt.

apk update
apk add gammu gammu-smsd gammu-dev gammu-libs build-base

Once I'd been able to manually install python-gammu in the container I then uninstalled it and restarted HA. After restarting HA I was then able to go beyond the python-gammu error and reach the errors reported by others above (ERR_NOTSUPPORTED)

I've now reverted to 2021.6.6.

redice2k commented 3 years ago

i have the same problem with the same error, i tried the 2021.7.4 of HA but it doesn't solve the problem. Now reverted to 2021.6.6.

cllatser commented 3 years ago

I had the same problem. It's like you can't access the device. I am back to version 2021.6.6 and everything works as before. El problema es que no puede acceder al dispositivo. Puede ser un error en la imagen de docker. The problem is that you cannot access the device. It may be a bug in the docker image.

ocalvo commented 3 years ago

@pvizeli has there been changes in how to access serial devices in the new alpine version? Is the libgammu component still getting installed?

thijsputman commented 3 years ago

Some additional insights that might be helpful:

It appears the first time Home Assistant/libgammu attempts to open the serial device, something goes wrong and it blocks on the device. This causes the ERR_NOTSUPPORTED error to appear.

Subsequent attempts to connect to the serial device (from within Home Assistant) generate a ERR_DEVICEOPENERROR (presumably because the device is held open in the initial failed attempt?). Once Home Assistant starts throwing ERR_DEVICEOPENERROR, attempting to use the serial device from outside of the container also doesn't work any more:

> gammu networkinfo
Error opening device. Unknown, busy or no permissions.

If I remove SMS support from my Home Assistant configuration, restart the container, connect into it and manually install gammu (apk add gammu; configure gammu via ~/.gammurc) I can run gammu commands (e.g. gammu networkinfo) without problems. They return the same information as when run from outside of the container.

jujumo commented 3 years ago

Yes, I also noted that the USB device is not freed via "lsof" when init fails . That's a good remark

Jedrek2021 commented 3 years ago

I have the same problem with the same error, i tried new version the core-2021.8.0 of HA but it doesn't solve the problem. Now reverted from backup to 2021.6.6.

dolenec commented 3 years ago

It is shame that the system is set up that they can publish new updates withouth fixing in the past already working and implemented stuff.. In this way you never can be sure when some component stopped to work with new updates.. For me last time was MS SQL, now this.. no solution in sight..

ocalvo commented 3 years ago

I was able to initialize the modem by manually deleting the integration and add it again via the integrations menu. Still doing more testing...

dolenec commented 3 years ago

I was able to initialize the modem by manually deleting the integration and add it again via the integrations menu. Still doing more testing...

Is it working in your tests? What do you mean by manual deleting it.. Can you give step by step what did you do..

dolenec commented 3 years ago

@pvizeli - any help from HA team regarding this..? It seems that this is the problem of new OS release / HA core..

ocalvo commented 3 years ago

I was able to initialize the modem by manually deleting the integration and add it again via the integrations menu. Still doing more testing...

Is it working in your tests? What do you mean by manual deleting it.. Can you give step by step what did you do..

I was only able to recover my development environment, I have found no way to resolve the issue on the production environment.

ocalvo commented 3 years ago

I have confirmed that the sync gammu is working fine: docker exec -it 8fe4a74f4604 python -c 'import gammu; from gammu.asyncworker import GammuAsyncWorker; config = {"Device": "/dev/ttyUSB0", "Connection": "at"}; sm = gammu.StateMachine(); sm.SetConfig(0, config); sm.Init(); i = sm.GetIMEI(); print(i); '

Replace the docker id and the device for your own device and actual core docker instance id.

ocalvo commented 3 years ago

The async worker is also working fine: docker exec -it 8fe4a74f4604 python -c '\ import gammu from gammu.asyncworker import GammuAsyncWorker import asyncio async def main(): config = {"Device": "/dev/ttyUSB0", "Connection": "at"} worker = GammuAsyncWorker() worker.configure(config) await worker.init_async() i = await worker.get_imei_async() print(i) event_loop = asyncio.get_event_loop() event_loop.run_until_complete(main()) ' This code prints the IMEI of the phone.

At this point, I dont know where else to look for.

ocalvo commented 3 years ago

I think I might understand what is going on, if I execute this command:

docker exec -it 8fe4a74f4604 python -c '\
import gammu
from gammu.asyncworker import GammuAsyncWorker
import asyncio
def sms_callback(state_machine, callback_type, callback_data):
   print("sms_callback")
async def main():
  config = {"Device": "/dev/ttyUSB0", "Connection": "at"}
  worker = GammuAsyncWorker()
  worker.configure(config)
  await worker.init_async()
  i = await worker.get_imei_async()
  print(i)
  try:
    await worker.set_incoming_sms_async()
  except gammu.ERR_NOTSUPPORTED:
    print("Warning: Your phone does not support incoming SMS notifications!")
  else:
    await worker.set_incoming_callback_async(sms_callback)
    print("worker.set_incoming_callback_async(sms_callback)")
event_loop = asyncio.get_event_loop()
event_loop.run_until_complete(main())
'

Then I see that worker.set_incoming_sms_async() fails in the thread with ERR_NOTSUPPORTED, this is the first problem, this used to work before. The second problem is that the exception is not raised back to the main thread, so the catch is never executed. This is the second problem.

I am not an expert on phyton, could some explain to me how to raise exceptions from a worker thread back into the parent thread?

To summarize, we have 2 problems:

  1. In newer builds of core, the call to GammuStateMachine.SetIncomingSMS() now fails.
  2. Exceptions from the worker thread are not raised in the main thread.

I am working on confirming problem number 1.

ocalvo commented 3 years ago

Yes, the root problem is that in the newer version of core gammu.StateMachine.SetIncomingSMS() now returns ERR_NOTSUPPORTED.

Confirmed with this command:

docker exec -it 8fe4a74f4604 python -c 'import gammu; from gammu.asyncworker import GammuAsyncWorker; config = {"Device": "/dev/ttyUSB0", "Connection": "at"}; sm = gammu.StateMachine(); sm.SetConfig(0, config); sm.Init(); i = sm.GetIMEI(); print(i); sm.SetIncomingSMS(); print("SetIncomingSMS"); '
ocalvo commented 3 years ago

Created PR with fix. Please review.

glith commented 3 years ago

Great news! Thanks! Are you also working on how to get the receiving part working? I use it for remote status checks when internet is not available.

ocalvo commented 3 years ago

Great news! Thanks! Are you also working on how to get the receiving part working? I use it for remote status checks when internet is not available.

Yes, I am planning on adding support for "polling" to be able to receive incoming SMS. I need to read the dev doc because integrations need to support turning off polling.

TazUk commented 3 years ago

Great news! Thanks! Are you also working on how to get the receiving part working? I use it for remote status checks when internet is not available.

Yes, I am planning on adding support for "polling" to be able to receive incoming SMS. I need to read the dev doc because integrations need to support turning off polling.

Just to check my understanding, is incoming SMS broken in all cases above 2021.6.6?

ocalvo commented 3 years ago

Great news! Thanks! Are you also working on how to get the receiving part working? I use it for remote status checks when internet is not available.

Yes, I am planning on adding support for "polling" to be able to receive incoming SMS. I need to read the dev doc because integrations need to support turning off polling.

Just to check my understanding, is incoming SMS broken in all cases above 2021.6.6?

Most likely, yes. I believe this is a bug in either gammu or Alpine or both, as the same GSM modem works fine in my development environment (Windows WSL) and fails in the production environment (RPI4)

To workaround this bug, I am planning on doing local polling to the device.

TazUk commented 3 years ago

Great news! Thanks! Are you also working on how to get the receiving part working? I use it for remote status checks when internet is not available.

Yes, I am planning on adding support for "polling" to be able to receive incoming SMS. I need to read the dev doc because integrations need to support turning off polling.

Just to check my understanding, is incoming SMS broken in all cases above 2021.6.6?

Most likely, yes. I believe this is a bug in either gammu or Alpine or both, as the same GSM modem works fine in my development environment (Windows WSL) and fails in the production environment (RPI4)

To workaround this bug, I am planning on doing local polling to the device.

Thank you for the clarification and all your efforts on this integration.

ocalvo commented 3 years ago

I have confirmed the fix in my production environment. I can still send SMS messages, however, as expected, receiving SMS seems to broken in this new version. I am working on adding local polling support to gammu to the integration to overcome this problem.

dolenec commented 3 years ago

So if I understand correctly - if I update from version 2021.6.6 to 2021.8.3 sending SMS will work with the current (same) configuration, only receiving SMS will not work?

ocalvo commented 3 years ago

Correct.

dolenec commented 3 years ago

I will try this weekend and will report it back.. thank you..