Integration with ntfy

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Integration with ntfy

#1 Post by budman1758 » 01 Jan 2023, 20:56

I recently came across this project and think its a great solution for sending notifications to a phone from ESPEasy.

Code: Select all

https://docs.ntfy.sh/
I have been attempting to send a message via ESPEasy from command line and can't seem to get it to work. Is it possible and if so could someone help me with formatting a command to send? Or, if not possible can it be made to?

Happy New Year to all!!
"The glass is twice as big as it needs to be".

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Integration with ntfy

#2 Post by Ath » 01 Jan 2023, 21:39

Hi there, and a happy new year 8-)

The main issue is that those services all require a HTTPS connection, but that's a) not supported by ESPEasy (yet) and b) the currently planned HTTPS support only touches the MQTT controllers #3788 and ESP32-only (because of resource limitations on ESP8266)
/Ton (PayPal.me)

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Integration with ntfy

#3 Post by budman1758 » 01 Jan 2023, 21:57

Pretty sure HTTPS is NOT required to post an http message. I have a self-hosted server instance of this and it will work either way
Attachments
ntfypost.png
ntfypost.png (28.93 KiB) Viewed 8434 times
"The glass is twice as big as it needs to be".

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Integration with ntfy

#4 Post by chromo23 » 02 Jan 2023, 13:30

Most of my devices send sensor data to thingspeak via rules.
I don’t know if it helps but my code looks like this:

Code: Select all

SendToHTTP,api.thingspeak.com,80,/update?api_key=********************&field7=[RelayXX#btnState]

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Integration with ntfy

#5 Post by Ath » 02 Jan 2023, 13:58

The example image shows a POST request, but not sure if we can do anything else than a GET using SendToHTTP from ESPEasy...
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Integration with ntfy

#6 Post by TD-er » 02 Jan 2023, 14:00

Advanced HTTP controller should be able to do some POST

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Integration with ntfy

#7 Post by chromo23 » 02 Jan 2023, 14:04

It seems, that GET requests are beeing redirected to https:
https://docs.ntfy.sh/config/#nginxapache2caddy
Bildschirmfoto 2023-01-02 um 14.02.43.png
Bildschirmfoto 2023-01-02 um 14.02.43.png (18.53 KiB) Viewed 8404 times

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Integration with ntfy

#8 Post by Ath » 02 Jan 2023, 15:26

chromo23 wrote: 02 Jan 2023, 14:04 It seems, that GET requests are beeing redirected to https:
https://docs.ntfy.sh/config/#nginxapache2caddy

Bildschirmfoto 2023-01-02 um 14.02.43.png
That's usually 'caused' by your browser, as they insist on using https, but the (external) website is most likely only HTTPS enabled (with redirect from HTTP), while the self-hosted software can be configured to accept HTTP ;)
/Ton (PayPal.me)

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Integration with ntfy

#9 Post by chromo23 » 02 Jan 2023, 15:59

Ath wrote: 02 Jan 2023, 15:26 while the self-hosted software can be configured to accept HTTP
Of course, if you host your own ntfy server you can remove the GET redirect in the config as described here:

Then it should work with ESPeasy i guess

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Integration with ntfy

#10 Post by chromo23 » 02 Jan 2023, 16:18

TD-er wrote: 02 Jan 2023, 14:00 Advanced HTTP controller should be able to do some POST
This works fine by the way but is maybe not the right choice since you cannot put custom text messages in the body?!

Edit: My sentence is misleading since you can put custom text messages in the body but they will be send every time a device triggers the controller. The main issue is more, that you can not use it in rules like SendToHTTP and therefore can not choose which text is send.

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Integration with ntfy

#11 Post by budman1758 » 03 Jan 2023, 01:16

The main issue is more, that you can not use it in rules like SendToHTTP and therefore can not choose which text is send.
In an ideal world that would be the best way to be able to use it. Hint, hint, nudge, nudge. :D :D
"The glass is twice as big as it needs to be".

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Integration with ntfy

#12 Post by TD-er » 03 Jan 2023, 01:23

Yep, sounds like it would be ideal indeed.
Maybe it would even be called like "PostToHTTP" or something like that.

But we still need stuff to dream about, right?
I guess I will be doing that right now... starting dreaming :)

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Integration with ntfy

#13 Post by chromo23 » 16 Jan 2023, 18:32

budman1758 wrote: 03 Jan 2023, 01:16 In an ideal world that would be the best way to be able to use it
seems like somebody made it happen and needs people to test it. :)
https://github.com/letscontrolit/ESPEasy/pull/4465

An example for ntfy:

Code: Select all

PostToHTTP ntfy.sh,80,test?title=%sysname%,,%eventvalue%  
(Note the two commas with nothing in between. That is the header section which you can leave empty.)

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Integration with ntfy

