Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify to Lametric Time #235

Closed
poblabs opened this issue Jun 5, 2020 · 31 comments
Closed

Notify to Lametric Time #235

poblabs opened this issue Jun 5, 2020 · 31 comments

Comments

@poblabs
Copy link

poblabs commented Jun 5, 2020

💡 The Idea
I have a Lametric Time and I'd like to be able to send notifications to it! There's a Python library here which may be able to streamline this feature.

https://github.com/keans/lmnotify

🔨 Breaking Feature
Nope, additional notification group

@caronc
Copy link
Owner

caronc commented Jun 7, 2020

Hey, that looks really neat. It's API also seems pretty cookie-cutter (much like some of the other Notifications services). I should be able to rig something up 👍 .

I don't actually have one of those devices to test with though, so I'll need your help here to test it out once I've got something. Are you okay with this? 🙂

@poblabs
Copy link
Author

poblabs commented Jun 8, 2020

Works for me! I use apprise in docker, so I may need to setup a small dev VM to play around with

@caronc
Copy link
Owner

caronc commented Jun 9, 2020

I reached out to Lametric through email hoping that they can set me up with a developer account with test devices (since I don't own a clock). It would make this process a lot easier.

If they don't get back to me or tell me they can't help me out, I'll use your first link you shared (thank you for that btw) and see if i can figure out how their API works that way. The only problem with the latter is that it's really cumbersome to develop something and keep asking you to try it out (for both of us).

@poblabs
Copy link
Author

poblabs commented Jun 9, 2020

Sounds good. LMK what they say. Otherwise, I'm happy to join the discord and help troubleshoot in as real time as I can if needed.

@caronc
Copy link
Owner

caronc commented Jul 27, 2020

Just letting you know, i realize it's been almost 2 months now; Lametric never responded to my email i sent to them. I will have to mock something up blindly and get you to test it for me unfortunately. There doesn't appear to be another way to do this.

Update: I reached out to Lametric again after this post (here) via another email to them, and they replied to that by setting me up an account in their public help forum. So I'll once again ask there and see if i'll have any luck 🤞

Update 2: I'm making progress; hopefully i'll have something for you to test soon. The confusing thing about Lametric is there appears to be 2 ways to notify the same device. You can either post to the device itself, or your can post a notification to Lametric's upstream developer website.

@caronc
Copy link
Owner

caronc commented Aug 6, 2020

@poblabs I think I've done it.... Here is how you can test it out for me on your clock:

# Create a virtual environment to work in
# This way you can just destroy it after when it's all over.
# The below will create a directory called apprise
python3 -m venv apprise

# Change into our new directory
cd apprise

# Activate our virtual environment
source bin/activate

# Install the branch with the Lametric feature:
pip install git+https://github.com/caronc/apprise.git@lametric-time-support

# Give it a go:
apprise -vv -b "Hello" lametric://{apikey}@{ipaddr_of_device}

# Try different message types if you want:
apprise -n warning -b "Oh No" lametric://{apikey}@{ipaddr_of_device}

# You can customize the message a bit too using the URL
apprise -vv -b "Hello" \
   "lametric://{apikey}@{ipaddr_of_device}?sound=knock&priority=critical&icon_type=alert"

Now I also added Cloud support too which contacts their end to update your clock. You loose out on some features though when you do this (such as priority, sound, and icon_type)

# Cloud messages u
apprise -vv -b "Cloud" "lametric://{client_id}@{client_secret}"

I'm not sure what the message limits are.... like how many characters you can specify in the body. I'm also not sure how new lines are interpreted \r\n... Maybe you could experiment with some of this and report back? Even if you could just let me know that this is working, that would be awesome!

@poblabs
Copy link
Author

poblabs commented Aug 6, 2020 via email

@mattpackwood
Copy link
Contributor

Hi, I have a LaMetric Time and can test...

Getting an error:

apprise -vv -b "Hello" lametric://9a7affc30b22b3e8XXKEYISSECRETXXXXX5ae350fc8c5f98ada@10.0.0.153
        
2020-08-06 10:44:16,030 - ERROR - Unparseable URL lametric://9a7affc30b22b3e8a151XXKEYISSECRETXXXXXae350fc8c5f98ada@10.0.0.153.
2020-08-06 10:44:16,030 - ERROR - You must specify at least one server URL or populated configuration file.
Usage:  [OPTIONS] SERVER_URL [SERVER_URL2 [SERVER_URL3]]

Matt

@caronc
Copy link
Owner

caronc commented Aug 6, 2020

@mattpackwood Thank you so much for joining in! Your help is always appreciated! 👍

You're definitely getting that error because you're not using the apprise found in this branch. You'll need to check out a proprietary branch (see this comment).

If you did do that, then maybe the apprise that already exists on your system is over-riding it? Make sure you properly activate your virtual environment.

@mattpackwood
Copy link
Contributor

Chris, this is what I get (forgive the length):

Matt-Packwoods-iMac:~ $ python3 -m venv apprise
Matt-Packwoods-iMac:~ $ cd apprise
Matt-Packwoods-iMac:apprise $ source bin/activate
(apprise) Matt-Packwoods-iMac:apprise $ pip install git+https://github.com/caronc/apprise.git@lametric-time-support
Collecting git+https://github.com/caronc/apprise.git@lametric-time-support
  Cloning https://github.com/caronc/apprise.git (to revision lametric-time-support) to /private/var/folders/s7/typ53r597p33k6rpcwn9lg_40000gn/T/pip-req-build-v5xeunqs
  Running command git clone -q https://github.com/caronc/apprise.git /private/var/folders/s7/typ53r597p33k6rpcwn9lg_40000gn/T/pip-req-build-v5xeunqs
  Running command git checkout -b lametric-time-support --track origin/lametric-time-support
  Switched to a new branch 'lametric-time-support'
  Branch 'lametric-time-support' set up to track remote branch 'lametric-time-support' from 'origin'.
Collecting requests
  Using cached requests-2.24.0-py2.py3-none-any.whl (61 kB)
Collecting requests-oauthlib
  Using cached requests_oauthlib-1.3.0-py2.py3-none-any.whl (23 kB)
Collecting six
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting click>=5.0
  Using cached click-7.1.2-py2.py3-none-any.whl (82 kB)
Collecting markdown
  Using cached Markdown-3.2.2-py3-none-any.whl (88 kB)
Collecting PyYAML
  Using cached PyYAML-5.3.1.tar.gz (269 kB)
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
  Using cached urllib3-1.25.10-py2.py3-none-any.whl (127 kB)
Collecting chardet<4,>=3.0.2
  Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Collecting idna<3,>=2.5
  Using cached idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2020.6.20-py2.py3-none-any.whl (156 kB)
Collecting oauthlib>=3.0.0
  Using cached oauthlib-3.1.0-py2.py3-none-any.whl (147 kB)
Using legacy setup.py install for apprise, since package 'wheel' is not installed.
Using legacy setup.py install for PyYAML, since package 'wheel' is not installed.
Installing collected packages: urllib3, chardet, idna, certifi, requests, oauthlib, requests-oauthlib, six, click, markdown, PyYAML, apprise
    Running setup.py install for PyYAML ... done
    Running setup.py install for apprise ... done
Successfully installed PyYAML-5.3.1 apprise-0.8.6 certifi-2020.6.20 chardet-3.0.4 click-7.1.2 idna-2.10 markdown-3.2.2 oauthlib-3.1.0 requests-2.24.0 requests-oauthlib-1.3.0 six-1.15.0 urllib3-1.25.10
WARNING: You are using pip version 20.1.1; however, version 20.2.1 is available.
You should consider upgrading via the '/Users/mattpackwood/apprise/bin/python3 -m pip install --upgrade pip' command.
(apprise) Matt-Packwoods-iMac:apprise $ apprise -vv -b "Hello" lametric://9a7affc30b22b3e8a151XXXXXXXX5035ae350fc8c5f98ada@10.0.0.153
2020-08-06 13:20:32,393 - ERROR - Unparseable URL lametric://9a7affc30b22b3e8a151e03XXXXXXXXX2af5035ae350fc8c5f98ada@10.0.0.153.
2020-08-06 13:20:32,393 - ERROR - You must specify at least one server URL or populated configuration file.
Usage:  [OPTIONS] SERVER_URL [SERVER_URL2 [SERVER_URL3]]

  Send a notification to all of the specified servers identified by their
  URLs the content provided within the title, body and notification-type.

  For a list of all of the supported services and information on how to use
  them, check out at https://github.com/caronc/apprise

(apprise) Matt-Packwoods-iMac:apprise $ which apprise
/System/Volumes/Data/Users/mattpackwood/Library/Python/3.8/bin/apprise

@caronc
Copy link
Owner

caronc commented Aug 6, 2020

Thanks @mattpackwood,

I'm stumped on this one, is apprise also installed in your global environment somewhere? My guess is that it is over-ridding your setup. Here is what happens when i repeat the exact commands you did (right to your call to apprise):

[l2g@caronc tmp]$ python3 -m venv apprise
[l2g@caronc tmp]$ 
[l2g@caronc tmp]$ # Change into our new directory
[l2g@caronc tmp]$ cd apprise
[l2g@caronc apprise]$ 
[l2g@caronc apprise]$ # Activate our virtual environment
[l2g@caronc apprise]$ source bin/activate
(apprise) [l2g@caronc apprise]$ 
(apprise) [l2g@caronc apprise]$ # Install the branch with the Lametric feature:
(apprise) [l2g@caronc apprise]$ pip install git+https://github.com/caronc/apprise.git@lametric-time-support
Collecting git+https://github.com/caronc/apprise.git@lametric-time-support
  Cloning https://github.com/caronc/apprise.git (to revision lametric-time-support) to /tmp/pip-req-build-nyc52f53
  Running command git clone -q https://github.com/caronc/apprise.git /tmp/pip-req-build-nyc52f53
  Running command git checkout -b lametric-time-support --track origin/lametric-time-support
  Switched to a new branch 'lametric-time-support'
  Branch 'lametric-time-support' set up to track remote branch 'lametric-time-support' from 'origin'.
Collecting requests (from apprise==0.8.6)
  Downloading https://files.pythonhosted.org/packages/45/1e/0c169c6a5381e241ba7404532c16a21d86ab872c9bed8bdcd4c423954103/requests-2.24.0-py2.py3-none-any.whl (61kB)
     |████████████████████████████████| 71kB 1.1MB/s 
Collecting requests-oauthlib (from apprise==0.8.6)
  Using cached https://files.pythonhosted.org/packages/a3/12/b92740d845ab62ea4edf04d2f4164d82532b5a0b03836d4d4e71c6f3d379/requests_oauthlib-1.3.0-py2.py3-none-any.whl
Collecting six (from apprise==0.8.6)
  Downloading https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl
Collecting click>=5.0 (from apprise==0.8.6)
  Downloading https://files.pythonhosted.org/packages/d2/3d/fa76db83bf75c4f8d338c2fd15c8d33fdd7ad23a9b5e57eb6c5de26b430e/click-7.1.2-py2.py3-none-any.whl (82kB)
     |████████████████████████████████| 92kB 3.0MB/s 
Collecting markdown (from apprise==0.8.6)
  Downloading https://files.pythonhosted.org/packages/a4/63/eaec2bd025ab48c754b55e8819af0f6a69e2b1e187611dd40cbbe101ee7f/Markdown-3.2.2-py3-none-any.whl (88kB)
     |████████████████████████████████| 92kB 2.7MB/s 
Collecting PyYAML (from apprise==0.8.6)
  Using cached https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz
Collecting certifi>=2017.4.17 (from requests->apprise==0.8.6)
  Downloading https://files.pythonhosted.org/packages/5e/c4/6c4fe722df5343c33226f0b4e0bb042e4dc13483228b4718baf286f86d87/certifi-2020.6.20-py2.py3-none-any.whl (156kB)
     |████████████████████████████████| 163kB 3.8MB/s 
Collecting chardet<4,>=3.0.2 (from requests->apprise==0.8.6)
  Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
Collecting idna<3,>=2.5 (from requests->apprise==0.8.6)
  Downloading https://files.pythonhosted.org/packages/a2/38/928ddce2273eaa564f6f50de919327bf3a00f091b5baba8dfa9460f3a8a8/idna-2.10-py2.py3-none-any.whl (58kB)
     |████████████████████████████████| 61kB 4.3MB/s 
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests->apprise==0.8.6)
  Downloading https://files.pythonhosted.org/packages/9f/f0/a391d1463ebb1b233795cabfc0ef38d3db4442339de68f847026199e69d7/urllib3-1.25.10-py2.py3-none-any.whl (127kB)
     |████████████████████████████████| 133kB 3.7MB/s 
