I have a wakeup routine that tells me the 1st calendar item of the day. my voicemail plays the latest news and then music starts.
I can collect all calendar items of the day with the service call. But i cant get it to work in a rest api. error 500 I have a remote script building up a playlist with all the items needed to played for the wakeup routine.
Does someone has a working example i can use?
#!/usr/bin/php
<?php
include("/opt/sascha/common.php");
// Define the service data
$service_data = array(
'start_date_time' => date('2024-04-20 00:00:00'),
'end_date_time' => date('2024-05-30 23:59:59'),
'target' => array(
'entity_id' => array(
'calendar.persoonlijk',
'calendar.verjaardagen',
'calendar.feestdagen_in_nederland'
)
),
'response_mode' => 'queued'
);
// Convert service data to JSON
$service_data_json = json_encode($service_data);
// Define the headers
$headers = array(
'Authorization: Bearer ' . $sHomeApiKey,
'Content-Type: application/json'
);
// Make the POST request
$ch = curl_init($sHomeApiUrl . '/api/services/calendar/get_events');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $service_data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute the request
$response = curl_exec($ch);
// Check for errors
if(curl_errno($ch)){
echo 'Error: ' . curl_error($ch);
}
// Close the request
curl_close($ch);
// Output the response
echo $response;
?>