sparvy
(SSIO)
July 8, 2024, 12:56pm
1
Using these infos, I’m trying to send some parameters via POST.
I put this code into configuration.yaml:
rest_command:
telegram_notify_door:
url: "https://webhooks.site.com/home_assistant.php"
method: POST
content_type: "application/x-www-form-urlencoded"
payload: "auth=hash&door={{ door }}&status={{ status }}"
And the action:
action:
- service: rest_command.telegram_notify_door
data:
door: "{{ trigger.to_state.name }}"
status: "{{ 'OPEN' if trigger.to_state.state == 'on' else 'CLOSED' }}"
But online I didn’t see any call.
Any ideas?
francisp
(Francis)
July 8, 2024, 1:39pm
2
Title is misleading. Seems about telegram, not SNZP-06
Before we begin…
This forum is not a helpdesk
The people here don’t work for Home Assistant, that’s an open source project. We are volunteering our free time to help others. Not all topics may get an answer, never mind one that helps you solve your problem.
[image]
This also isn’t a general home automation forum, this is a forum for Home Assistant and things related to it. Any question about Home Assistant, and about using things with Home Assistant, is welcome here. We can’t help you with eve…
sparvy
(SSIO)
July 8, 2024, 1:41pm
3
@francisp ops sorry.
has anyone ever tried to use rest_command with a POST method?
Troon
(Troon)
July 9, 2024, 6:27pm
4
Your payload looks like a GET query-style payload. Should that be in the URL?
I would expect a POST payload to look like a dictionary. See this example:
sparvy
(SSIO)
July 10, 2024, 5:00am
5
do you mean that it must always be in json format?
Troon
(Troon)
July 10, 2024, 6:30am
6
What is the endpoint of your POST request expecting?
sparvy
(SSIO)
July 10, 2024, 7:30am
7
I’m just debugging using this code
debug("--- ".date("Y-m-d H:i:s")." ----------------------\n");
debug("\$_GET: ".print_r($_GET, 1)."\n\n");
debug("\$_POST: ".print_r($_POST, 1)."\n\n");
debug("\$_FILES: ".print_r($_FILES, 1)."\n\n");
the debug function
// print debug
function debug($msg) {
$fd = fopen(__DIR__."/debug.log", "a");
fwrite($fd, $msg);
fclose($fd);
}
so I can read via terminal using tail -f debug.log
Using this conf
rest_command:
telegram_notify_door:
url: "https://webhooks.site.com/home_assistant.php?gvar=aaa"
method: POST
payload: 'pvar=bbb'
I can see the $_GET var but $_POST is empty.
--- 2024-07-10 06:34:40 ----------------------
$_GET: Array
(
[gvar] => aaa
)
$_POST: Array
(
)
$_FILES: Array
(
)
Using json doesn’t make any differences.
Troon
(Troon)
July 10, 2024, 7:37am
8
Have you validated your PHP script using e.g. curl
ensure $_POST
is working? I assume you’re substituting your real domain name into the url
.
sparvy
(SSIO)
July 10, 2024, 7:44am
9
no problems using curl
curl -X POST -d "pvar=bbb" https://webhooks.site.com/home_assistant.php?gvar=aaa
debug.log
--- 2024-07-10 07:43:06 ----------------------
$_GET: Array
(
[gvar] => aaa
)
$_POST: Array
(
[pvar] => bbb
)
$_FILES: Array
(
)
sparvy
(SSIO)
July 10, 2024, 8:18am
10
It’s ridiculous… even if I copy/paste the example code from the home assistant documentation, it doesn’t work.
I thinking the post method does not work at all.