51 lines
1.3 KiB
Python
Executable file
51 lines
1.3 KiB
Python
Executable file
#!/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(demand)
|
|
|
|
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
|