Collecting oauthlib>=3.0.0 (from requests-oauthlib->apprise==0.8.6)
  Using cached https://files.pythonhosted.org/packages/05/57/ce2e7a8fa7c0afb54a0581b14a65b56e62b5759dbc98e80627142b8a3704/oauthlib-3.1.0-py2.py3-none-any.whl
Collecting importlib-metadata; python_version < "3.8" (from markdown->apprise==0.8.6)
  Downloading https://files.pythonhosted.org/packages/8e/58/cdea07eb51fc2b906db0968a94700866fc46249bdc75cac23f9d13168929/importlib_metadata-1.7.0-py2.py3-none-any.whl
Collecting zipp>=0.5 (from importlib-metadata; python_version < "3.8"->markdown->apprise==0.8.6)
  Using cached https://files.pythonhosted.org/packages/b2/34/bfcb43cc0ba81f527bc4f40ef41ba2ff4080e047acb0586b56b3d017ace4/zipp-3.1.0-py3-none-any.whl
Installing collected packages: certifi, chardet, idna, urllib3, requests, oauthlib, requests-oauthlib, six, click, zipp, importlib-metadata, markdown, PyYAML, apprise
  Running setup.py install for PyYAML ... done
  Running setup.py install for apprise ... done
Successfully installed PyYAML-5.3.1 apprise-0.8.6 certifi-2020.6.20 chardet-3.0.4 click-7.1.2 idna-2.10 importlib-metadata-1.7.0 markdown-3.2.2 oauthlib-3.1.0 requests-2.24.0 requests-oauthlib-1.3.0 six-1.15.0 urllib3-1.25.10 zipp-3.1.0
WARNING: You are using pip version 19.1.1, however version 20.2.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(apprise) [l2g@caronc apprise]$ which apprise
~/tmp/apprise/bin/apprise
(apprise) [l2g@caronc apprise]$ apprise -vv -b "Hello" lametric://9a7affc30b22b3e8a151XXXXXXXX5035ae350fc8c5f98ada@10.0.0.153
2020-08-06 13:46:42,062 - WARNING - A Connection error occurred sending LaMetric notification to 10.0.0.153.

