<?php
require 'TuyaCloud.php';

// ATTENTION: it seems you have to keep "33" for the countryCode and "eu" for the region, wherever you are…
//            -> see this comment: https://github.com/Aymkdn/tuyacloud-php/issues/9#issuecomment-1144097955
$tuya = new TuyaCloud([
  "userName" => "pkuba04@wp.pl", // username/email to access to SmartLife/Tuya app
  "password" => "#Hyzne967", // password to access to SmartLife/Tuya app
  "bizType" => "smart_life", // type ('tuya' or 'smart_life')
  "countryCode" => "48", // Country code (International dialing number), e.g. "33" for France or "1" for USA
  "region" => "eu" // region (az=Americas, ay=Asia, eu=Europe)
]);

// to get a list of your devices
$devices = $tuya->getDevices();
foreach($devices as $device) {
  echo "Name: ".$device->name."<br>";
  echo "ID: ".$device->id."<br>";
  echo "Type: ".$device->dev_type."<br>";
  if ($device->dev_type !== "scene") {
    echo "State: ".$device->data->state."<br>";
    echo "Online: ".$device->data->online."<br><br>";
  }
}

// to get the state of a device
// echo "State Switch 1 => ".$tuya->setState([
//   "id" => "bf10ca289ddf46ccdaap5l",
//   "value" => "on"
// ]);

?>