AlexandrErohin / home-assistant-tplink-router

Home Assistant component for TP-Link router administration with sensors, button reboot, switches and device tracking.
https://community.home-assistant.io/t/custom-component-tp-link-router-integration
MIT License
137 stars 16 forks source link

Add support to send text messages #85

Closed Momro closed 6 days ago

Momro commented 1 month ago

Hi,

I have a TL-MR100 v2.0. I use a SIM card and the LTE connection of the router as fallback internet. I would like to utilize the SIM card for short text messages, too, but I cannot find an integration that does that.

I was able to connect and send a text message like this:

python
[...]
from tplinkrouterc6u import (
...     TplinkRouterProvider,
...     TplinkRouter,
...     TplinkC1200Router,
...     TPLinkMRClient,
...     TPLinkDecoClient,
...     Connection
... )

router = TplinkRouterProvider.get_client('http://192.168.9.1', 'xxxxx')
router.authorize()
router.send_sms("017987665432", "hallo aus der python console")
router.logout()

This uses https://pypi.org/project/tplinkrouterc6u/#status though, and I was told that you cannot add Python libraries in HAOS, so I'm a bit stuck here.

Any chance you could add this to your integration?

AlexandrErohin commented 1 month ago

This integrations supports many routers but only some of them has sms feature. I don't think it is good to add feature which would be unavailable for most of users You may use this code as individual python script https://www.home-assistant.io/integrations/python_script/

Momro commented 1 month ago

It appears to be not exactly possible to do this in python code because one cannot sideload pip libraries though

Pel1can111 commented 1 month ago

@Momro If you find a solution to achieve this please can you update this. Would be awesome to utilise the sms feature of these routers to send updates/notifications to family/friends that interact with home assistant though physical buttons without setting them up with remote access to HA.

Would also be a great way to fire off critical alerts.

iursevla commented 3 weeks ago

@Momro @Pel1can111 Seems like it is possible with PyScript

I also need this feature (sending SMS) and I'm using Typescript code to do it outside of Home Assistant. Basically, event happens in HA -> HA sends MQTT message to topic -> Typescript code is listening to topic -> sends SMS message

Momro commented 3 weeks ago

@Momro @Pel1can111 Seems like it is possible with PyScript

I also need this feature (sending SMS) and I'm using Typescript code to do it outside of Home Assistant. Basically, event happens in HA -> HA sends MQTT message to topic -> Typescript code is listening to topic -> sends SMS message

But I cannot import said library in HA / I cannot download it. One would maybe have to download the files from pypi manually, upload to HA and import it there... But maybe it would still not be possible depending on the local interpreter of HA

iursevla commented 3 weeks ago

@Momro I saw this video: https://www.youtube.com/watch?v=Kr1rAJnVBrI (at 09:05 for script with imports)

Momro commented 3 weeks ago

@Momro I saw this video: https://www.youtube.com/watch?v=Kr1rAJnVBrI (at 09:05 for script with imports)

Interesting! Relevant part is at 9:45.

Thanks mate!

iursevla commented 2 weeks ago

@Momro any news? Did you try it?

AlexandrErohin commented 1 week ago

Added service for sending SMS message in version 2.2.0. Please try and let me know https://github.com/AlexandrErohin/home-assistant-tplink-router?tab=readme-ov-file#send-sms-only-for-mr-lte-routers P.S. Would be great if you could give a star to the repo :) Thanks

Pel1can111 commented 1 week ago

Thank you! Tested and works perfect, added a star as well!

AlexandrErohin commented 1 week ago

@Pel1can111 What is your router hardware version?

Pel1can111 commented 1 week ago

Firmware: 1.2.0 0.9.1 v0001.0 Build 240718 Rel.53010n Hardware: Archer MR200 v6.0 00000001

Hope that helps

Momro commented 6 days ago

Added service for sending SMS message in version 2.2.0. Please try and let me know https://github.com/AlexandrErohin/home-assistant-tplink-router?tab=readme-ov-file#send-sms-only-for-mr-lte-routers P.S. Would be great if you could give a star to the repo :) Thanks

I found out that your example in the readme is incorrect. This is how it has to look like:

action: tplink_router.send_sms
data:
  number: "+1234567890"
  text: Hello World
  device: 5afce1e27272cb7d997cbe4220891a2d

I did't know where to get the device ID from. Maybe others will find it helpful if you mentioned that you can get the ID from the URL when you visit the device page :-)

Momro commented 6 days ago

Anyway, thank you so much! Great work, truly helpful!

Pel1can111 commented 6 days ago

Curious question (I really don't want to come accross as ungrateful for adding this functionality) but firstly would it be very hard to add the last SMS recieved as a sensor? One for the senders number and another for the message?

Mostly curious if this would even be possible and would it useful or crazy?! Seems like an intersting idea to have the ability to trigger an automation by SMS but not sure if its just my mind running a bit too far with this!!

Momro commented 6 days ago

Interesting idea, but best to open a new issue because it is a separate topic 😉