Get heating state from hass
This commit is contained in:
parent
9625bd3b5c
commit
0943e948c7
1 changed files with 50 additions and 0 deletions
50
control/hass-heating.py
Executable file
50
control/hass-heating.py
Executable file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
import os
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
|
script_directory = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
with open(script_directory + '/../config/config.json', 'r') as thefile:
|
||||||
|
config = json.load(thefile)
|
||||||
|
|
||||||
|
auth = config['auth']
|
||||||
|
urls = config['urls']
|
||||||
|
control = config['control']
|
||||||
|
|
||||||
|
try:
|
||||||
|
ro = requests.get(urls['hass'], headers = {
|
||||||
|
'Authorization': 'Bearer ' + auth['bearer'],
|
||||||
|
'content-type': 'application/json',
|
||||||
|
})
|
||||||
|
except:
|
||||||
|
print("Error getting override. Defaulting to off.")
|
||||||
|
heating = False
|
||||||
|
else:
|
||||||
|
heating = ro.json()
|
||||||
|
|
||||||
|
if heating['state'] == 'on':
|
||||||
|
demand = True
|
||||||
|
else:
|
||||||
|
demand = False
|
||||||
|
|
||||||
|
print(heating)
|
||||||
|
|
||||||
|
runs = 0
|
||||||
|
if demand:
|
||||||
|
while runs < 3:
|
||||||
|
subprocess.run([script_directory + '/../sender/rf', control['on']['code'], control['on']['multiplier'], control['on']['inverse']])
|
||||||
|
with open(script_directory + '/../rwdata/state.txt', 'w+') as thefile:
|
||||||
|
thefile.write("1")
|
||||||
|
time.sleep(1)
|
||||||
|
runs = runs + 1
|
||||||
|
|
||||||
|
else:
|
||||||
|
while runs < 3:
|
||||||
|
subprocess.run([script_directory + '/../sender/rf', control['off']['code'], control['off']['multiplier'], control['off']['inverse']])
|
||||||
|
with open(script_directory + '/../rwdata/state.txt', 'w+') as thefile:
|
||||||
|
thefile.write("0")
|
||||||
|
time.sleep(1)
|
||||||
|
runs = runs + 1
|
Loading…
Reference in a new issue