One command i did that you'll see above (after activation) was this:

# what binary script will i launch if i type the word `apprise`
which apprise
# My response was: ~/tmp/apprise/bin/apprise
# Good! This is the directory (/tmp/apprise) that i created my virtualenv in

Based on your error message you're going to get a different directory path. The connection error i got showed that it parsed 'exactly' what you provided, but since i don't have a clock, i got the expected time.

Thanks for all your help so far though! Keep me posted if you figure it out.

@mattpackwood
Copy link
Contributor

Chris,

I dropped down so I was in:
/Users/mattpackwood/apprise/bin

Then ran:
./apprise -vv -b "Hello" lametric://9a7affc30b22b3e8a151e03XXXXXd1d2af5035ae350fc8c5f98ada@10.0.0.153

And got
2020-08-06 13:53:10,978 - WARNING - A Connection error occurred sending LaMetric notification to 10.0.0.153.

@caronc
Copy link
Owner

caronc commented Aug 6, 2020

Matt,

Perfect! thank you! I think i just fixed that problem. Do a git pull in your activated environment to grab the update (and try again). Alternatively just re-creating the environment will do it too.

Good Luck

Chris

@mattpackwood
Copy link
Contributor

Chris,

It is working, but I get:

2020-08-06 16:22:36,731 - WARNING - Failed to send LaMetric notification: error=201.

