Samsung RS6GA884CSL/EG Side-by-Side Kühlschrank

Der Kühlschrank wird mit WIFI ausgeliefert. In der Nachricht ist sowohl die Temperatur, also auch der Verbrauch sichtbar: Anstatt des Kühlschrankes sollten sich auch viele andere Smartthings-Geräte einbinden lassen. (Klimaanlage?)

Das Script sollte mit cron regelmäßig aufgerufen werden.

myexample.py
#!/usr/bin/env python3
import requests
import json
 
def main():
    token  = '123456' # get it from https://account.smartthings.com/tokens
    token2 = '123456'
    device = '123456'
    url = 'https://api.smartthings.com/v1/devices/'+ device +'/status' 
    headers = {'Authorization': 'Bearer '+token}
    myobj = {'somekey': 'somevalue'}
    x = requests.get(url, headers=headers)
    xjson = x.json()
    old_soll2 = xjson['components']['cooler']['thermostatCoolingSetpoint']['coolingSetpoint']['value']
    old_soll1 = xjson['components']['freezer']['thermostatCoolingSetpoint']['coolingSetpoint']['value']
    soll1 = old_soll1
    soll2 = old_soll2
    print ('powerConsumption       ' + str(xjson['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=' ')
    print (y.json())
    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=' ')
    print (y.json())
    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=' ')
    print (y.json())
    url = 'http://localhost:8080/data/74255150-10e0-11ec-ae1b-0b00b3c7779f.json?from=1+minute+ago&to=now'
    y = requests.get(url)
    einspeisung  = y.json()['data']['average']
    print("Einspeisung:" + str(einspeisung))
 
    if einspeisung >  500:
       soll1 = -21
       soll2 = 4
    if einspeisung <  1:
       soll1 = -19
       soll2 = 6
    headers = {'Authorization': 'Bearer '+token, 'Content-Type': 'application/json' }
    if soll1  != old_soll1:
       print('freezer')
       url = 'https://api.smartthings.com/v1/devices/'+ device +'/commands'
       payload = [{"component":"freezer","capability":"thermostatCoolingSetpoint","command":"setCoolingSetpoint","arguments":[soll1]}]
       y = requests.post(url, headers=headers,  data=json.dumps(payload))
       print (y.json())
    if soll2  != old_soll2:
       print('cooler')
       url = 'https://api.smartthings.com/v1/devices/'+ device +'/commands'
       payload = [{"component":"cooler","capability":"thermostatCoolingSetpoint","command":"setCoolingSetpoint","arguments":[soll2]}]
       y = requests.post(url, headers=headers,  data=json.dumps(payload))
       print (y.json())
if __name__ == '__main__':
    main()