Re: Recuperer Notification Batterie ..% (Branche, pas en charge)
Publié : 18 avr. 2016, 21:03
Reprenez le contrôle de votre domotique
https://easydomoticz.com/forum/
Code : Tout sélectionner
Powershell.exe -WindowStyle hidden -nologo -executionpolicy remotesigned -Command "& 'C:\Program Files (x86)\Domoticz\scripts\powershell\Niv_Charge_Batterie_PC.ps1'"
Code : Tout sélectionner
# --- les adresses Domoticz user/pass et l'idx à activer --------
$domoticz="http://192.168.0.XX:XXXX"
$user="Controle_Batterie_PC"
$pass="XXXX"
$idx="321"
#------------------------------------------
# -----debug a 1 pour afficher qq messages, 0 sinon ----
$debug=1
#------------------------------
# la commande powershell pour recuperer etat batteries
$pourcent_batterie = (Get-WmiObject win32_battery).estimatedChargeRemaining
#------------------------------
$pair = "${user}:${pass}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$headers = @{ Authorization = $basicAuthValue }
## la commande json a passer est
# /json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=PERCENTAGE
$url1="/json.htm?type=command¶m=udevice&idx="+$idx
$url2="&nvalue=0&svalue="+$pourcent_batterie
$urldz=($domoticz+$url1+$url2)
#Invoke the web-request avec les headers d'authentification
try { $json=Invoke-WebRequest -uri $urldz -Headers $headers } catch
{
$_.Exception.Response.StatusCode.Value__
if ($_.Exception.Response.StatusCode.Value__-eq 401) {write-host "erreur authentification user/pass"}
}
# recup reponse JSON
$infos_json = ConvertFrom-Json -InputObject $json
#recuperation depuis $infos_json avelc les libelles Domoticz
$Val_Retour=$infos_json.status
if ($debug-eq 1) {
Write-Host 'pourcentage: ' $pourcent_batterie
Write-Host $json
Write-Host "url Domoticz=" $urldz
Write-Host "message Json="$json
}
Je continu mes recherches, je suis passé de la version Domoticz 2023.1 a 2024.6Microsoft Windows [version 10.0.19045.4780]
(c) Microsoft Corporation. Tous droits réservés.
C:\WINDOWS\system32>Powershell.exe -nologo -executionpolicy remotesigned -Command "& 'C:\Program Files (x86)\Domoticz\scripts\powershell\Niv_Charge_Batterie_PC.ps1'"
401
erreur authentification user/pass
ConvertFrom-Json : Impossible de lier l'argument au paramètre « InputObject », car il a la valeur Null.
Au caractère C:\Program Files (x86)\Domoticz\scripts\powershell\Niv_Charge_Batterie_PC.ps1:43 : 45
+ $infos_json = ConvertFrom-Json -InputObject $json
+ ~~~~~
+ CategoryInfo : InvalidData : (:) [ConvertFrom-Json], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertFrom
JsonCommand
pourcentage: 96
url Domoticz= http://192.168.0.XX:XXXX/json.htm?type=command¶m=udevice&idx=321&nvalue=0&svalue=96
message Json=
C:\WINDOWS\system32>