This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
Speech by PHP CURL
Michiel145
Member
Hi there,
I'm playing around with the web-api and I'm able to readout devices, switch devices, but I cant seem to make Homey speak by CURL GET and PUT.
Is there a way to do this?
I see some topics where they say it should work so PUT to http://HOMEYIP/api/manager/speech-output/, but is does not work.
The error I get is "{"status":404,"result":"not_found"}".
When trying to PUT to /manager/speech-output/, I get "Cannot PUT /manager/speech-output/".
Thanks!
Some example PHP code
I'm playing around with the web-api and I'm able to readout devices, switch devices, but I cant seem to make Homey speak by CURL GET and PUT.
Is there a way to do this?
I see some topics where they say it should work so PUT to http://HOMEYIP/api/manager/speech-output/, but is does not work.
The error I get is "{"status":404,"result":"not_found"}".
When trying to PUT to /manager/speech-output/, I get "Cannot PUT /manager/speech-output/".
Thanks!
Some example PHP code
function speech_output($text){
$apiUrl = 'http://'.HOMEY_IP.'/manager/speech-output/';
$data = array("text" => $text);
$data_json = json_encode($data);
$curl = curl_init($apiUrl);
$headers = array(
'Authorization: Bearer '.HOMEY_TOKEN,
'Content-Type: application/json',
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
$json = curl_exec($curl);
echo $json;
$arr_data = (json_decode($json, true));
if($arr_data[status] <> "200"){
return false;
}else{
return true;
}
}
Comments
The problem is that you're making a PUT request instead of a POST request .
The following should work:
$text = 'Hello, world!'; $curl = curl_init('http://YOUR-HOMEY-IP/api/manager/speech-output/'); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode(['text' => $text])); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Authorization: Bearer YOUR-BEARER-TOKEN', ]); $result = curl_exec($curl); var_dump($result);
i didn't because the api changed too much (when i was working on it), and might still change a little
plus i think you are the second one (i know of) that works with PHP for homey, the rest works mostly with javascript (and modules)
even though i also started in PHP, i switched to javascript (ajax) since that was easier to do anything without having to refresh pages, making the pages more dynamic with showing information
The thing i don't get (and am looking for) is to "Send" text to Homey, who will pick this up as if it was spoken,
changing the URL in the above script form "speech-output" to "speech-input" did not work for some reason..
It shows : "{"status":500,"result":"invalid_transcript"}"
-= edit =-
sorted, though more testing is needed, in the above code change
<code>
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode(['text' => $text]));
</code>
to
<code>
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode(['transcript' => $text]));
</code>
(obviously also change the URL to speech-input)
Now I can finally use Autovoice to control Homey
-=edit2 =-
Dear lord, this works really well ..