| Nächste Überarbeitung | Vorhergehende Überarbeitung |
| hardware:smartthings_cooler [2022/04/24 06:45] – angelegt mauwjo | hardware:smartthings_cooler [2022/04/25 12:28] (aktuell) – mauwjo |
|---|
| |
| def main(): | def main(): |
| token = 'e306f894-c0da-4bd9-822e-2ad965092478' # get it from https://account.smartthings.com/tokens | token = '123456' # get it from https://account.smartthings.com/tokens |
| url = 'https://api.smartthings.com/v1/devices/702b151a-acc1-46b3-b16d-aadb1b74149e/status' | token2 = '123456' |
| | device = '123456' |
| | url = 'https://api.smartthings.com/v1/devices/'+ device +'/status' |
| headers = {'Authorization': 'Bearer '+token} | headers = {'Authorization': 'Bearer '+token} |
| myobj = {'somekey': 'somevalue'} | myobj = {'somekey': 'somevalue'} |
| x = requests.get(url, headers=headers) | x = requests.get(url, headers=headers) |
| print (x.json()['components']['main']['powerConsumptionReport']['powerConsumption']['value']['energy']) | xjson = x.json() |
| print (x.json()['components']['cooler']['temperatureMeasurement']['temperature']['value']) | old_soll2 = xjson['components']['cooler']['thermostatCoolingSetpoint']['coolingSetpoint']['value'] |
| print (x.json()['components']['cooler']['thermostatCoolingSetpoint']['coolingSetpoint']['value']) | old_soll1 = xjson['components']['freezer']['thermostatCoolingSetpoint']['coolingSetpoint']['value'] |
| print (x.json()['components']['freezer']['thermostatCoolingSetpoint']['coolingSetpoint']['value']) | soll1 = old_soll1 |
| #send to VZLOgger | soll2 = old_soll2 |
| headers = {'x-auth-token': '2ad965092478', 'Content-Type': 'application/json' } | print ('powerConsumption ' + str(xjson['components']['main']['powerConsumptionReport']['powerConsumption']['value']['energy'])) |
| server_endpoint = "http://localhost:8080/data/d52043c0-c330-11ec-b314-5f9afa3b2ce2.json?value=" + str( x.json()['components']['main']['powerConsumptionReport']['powerConsumption']['value']['energy'] ); | print ('cooler_temperature ' + str(xjson['components']['cooler']['temperatureMeasurement']['temperature']['value'])) |
| | print ('cooler coolingSetpoint ' + str(old_soll2)) |
| | print ('freeze coolingSetpoint ' + str(old_soll1)) |
| | |
| | headers = {'x-auth-token': token2, 'Content-Type': 'application/json' } |
| | server_endpoint = "http://localhost:8080/data/d52043c0-c330-11ec-b314-5f9afa3b2ce2.json?value=" + str( xjson['components']['main']['powerConsumptionReport']['powerConsumption']['value']['energy'] ); |
| y = requests.post(server_endpoint, headers=headers, data=' ') | y = requests.post(server_endpoint, headers=headers, data=' ') |
| print (y.json()) | print (y.json()) |
| server_endpoint = "http://localhost:8080/data/e10e5be0-c33a-11ec-8631-4bb138decf9f.json?value=" + str( x.json()['components']['cooler']['temperatureMeasurement']['temperature']['value'] ); | server_endpoint = "http://localhost:8080/data/e10e5be0-c33a-11ec-8631-4bb138decf9f.json?value=" + str( xjson['components']['cooler']['temperatureMeasurement']['temperature']['value'] ); |
| y = requests.post(server_endpoint, headers=headers, data=' ') | y = requests.post(server_endpoint, headers=headers, data=' ') |
| print (y.json()) | print (y.json()) |
| server_endpoint = "http://localhost:8080/data/878eb080-c340-11ec-8251-d79d02cab158.json?value=" + str( x.json()['components']['freezer']['temperatureMeasurement']['temperature']['value'] ); | server_endpoint = "http://localhost:8080/data/878eb080-c340-11ec-8251-d79d02cab158.json?value=" + str( xjson['components']['freezer']['temperatureMeasurement']['temperature']['value'] ); |
| y = requests.post(server_endpoint, headers=headers, data=' ') | y = requests.post(server_endpoint, headers=headers, data=' ') |
| print (y.json()) | print (y.json()) |
| #get from VZLOGGER current measurement if we buy or sell energy | url = 'http://localhost:8080/data/74255150-10e0-11ec-ae1b-0b00b3c7779f.json?from=1+minute+ago&to=now' |
| url = 'http://localhost:8080/data/6f059630-dc46-11e3-a595-3d3810b75dc6.json' | |
| y = requests.get(url) | y = requests.get(url) |
| einspeisung = y.json()['data']['tuples'][0][1] | einspeisung = y.json()['data']['average'] |
| if einspeisung < -500: | print("Einspeisung:" + str(einspeisung)) |
| | |
| | if einspeisung > 500: |
| soll1 = -21 | soll1 = -21 |
| soll2 = 4 | soll2 = 4 |
| if einspeisung > 0: | if einspeisung < 1: |
| soll1 = -19 | soll1 = -19 |
| soll2 = 6 | soll2 = 6 |
| # adjust temperatures based on it | headers = {'Authorization': 'Bearer '+token, 'Content-Type': 'application/json' } |
| if soll1 != x.json()['components']['freezer']['temperatureMeasurement']['temperature']['value']: | if soll1 != old_soll1: |
| url = 'https://api.smartthings.com/v1/devices/702b151a-acc1-46b3-b16d-aadb1b74149e/commands' | print('freezer') |
| headers = {'Authorization': 'Bearer '+token, 'Content-Type': 'application/json' } | url = 'https://api.smartthings.com/v1/devices/'+ device +'/commands' |
| payload = [{"component":"freezer","capability":"thermostatCoolingSetpoint","command":"setCoolingSetpoint","arguments":[soll1]}] | payload = [{"component":"freezer","capability":"thermostatCoolingSetpoint","command":"setCoolingSetpoint","arguments":[soll1]}] |
| y = requests.post(url, headers=headers, data=json.dumps(payload)) | y = requests.post(url, headers=headers, data=json.dumps(payload)) |
| print (y.json()) | print (y.json()) |
| if soll2 != x.json()['components']['cooler']['temperatureMeasurement']['temperature']['value']: | if soll2 != old_soll2: |
| url = 'https://api.smartthings.com/v1/devices/702b151a-acc1-46b3-b16d-aadb1b74149e/commands' | print('cooler') |
| headers = {'Authorization': 'Bearer '+token, 'Content-Type': 'application/json' } | url = 'https://api.smartthings.com/v1/devices/'+ device +'/commands' |
| payload = [{"component":"cooler","capability":"thermostatCoolingSetpoint","command":"setCoolingSetpoint","arguments":[soll2]}]code | payload = [{"component":"cooler","capability":"thermostatCoolingSetpoint","command":"setCoolingSetpoint","arguments":[soll2]}] |
| y = requests.post(url, headers=headers, data=json.dumps(payload)) | y = requests.post(url, headers=headers, data=json.dumps(payload)) |
| print (y.json()) | print (y.json()) |
| | if __name__ == '__main__': |
| | main() |
| </code> | </code> |