Page 1 of 1
Integration with ntfy
Posted: 01 Jan 2023, 20:56
by budman1758
I recently came across this project and think its a great solution for sending notifications to a phone from ESPEasy.
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!!
Re: Integration with ntfy
Posted: 01 Jan 2023, 21:39
by Ath
Hi there, and a happy new year
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)
Re: Integration with ntfy
Posted: 01 Jan 2023, 21:57
by budman1758
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
Re: Integration with ntfy
Posted: 02 Jan 2023, 13:30
by chromo23
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]
Re: Integration with ntfy
Posted: 02 Jan 2023, 13:58
by Ath
The example image shows a POST request, but not sure if we can do anything else than a GET using SendToHTTP from ESPEasy...
Re: Integration with ntfy
Posted: 02 Jan 2023, 14:00
by TD-er
Advanced HTTP controller should be able to do some POST
Re: Integration with ntfy
Posted: 02 Jan 2023, 14:04
by chromo23
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 (18.53 KiB) Viewed 24687 times
Re: Integration with ntfy
Posted: 02 Jan 2023, 15:26
by Ath
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

Re: Integration with ntfy
Posted: 02 Jan 2023, 15:59
by chromo23
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
Re: Integration with ntfy
Posted: 02 Jan 2023, 16:18
by chromo23
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.
Re: Integration with ntfy
Posted: 03 Jan 2023, 01:16
by budman1758
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.

Re: Integration with ntfy
Posted: 03 Jan 2023, 01:23
by TD-er
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

Re: Integration with ntfy
Posted: 16 Jan 2023, 18:32
by chromo23
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.)
Re: Integration with ntfy
Posted: 16 Jan 2023, 21:25
by budman1758
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.
Re: Integration with ntfy
Posted: 18 Jan 2023, 01:45
by budman1758
seems like somebody made it happen and needs people to test it.

Tested and from what I can see, seems to be working fine!
Re: Integration with ntfy
Posted: 27 Jan 2023, 20:16
by budman1758
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.
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.
Re: Integration with ntfy
Posted: 27 Jan 2023, 20:42
by chromo23
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.
Re: Integration with ntfy
Posted: 27 Jan 2023, 21:19
by budman1758
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 (24.79 KiB) Viewed 24183 times
Re: Integration with ntfy
Posted: 27 Jan 2023, 21:26
by chromo23
can you replace the space after „posttohttp“ with a „,“ as in posttohttp,192….
Re: Integration with ntfy
Posted: 27 Jan 2023, 21:27
by Ath
You might want to use "on Clock#Time=all,**:** do" to trigger every minute, if only for testing and looking at the logs
Re: Integration with ntfy
Posted: 27 Jan 2023, 21:30
by Ath
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?
Re: Integration with ntfy
Posted: 27 Jan 2023, 21:36
by budman1758
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.
Re: Integration with ntfy
Posted: 27 Jan 2023, 21:40
by Ath
You could add quotes around the "title:%sysname%" part, to ensure it's seen as 1 part for PostToHTTP to digest.
Re: Integration with ntfy
Posted: 27 Jan 2023, 21:50
by budman1758
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 (26.08 KiB) Viewed 24171 times
Re: Integration with ntfy
Posted: 27 Jan 2023, 21:51
by Ath
Taking the "If" out of the message seems to fix it, that's surely something to investigate...

Re: Integration with ntfy
Posted: 27 Jan 2023, 22:00
by budman1758
Ath wrote: ↑27 Jan 2023, 21:51
Taking the "If" out of the message seems to fix it, that's surely something to investigate...
You nailed it! Took the "if" out of the statement and it works.
Time to start investigating.....

Re: Integration with ntfy
Posted: 27 Jan 2023, 22:35
by Ath
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
@budman1578
Thanks for helping find this, somewhat obscure, issue. I expect to have fixed it now.
Re: Integration with ntfy
Posted: 27 Jan 2023, 22:35
by TD-er
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...
You nailed it! Took the "if" out of the statement and it works.
Time to start investigating.....
Nope, time to start testing as he already made a pull request for it....
https://github.com/letscontrolit/ESPEasy/pull/4486
Re: Integration with ntfy
Posted: 28 Jan 2023, 06:21
by budman1758
Re: Integration with ntfy
Posted: 31 Jan 2023, 06:16
by budman1758
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?
Re: Integration with ntfy
Posted: 31 Jan 2023, 08:25
by TD-er
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.
Re: Integration with ntfy
Posted: 31 Jan 2023, 08:32
by Ath
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
Re: Integration with ntfy
Posted: 31 Jan 2023, 19:21
by budman1758
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.