Hey guys,
so, I’ve got an OpenHAB server running that connects to my Sonos Play.
It works pretty well and is also available via my.openhab.
The sound is pretty amazing, unfortunately my neighbors (all students sigh) do not like me partying late at night.
Until now they always used to complain via Whatsapp, until I setup a simple HTML page, where they can turn my music volume down to 50% remotely.
That’s pretty cool, so I’ve thought about publishing the currently playing track, album and artist on the page. (That way they know what beautiful melody interrupted their sleep)
So, I’m a total beginner in web development, that’s why I’m asking:
How do I display the result of a specific openhab REST call on a html page?
I’ve got the following PHP:
<?php
function getStatus($item)
{
$url = "https://my.openhab.org:443/rest/items/" . $item;
$options = array(
'http' => array(
'header' => "Content-type: text/plain\r\n",
'method' => 'GET',
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
getStatus("Title");
?>
When I run this request in postman, I’m getting a proper result:
{
"link": "https://my.openhab.org/rest/items/Title",
"state": "Giles",
"type": "String",
"name": "Title",
"tags": [],
"groupNames": []
}
So, question is how do I get this “state” result into - say a HTML Tag?
I know this might be trivial, but I’m such a noob when it comes to php and html