not being very familiar with the syntax of Home Assistant, in an automation,
I cannot convert the following basic program into a rest_command called by an automation
import requests
from requests.auth import HTTPBasicAuth
import json
vacationTemperature = 0
HC2addr ="x.x.x.x"
heatingSection = "8"
headers = {'Accept': 'application/json'}
hc2auth = HTTPBasicAuth('xxx', 'xxx')
url="http://{}/api/panels/heating/{}".format(HC2addr,heatingSection)
print(url)
r = requests.get(url, headers=headers, auth=hc2auth)
if r.status_code ==200:
data=r.json()
print(json.dumps(data, indent=4))
if data['properties']['vacationTemperature'] != vacationTemperature:
data['properties']['vacationTemperature'] = vacationTemperature
r = requests.put(url, headers=headers, auth=hc2auth, json=data)
if r.status_code == 200:
print("OK")
else:
print(r.status_code)
else:
print(r.status_code)
is it possible, even partially ?