Hallo,
ich möchte Daten in einer USV abfragen, die nicht per SNMP zur Verfügung gestellt werden.
Dazu gibt es wohl zwei Ansätze:
1. https://community.home-assistant.io/t/cyberpower-b…-sensors/226563
Code
- platform : rest
resource: http://<IPADRESS>:3052/local/rest/v1/ups/status
name: Server UPS
headers:
Authorization: <BEARER-TOKEN-COPIED-EARLIER>
User-Agent: Home Assistant
Content-Type: application/json
value_template: '{{ value_json["battery"]["stateText"] }}'
json_attributes:
- input
- output
- battery
- bypass
- system
- onlyPhaseArch
- communicationAvaiable
- <Add any other attributes found in response tab>
Alles anzeigen
Mir geht es nur um den Loginvorgang, die Daten "zerpflücke" ich mir dann schon. Wie es aussieht, genügt hier der Login mit einem (immer gleich bleibenden?) BearerToken. Wie gebe ich sowas in eine Abfrage mit und wie löst man es am besten? Inet.au3? Winhttp.au3?
2. https://community.home-assistant.io/t/cyberpower-b…-sensors/226563
Code
import requests
import paho.mqtt.client as paho
import json
url = "http://192.168.x.x:3052/local/rest/v1/login/verify"
url2 = "http://192.168.x.x:3052/local/rest/v1/ups/status"
payload = {"userName": "adminuser", "password": "adminpassword"}
headers = {'Content-Type': "application/json"}
response = requests.request("POST", url, json=payload, headers=headers)
# the json parameter should handle encoding for you
cookies = response.cookies
response = requests.request("GET", url2, cookies=cookies)
r_dictionary= response.json()
iv = r_dictionary['input']['voltages'][0]
ov = r_dictionary['output']['voltages'][0]
ol = r_dictionary['output']['loads'][0]
br = r_dictionary['battery']['remainingRunTimeInSecs']/60
brf = r_dictionary['battery']['remainingRunTimeFormated']
sys = r_dictionary['system']['stateText']
batt = r_dictionary['battery']['stateText']
cap = r_dictionary['battery']['capacity']
comm = r_dictionary['communicationAvaiable']
Alles anzeigen
Er gibt hier wohl direkt das Passwort und den Usernamen mit. Wie könnte ich es so umsetzen?
Ich bin leider was die Webgeschichten (außer IE.au3, aber die lassen wir mal lieber außen vor) recht schwach.
Danke!