In my terminal window

@mattpackwood
Copy link
Contributor

That got it!
2020-08-06 16:51:02,074 - INFO - Sent LaMetric notification.

@caronc
Copy link
Owner

caronc commented Aug 6, 2020

Awesome! We're getting closer! I just pushed another small update that will accept the 201 HTTP response code (as it should). You'll need to do a git pull to grab it.

Would you mind trying different message sizes for me? I'd be curious how big you can make them before it's an issue upstream. Also try running the command as:

# -t introduces a title which will cause 2 lines to be sent upstream
# i'll be curious how LaMetric handles new lines
./apprise -vv -t "title" -b "Hello" lametric://{apitoken}@{device_ip}

Chris

@mattpackwood
Copy link
Contributor

You just get "TITLE HELLO" in the display, it concatenates the text

As for length, I used "This is a test, 1 2 3 4 5 6 7 8 9 10 - Still no end in sight, still typing, hands getting tired, yep this is still not the end, not sure what to type now, can't really think of anything, is it the end, oh actually it is..." with no issue

@caronc
Copy link
Owner

caronc commented Aug 7, 2020

Wiki Page ready to go!

Just adding a few final touches and will merge the code shortly to the master branch.

@caronc
Copy link
Owner

caronc commented Aug 7, 2020

Code merged; closing off issue. Please let me know if any of you have any issues!

