Yesterday I got this awesome LaMetric clock for my birthday. It opens a whole new era on how you can use clocks by adding them to your smarthouse. Since I couldn’t find a PHP ‘Hello World!’ script I decided to built my own, maybe it can help you too.

Follow these three steps to get the data you need:

  1. Create a ‘Notification App’ on https://developer.lametric.com/
  2. Get your API key at https://developer.lametric.com/user/devices
  3. Find the IP address of your LaMetric clock, help can be found here: https://lametric-documentation.readthedocs.io/en/latest/guides/first-steps/first-local-notification.html
<?php

// start program
echo "Sending 'Hello World' to your LaMetric Clock...";

// message
$message = "Hello World!";

// settings
$header  = array("Content-Type: application/json");
$apikey  = "**************************************";
$url     = "http://xxx.xxx.xxx.xxx:8080/api/v2/device/notifications";

$post    = '{
   "model": {
        "frames": [
            {
               "icon":2867,
               "text":"' . $message . '"
            }
        ]
    }
}';

// curl
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERPWD, "dev:" . $apikey);  
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// execute
$response = curl_exec($ch);
if (strpos($response, "success") !== false) {
  echo 'Success!';
} else {
  echo 'Failed!';
}

// close
curl_close($ch);

?>