#14 Post by budman1758 » 16 Jan 2023, 21:25

seems like somebody made it happen and needs people to test it. :)
Great! Will give it a go. Need a day or 3 to actually get some time to set up a unit and test.
"The glass is twice as big as it needs to be".

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Integration with ntfy

#15 Post by budman1758 » 18 Jan 2023, 01:45

seems like somebody made it happen and needs people to test it. :)
Tested and from what I can see, seems to be working fine!
"The glass is twice as big as it needs to be".

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Integration with ntfy

#16 Post by budman1758 » 27 Jan 2023, 20:16

Well. I don't know why but for some reason I can't get my test unit to post from a rule. The message works fine from command line but the rule does not. This command works fine from the tools page...

Code: Select all

PostToHTTP 192.168.1.58,80,meds?title=%sysname%,,'Its %sysweekday_s% @ %systm_hm_am% Did you take your meds yet?. If not then get off your butt and take them!!'
Message comes thru loud and clear. :lol: :lol:

This does not...

Code: Select all

On Clock#Time=all,10:50 Do
PostToHTTP 192.168.1.58,80,meds?title=%sysname%,,'Its %sysweekday_s% @ %systm_hm_am% Did you take your meds yet?. If not then get off your butt and take them!!'
Endon
Nothing in the log at all at the target time. Its almost like the clock#time trigger is not working. Screenshot of the build I'm using.
Attachments
Build data.png
Build data.png (22.13 KiB) Viewed 7910 times
"The glass is twice as big as it needs to be".

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Integration with ntfy

#17 Post by chromo23 » 27 Jan 2023, 20:42

can you try:

Code: Select all

On Clock#Time=all,10:50 Do
PostToHTTP 192.168.1.58,80,meds,title:%sysname%,'Its %sysweekday_s% @ %systm_hm_am% Did you take your meds yet?. If not then get off your butt and take them!!'
Endon
it is the more correct syntax… as provided in the documentation.

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Integration with ntfy

#18 Post by budman1758 » 27 Jan 2023, 21:19

chromo23 wrote: 27 Jan 2023, 20:42 can you try:

Code: Select all

On Clock#Time=all,10:50 Do
PostToHTTP 192.168.1.58,80,meds,title:%sysname%,'Its %sysweekday_s% @ %systm_hm_am% Did you take your meds yet?. If not then get off your butt and take them!!'
Endon
it is the more correct syntax… as provided in the documentation.
Still no workie. Nothing in the log except the standard "Event clock#time=bla bla

EDIT: Set the log level to debug and this shows up.
Log debug.png
Log debug.png (24.79 KiB) Viewed 7900 times
Last edited by budman1758 on 27 Jan 2023, 21:26, edited 1 time in total.
"The glass is twice as big as it needs to be".

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Integration with ntfy

#19 Post by chromo23 » 27 Jan 2023, 21:26

can you replace the space after „posttohttp“ with a „,“ as in posttohttp,192….

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Integration with ntfy

#20 Post by Ath » 27 Jan 2023, 21:27

You might want to use "on Clock#Time=all,**:** do" to trigger every minute, if only for testing and looking at the logs
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Integration with ntfy

#21 Post by Ath » 27 Jan 2023, 21:30

Seeing that conditionMatchExtended log responding to the "if" in the message seems a bit weird, possibly related to a (bad) quoting issue

Edit:
Does the %sysname% have commas, spaces or quotes?
/Ton (PayPal.me)

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Integration with ntfy

#22 Post by budman1758 » 27 Jan 2023, 21:36

Ath wrote: 27 Jan 2023, 21:30 Seeing that conditionMatchExtended log responding to the "if" in the message seems a bit weird, possibly related to a (bad) quoting issue

Edit:
Does the %sysname% have commas, spaces or quotes?
System name is ESP_Easy_ntfy
Put double quotes instead of single around the "message" part of the line. Made no difference as far as I can tell.
"The glass is twice as big as it needs to be".

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Integration with ntfy

#23 Post by Ath » 27 Jan 2023, 21:40

You could add quotes around the "title:%sysname%" part, to ensure it's seen as 1 part for PostToHTTP to digest.
/Ton (PayPal.me)

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Integration with ntfy

#24 Post by budman1758 » 27 Jan 2023, 21:50

Ath wrote: 27 Jan 2023, 21:40 You could add quotes around the "title:%sysname%" part, to ensure it's seen as 1 part for PostToHTTP to digest.
Like this? This command gets the same thing. No workie.

Code: Select all

PostToHTTP 192.168.1.58,80,meds,"title:%sysname%","Its %sysweekday_s% %systm_hm_am% Did you take your meds yet. If not then get off your butt and take them!!"
log debug 2.png
log debug 2.png (26.08 KiB) Viewed 7888 times
"The glass is twice as big as it needs to be".

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Integration with ntfy

