YAML:
alias: NFC webhook test
description: ""
trigger:
- platform: webhook
allowed_methods:
- POST
- PUT
- GET
local_only: false
webhook_id: test1234
condition: []
action:
- service: notify.mobile_app_pixel
metadata: {}
data:
message: webhook test
data:
ttl: 0
priority: high
mode: single
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Trigger Webhook</title>
</head>
<body>
<h1>Trigger Webhook</h1>
<script>
// Function to trigger the webhook and then close the window
function triggerWebhookAndClose() {
fetch('https://homeassistant/api/webhook/test1234')
.then(response => {
if (response.ok) {
console.log('Success:', response.statusText);
alert('Webhook triggered successfully!');
} else {
console.error('Error:', response.statusText);
alert('Failed to trigger webhook: ' + response.statusText);
}
// Close the window after triggering the webhook
window.close();
})
.catch(error => {
console.error('Error:', error);
alert('Failed to trigger webhook: ' + error.message);
// Close the window in case of error (optional)
window.close();
});
}
// Trigger the function as soon as the page loads
triggerWebhookAndClose();
</script>
</body>
</html>