Du coup, j’ai découvert le bloc code, et voici ce que ca a donné pour la postérité (ca ne peut pas fonctionner en l’état pour quelqu’un d’autres, mais peut-être que ca peut donner des idées) :
$consigneSolaire = cmd::byId(1737)->execCmd();
$energie = -cmd::byId(19)->execCmd();
$scenario->setLog("Energie disponible ".$energie);
$scenario->setLog("Refresh Energie disponible");
cmd::byId(22)->execCmd();
sleep(20);
$energie = -cmd::byId(19)->execCmd();
$scenario->setLog("Energie disponible ".$energie);
$thermostats = array(
"Ami" => array("name"=>"Ami","consigneId"=> 752, "temperatureId" => 753, "reglageId" => 772, "homeId" => 774, "modeTechId" => 754,"conso"=>900),
"Albane" => array("name"=>"Albane","consigneId"=> 776, "temperatureId" => 777, "reglageId" => 796, "homeId" => 798, "modeTechId" => 778,"conso"=>900),
"Olympe" => array("name"=>"Olympe","consigneId"=> 800, "temperatureId" => 801, "reglageId" => 820, "homeId" => 822, "modeTechId" => 802,"conso"=>1200),
"Parents" => array("name"=>"Parents","consigneId"=> 824, "temperatureId" => 825, "reglageId" => 844, "homeId" => 846, "modeTechId" => 826,"conso"=>1800),
"Séjour" => array("name"=>"Séjour","consigneId"=> 704, "temperatureId" => 705, "reglageId" => 724, "homeId" => 726, "modeTechId" => 706,"conso"=>5000),
"Couloir" => array("name"=>"Couloir","consigneId"=> 728, "temperatureId" => 729, "reglageId" => 748, "homeId" => 750, "modeTechId" => 730,"conso"=>250),
"Cuisine" => array("name"=>"Cuisine","consigneId"=> 680, "temperatureId" => 681, "reglageId" => 700, "homeId" => 702, "modeTechId" => 682,"conso"=>3450),
"Sdb" => array("name"=>"Sdb","consigneId"=> 848, "temperatureId" => 849, "reglageId" => 868, "homeId" => 870, "modeTechId" => 850,"conso"=>400), //todo
"Toilettes" => array("name"=>"Toilettes","consigneId"=> 1025, "temperatureId" => 1026, "reglageId" => 1045, "homeId" => 1047, "modeTechId" => 1027,"conso"=>200), //todo
);
// Collecte d'information et extinction thermostats qui ont atteint la consigne
foreach($thermostats as $key => $thermostat) {
$thermostat["temperature"] = cmd::byId($thermostat["temperatureId"])->execCmd();
$thermostat["mode"] = cmd::byId($thermostat["modeTechId"])->execCmd();
if ($thermostat["temperature"] < $consigneSolaire) {
$thermostat["shouldForce"] = true;
}
// Eteint allumage précédent, température atteinte
if ($thermostat["temperature"] > $consigneSolaire && $thermostat["mode"] == "manual") {
cmd::byId($thermostat["homeId"])->execCmd();
$scenario->setLog("Extinction ".$thermostat["name"]);
$thermostat["mode"] = "schedule";
$energie += $thermostat["conso"];
}
if ($thermostat["mode"] == "manual") {
$scenario->setLog("Chauffe en cours ".$thermostat["name"]);
}
$thermostats[$key] = $thermostat;
}
// Vérification des thermostats à eteindre si la production solaire a baissé
function cmpconso($a, $b)
{
if ($a["conso"] == $b["conso"]) {
return 0;
}
return ($a["conso"] > $b["conso"]) ? -1 : 1;
}
usort($thermostats, "cmpconso");
foreach($thermostats as $key => $thermostat) {
// Extinction, si pas assez d'energie
if ($energie < 0 && $thermostat["mode"] == "manual") {
cmd::byId($thermostat["homeId"])->execCmd();
$energie += $thermostat["conso"];
$scenario->setLog("Extinction (energy low) ".$thermostat["name"]);
}
}
// Vérification des thermostats à allumer si la production solaire a augmenté
function cmp($a, $b)
{
if ($a["temperature"] == $b["temperature"]) {
return 0;
}
return ($a["temperature"] < $b["temperature"]) ? -1 : 1;
}
usort($thermostats, "cmp");
foreach($thermostats as $key => $thermostat) {
// Allumage, si pas déjà allumé et energie possible
if ($thermostat["shouldForce"] && $energie > $thermostat["conso"] && $thermostat["mode"] == "schedule") {
cmd::byId($thermostat["reglageId"])->execCmd(array('title' => $consigneSolaire , 'message' => ''));
$energie -= $thermostat["conso"];
$scenario->setLog("Allumage ".$thermostat["name"]);
}
}
$scenario->setLog("Energie restante ".$energie);