#25 Post by Ath » 27 Jan 2023, 21:51

Taking the "If" out of the message seems to fix it, that's surely something to investigate... :shock:
/Ton (PayPal.me)

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Integration with ntfy

#26 Post by budman1758 » 27 Jan 2023, 22:00

Ath wrote: 27 Jan 2023, 21:51 Taking the "If" out of the message seems to fix it, that's surely something to investigate... :shock:
You nailed it! Took the "if" out of the statement and it works.
Time to start investigating..... :lol: :lol:
"The glass is twice as big as it needs to be".

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Integration with ntfy

#27 Post by Ath » 27 Jan 2023, 22:35

I've created a pull request #4486 to fix this issue. Would have been the same for "elseif " but that's much less likely to be used in any text, other than code :lol:

@budman1578
Thanks for helping find this, somewhat obscure, issue. I expect to have fixed it now.
Last edited by Ath on 27 Jan 2023, 22:38, edited 1 time in total.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Integration with ntfy

#28 Post by TD-er » 27 Jan 2023, 22:35

budman1758 wrote: 27 Jan 2023, 22:00
Ath wrote: 27 Jan 2023, 21:51 Taking the "If" out of the message seems to fix it, that's surely something to investigate... :shock:
You nailed it! Took the "if" out of the statement and it works.
Time to start investigating..... :lol: :lol:
Nope, time to start testing as he already made a pull request for it....
https://github.com/letscontrolit/ESPEasy/pull/4486

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Integration with ntfy

#29 Post by budman1758 » 28 Jan 2023, 06:21

TD-er wrote: 27 Jan 2023, 22:35 Nope, time to start testing as he already made a pull request for it....
https://github.com/letscontrolit/ESPEasy/pull/4486
Yessir!! Getting right on it!! :geek: :geek:

Tested with the "if" back in the statement and by golly it works! Seems another dragon has met its match. :lol: :lol:
"The glass is twice as big as it needs to be".

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Integration with ntfy

#30 Post by budman1758 » 31 Jan 2023, 06:16

How difficult would this be.........?
I have an idea growing in my head that goes like this.
Store plain text messages on the file system of the esp. Arrange them like message1, message 2 ect.
The message could be just about anything....
From rules when you want a particular message sent you make the rule like...

Code: Select all

On what#ever do
Postohttp bla bla bla "message 2"
endon
This way you could have a lot of different message possibilities without maxing out the rules storage and/or complexity.
Not sure what the file storage capacity is but methinks this would make message and notification sending quite a bit easier.
Should I spray some weed killer on my head or is this something thats possible without a major re-write of ESPEasy?
"The glass is twice as big as it needs to be".

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Integration with ntfy

#31 Post by TD-er » 31 Jan 2023, 08:25

No need for the weed killer :)

However you might need to flex your brains a bit as you need to wrap it around some slightly other concept of eventvalues :)

Code: Select all

On what#ever do
  asyncevent,message=1
endon

On foo#bar=1 do
  asyncevent,message=%eventvalue1%
endon

On message do
  if %eventvalue1%=1
    Postohttp bla bla bla "message 1"  
  elseif %eventvalue1%=2
    Postohttp bla bla bla "message 2"
  endif
endon
You can also (added recently) have strings as eventvalues, however you may need to have them not as the first eventvalue.
See: https://espeasy.readthedocs.io/en/lates ... eventvalue

Another nice option can be to use wildcards and part of the event as your message. (%eventname% and %eventpar%)
See: https://espeasy.readthedocs.io/en/lates ... l#examples

However an eventname or eventpar cannot have spaces.

Oh and about the rules file length...
That's currently more of an advice, no longer a true limit anymore.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Integration with ntfy

#32 Post by Ath » 31 Jan 2023, 08:32

Not really a wild thought, I'm thinking in the line of:

Code: Select all

PostToHTTP,<ip>,<port>,<url>,[<header:value>],@<filename>
in the good old tradition of referencing a file via the @ character ;)

I'll see if that's doable within reasonable code size
/Ton (PayPal.me)

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Integration with ntfy

#33 Post by budman1758 » 31 Jan 2023, 19:21

Ath wrote: 31 Jan 2023, 08:32 Not really a wild thought, I'm thinking in the line of:

Code: Select all

PostToHTTP,<ip>,<port>,<url>,[<header:value>],@<filename>
in the good old tradition of referencing a file via the @ character ;)

I'll see if that's doable within reasonable code size
Cool. Sounds good. Meanwhile I will try to wrap my brain around those rule examples.
"The glass is twice as big as it needs to be".

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests