Si cela peut aider, avant je pouvais récupérer cet info, avec Domoticz.
J’utilisais deux fichiers pour ce faire :
Un script LUA :
commandArray = {}
---récupère l'heure en minutes
time=os.time()
minutes=tonumber(os.date('%M',time))
hours=tonumber(os.date('%H',time))
maintenant=tonumber(hours*60+minutes)
if(maintenant%1 ==0 )then
local appelTBH=assert(io.popen("php /usr/local/domoticz/var/scripts/tbhweb_elec.php username password"))
local puissanceTBH = appelTBH:read('*all')
appelTBH:close()
puissance = tostring(puissanceTBH)
print(puissance)
--Ensuite remplissez votre commandArray avec les donnees recueillies :)
commandArray[1] = {['UpdateDevice'] = '14|1|' ..puissance..";0"}
end
return commandArray
Et un fichier PHP (qui était appelé dans le script LUA) :
<?php
///////////////////////////////////////////////
// Slush Coin Check
///////////////////////////////////////////////
if($argc == 3) {
$username = $argv[1];
$password = $argv[2];
} else {
die("Usage: username password\n");
}
///////////////////////////////////////////////
// Create the temporary cookie
///////////////////////////////////////////////
$cookiefile = tempnam("", "slush_");
///////////////////////////////////////////////
// Get CSRF
///////////////////////////////////////////////
$url = "https://mon.projet-tbh.fr/accounts/login/?next=/";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
preg_match("/<input type='hidden' name='csrfmiddlewaretoken' value='(.*?)' \/>/", $data, $csrf);
///////////////////////////////////////////////
// Login to Slush
///////////////////////////////////////////////
$url = "https://mon.projet-tbh.fr/accounts/login/?next=/";
$postfields = "csrfmiddlewaretoken=$csrf[1]&username=$username&password=$password";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
$data = curl_exec($curl);
curl_close($curl);
///////////////////////////////////////////////
// Visit earnings page
///////////////////////////////////////////////
$url = "https://mon.projet-tbh.fr/energie/tableau-de-bord";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
///////////////////////////////////////////////
// Capture current power
///////////////////////////////////////////////
try{
$puissance = json_decode($data, true);
if(isset($puissance['puissance']) ) {
echo $puissance['puissance'];
} else {
echo null;
}
} catch(Exception $e){
echo($e);
}
///////////////////////////////////////////////
// Clean up cookie
///////////////////////////////////////////////
unlink($cookiefile);
?>
Merci de votre aide