@caronc caronc closed this as completed Aug 7, 2020
@poblabs
Copy link
Author

poblabs commented Sep 1, 2020

Works great! I'm wondering if we can use a custom icon? I see there's the defaults listed, but maybe an option to do "custom" then we could do "icon=<prefix>XXX" for a custom icon from their website.

@caronc
Copy link
Owner

caronc commented Sep 1, 2020

That's a great idea. I was going to bundle a new official release today, but i'll do this first so it can be part of it.
I'll stick it i a new ticket though so it's easier to track that way.

@poblabs
Copy link
Author

poblabs commented Sep 1, 2020 via email

@mattpackwood
Copy link
Contributor

@poblabs can you make the web based notifiactions work?

@poblabs
Copy link
Author

poblabs commented Sep 3, 2020

I'm only using local notifications since my Home Assistant is local. Haven't tried the cloud at all. Is it not working for you?

@caronc
Copy link
Owner

caronc commented Sep 3, 2020

@mattpackwood i might have to rebuild the Apprise API for you to get the latest code changes. Does it work from the CLI and just not from the API?

@poblabs
Copy link
Author

poblabs commented Sep 3, 2020

Ah, I am running the Apprise API in a docker container, and I did have to go into the docker container and run a pip upgrade on the apprise package. Not clean by any means but it worked.

@mattpackwood
Copy link
Contributor

I am running on an Ubuntu machine, I just updated to the latest version, still no joy.... @poblabs how do you have your LaMetric API configured?

@poblabs
Copy link
Author

poblabs commented Sep 3, 2020

@mattpackwood I've got it running in a docker container, then curl to send a notification, or use Home Assistant's POST_JSON notify service. The IP of the lametric time is DHCP reserved, and the last URL is the server hosting apprise docker

curl -X POST -d '{"urls":"lametric://{api key from lametrics website}@192.168.0.19:8080/?sound=bicycle&priority=info&icon=7956","body":"Test body content","title":"Test title from apprise"}' -H "Content-Type: application/json" http://192.168.0.60:8090/notify/

@mattpackwood
Copy link
Contributor

@poblabs Sorry, I was being unclear, I can run it locally using:
apprise -vv -b "Test Message Body" lametric://abc123@192.168.1.3

But no luck with Cloud Mode:
apprise -vv -b "Test Message Body" lametric://12:23:45:64@abcdefg==

@caronc
Copy link
Owner

caronc commented Sep 3, 2020

That sucks, you're my first tester for this. I probably wrongfully assumed it would just work. Would your mind sharing with me the output of -vvvvv. You can skew some of the output to protect your credentials

@mattpackwood
Copy link
Contributor

mattpackwood commented Sep 3, 2020

No worries, here you go...

mattpackwood@ubuntu:~$ apprise -vvv -b "Test Message Body" lametric://9403c98d-REDACTED5bd2f@JDEkREDACTED5YVBnMA==
2020-09-03 17:03:29,749 - DEBUG - Loaded LaMetric URL: lametric://9403c98d-REDACTED-246509a5bd2f@JDEka0dTNGdDMREDACTEDN2F5YVBnMA%3D%3D/?mode=cloud&format=text&overflow=upstream&rto=4.0&cto=4.0&verify=yes
2020-09-03 17:03:29,749 - INFO - Notifying 1 service(s) asynchronous.
2020-09-03 17:03:29,749 - DEBUG - Using selector: EpollSelector
2020-09-03 17:03:29,750 - DEBUG - LaMetric POST URL: https://developer.lametric.com/api/v1/dev/widget/update/com.lametric.9403c98d-REDACTED-246509a5bd2f (cert_verify=True)
2020-09-03 17:03:29,750 - DEBUG - LaMetric Payload: {'frames': [{'icon': 'i620', 'text': 'Test Message Body'}]}
2020-09-03 17:03:30,973 - WARNING - Failed to send LaMetric notification: Page not found., error=404.
2020-09-03 17:03:30,974 - DEBUG - Response Details:
b''
mattpackwood@ubuntu:~$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants