initial commit
This commit is contained in:
144
carrier_logger.py
Normal file
144
carrier_logger.py
Normal file
@@ -0,0 +1,144 @@
|
||||
import time
|
||||
from datetime import datetime
|
||||
from carrier_api import ApiConnection
|
||||
import json
|
||||
import mysql.connector
|
||||
|
||||
username = 'bkiedinger@gmail.com'
|
||||
password = 'Little1!'
|
||||
|
||||
|
||||
def parse_status(status, last_status_time, cursorObject, dataBase, table):
|
||||
print(status['idu'])
|
||||
print(status['odu'])
|
||||
print(status['zones']['zone'][0])
|
||||
|
||||
zone = status['zones']['zone'][0]
|
||||
|
||||
status_time = datetime.strptime(status['timestamp'], '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||
status_time = status_time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
print(status_time)
|
||||
|
||||
if last_status_time != status_time:
|
||||
last_status_time = status_time
|
||||
print('Add database entry')
|
||||
|
||||
# insert into table
|
||||
sql = (f"INSERT INTO {table} (timestamp, status_timestamp, outdoor_temp, idu_cfm, \
|
||||
idu_opstat, odu_opmode, odu_opstat, room_temp, room_humidity, cool_setpoint, heat_setpoint, \
|
||||
current_activity, zone_conditioning, mode) \
|
||||
VALUES (CURRENT_TIMESTAMP, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")
|
||||
val = [status_time, status['oat'], status['idu']['cfm'], status['idu']['opstat'],
|
||||
status['odu']['opmode'], status['odu']['opstat'], zone['rt'], zone['rh'], zone['clsp'], zone['htsp'],
|
||||
zone['currentActivity'], zone['zoneconditioning'], status['mode']]
|
||||
cursorObject.execute(sql, val)
|
||||
dataBase.commit()
|
||||
|
||||
return last_status_time
|
||||
|
||||
def main():
|
||||
print('Carrier Logger')
|
||||
|
||||
dataBase = mysql.connector.connect(
|
||||
host="192.168.1.25",
|
||||
port="3306",
|
||||
user="grafana_user",
|
||||
passwd="Little1!",
|
||||
database="grafana"
|
||||
)
|
||||
|
||||
# preparing a cursor object
|
||||
cursorObject = dataBase.cursor()
|
||||
|
||||
# cursorObject.execute('SELECT NOW()')
|
||||
# for time in cursorObject:
|
||||
# print(time)
|
||||
# print()
|
||||
|
||||
api_connection = ApiConnection(username=username, password=password)
|
||||
|
||||
systems = api_connection.get_systems()
|
||||
|
||||
# config = api_connection.get_config(systems[1].serial)
|
||||
# fid = open('config.json', 'w')
|
||||
# json.dump(config, fid, indent=4)
|
||||
# fid.close()
|
||||
|
||||
last_status_time_upstairs = ''
|
||||
last_status_time_downstairs = ''
|
||||
|
||||
|
||||
while True:
|
||||
print('Get Log')
|
||||
api_connection.activate()
|
||||
status = api_connection.get_status(systems[1].serial)
|
||||
last_status_time_downstairs = parse_status(status, last_status_time_downstairs, cursorObject, dataBase, "CARRIER_DOWNSTAIRS_STATUS")
|
||||
|
||||
status = api_connection.get_status(systems[0].serial)
|
||||
last_status_time_upstairs = parse_status(status, last_status_time_upstairs, cursorObject, dataBase, "CARRIER_UPSTAIRS_STATUS")
|
||||
|
||||
# print(status['idu'])
|
||||
# print(status['odu'])
|
||||
# print(status['zones']['zone'][0])
|
||||
#
|
||||
# zone = status['zones']['zone'][0]
|
||||
#
|
||||
# status_time = datetime.strptime(status['timestamp'], '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||
# status_time = status_time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
#
|
||||
# print(status_time)
|
||||
#
|
||||
# if last_status_time != status_time:
|
||||
# last_status_time = status_time
|
||||
# print('Add database entry')
|
||||
#
|
||||
# # insert into table
|
||||
# sql = ("INSERT INTO CARRIER_DOWNSTAIRS_STATUS (timestamp, status_timestamp, outdoor_temp, idu_cfm, \
|
||||
# idu_opstat, odu_opmode, odu_opstat, room_temp, room_humidity, cool_setpoint, heat_setpoint, \
|
||||
# current_activity, zone_conditioning, mode) \
|
||||
# VALUES (CURRENT_TIMESTAMP, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")
|
||||
# val = [status_time, status['oat'], status['idu']['cfm'], status['idu']['opstat'],
|
||||
# status['odu']['opmode'], status['odu']['opstat'], zone['rt'], zone['rh'], zone['clsp'], zone['htsp'],
|
||||
# zone['currentActivity'], zone['zoneconditioning'], status['mode']]
|
||||
# cursorObject.execute(sql, val)
|
||||
# dataBase.commit()
|
||||
|
||||
time.sleep(1 * 60)
|
||||
|
||||
|
||||
# fid = open('status.json', 'w')
|
||||
# json.dump(status, fid, indent=4)
|
||||
# fid.close()
|
||||
|
||||
test = 0
|
||||
|
||||
# {'serial': '4221W206632',
|
||||
# 'name': 'Upstairs ',
|
||||
# 'profile': {
|
||||
# 'model': 'SYSTXCCWIC01-B',
|
||||
# 'brand': 'Carrier',
|
||||
# 'firmware': 'CESR131626-04.47',
|
||||
# 'indoor_model': '58TN0A070C141212',
|
||||
# 'indoor_serial': '4521A18985',
|
||||
# 'outdoor_model': '24VNA925A00320',
|
||||
# 'outdoor_serial': '2422E23423 ',
|
||||
# 'time_stamp': '05/23/2024, 04:49:12 CDT',
|
||||
# 'zone_ids': ['1']},
|
||||
# 'status': {
|
||||
# 'outdoor_temperature': 89.0,
|
||||
# 'mode': 'cool',
|
||||
# 'temperature_unit': 'F',
|
||||
# 'filter_used': 10,
|
||||
# 'is_disconnected': False,
|
||||
# 'airflow_cfm': 373,
|
||||
# 'humidity_level': 100,
|
||||
# 'humidifier_on': False,
|
||||
# 'outdoor_unit_operational_status': 'Stage 2',
|
||||
# 'indoor_unit_operational_status': 'off',
|
||||
# 'time_stamp': '05/26/2024, 21:06:24 CDT',
|
||||
# 'zones': [{'id': '1', 'name': 'ZONE 1', 'current_activity': 'home', 'temperature': 72.0, 'humidity': 57, 'fan': 'off', 'hold': False, 'occupancy': False, 'hold_until': None, 'heat_set_point': 69.0, 'cool_set_point': 72.0, 'conditioning': 'active_cool'}]}, 'config': {'temperature_unit': 'F', 'static_pressure': 0.8033332824707031, 'mode': 'cool', 'limit_min': 50, 'limit_max': 90, 'time_stamp': '05/22/2024, 19:00:14 CDT', 'zones': [{'api_id': '1', 'name': 'ZONE 1', 'now': '21:11', 'current_activity': {'api_id': 'home', 'fan': 'off', 'heat_set_point': 69.0, 'cool_set_point': 72.0}, 'hold_activity': None, 'hold': False, 'hold_until': None, 'today_active_periods': ["{'$': {'id': '1'}, 'activity': 'wake', 'time': '07:00', 'enabled': 'on'}", "{'$': {'id': '2'}, 'activity': 'away', 'time': '08:00', 'enabled': 'on'}", "{'$': {'id': '3'}, 'activity': 'home', 'time': '18:45', 'enabled': 'on'}", "{'$': {'id': '4'}, 'activity': 'home', 'time': '19:45', 'enabled': 'on'}", "{'$': {'id': '5'}, 'activity': 'sleep', 'time': '22:00', 'enabled': 'on'}"], 'yesterday_active_periods': ["{'$': {'id': '1'}, 'activity': 'wake', 'time': '07:00', 'enabled': 'on'}", "{'$': {'id': '2'}, 'activity': 'away', 'time': '08:00', 'enabled': 'on'}", "{'$': {'id': '3'}, 'activity': 'home', 'time': '18:45', 'enabled': 'on'}", "{'$': {'id': '4'}, 'activity': 'home', 'time': '19:45', 'enabled': 'on'}", "{'$': {'id': '5'}, 'activity': 'sleep', 'time': '22:00', 'enabled': 'on'}"], 'activities': [{'api_id': 'away', 'fan': 'off', 'heat_set_point': 68.0, 'cool_set_point': 74.0}, {'api_id': 'home', 'fan': 'off', 'heat_set_point': 69.0, 'cool_set_point': 72.0}, {'api_id': 'manual', 'fan': 'off', 'heat_set_point': 68.0, 'cool_set_point': 72.0}, {'api_id': 'sleep', 'fan': 'off', 'heat_set_point': 70.0, 'cool_set_point': 72.0}, {'api_id': 'wake', 'fan': 'off', 'heat_set_point': 68.0, 'cool_set_point': 74.0}, {'api_id': 'vacation', 'fan': 'off', 'heat_set_point': 63.0, 'cool_set_point': 77.0}]}]}}
|
||||
|
||||
if __name__ == "__main__":
|
||||
# execute only if run as a script
|
||||
main()
|
||||
48
sql_test.py
Normal file
48
sql_test.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import time
|
||||
|
||||
import mysql.connector
|
||||
|
||||
dataBase = mysql.connector.connect(
|
||||
host="192.168.1.25",
|
||||
port="3306",
|
||||
user="grafana_user",
|
||||
passwd="Little1!",
|
||||
database="grafana"
|
||||
)
|
||||
|
||||
# preparing a cursor object
|
||||
cursorObject = dataBase.cursor()
|
||||
|
||||
# creating table
|
||||
studentRecord = """CREATE TABLE CARRIER_UPSTAIRS_STATUS (
|
||||
timestamp TIMESTAMP,
|
||||
status_timestamp TIMESTAMP,
|
||||
outdoor_temp int,
|
||||
idu_cfm int,
|
||||
idu_opstat VARCHAR(20),
|
||||
odu_opmode VARCHAR(20),
|
||||
odu_opstat VARCHAR(20),
|
||||
room_temp int,
|
||||
room_humidity int,
|
||||
cool_setpoint int,
|
||||
heat_setpoint int,
|
||||
current_activity VARCHAR(20),
|
||||
zone_conditioning VARCHAR(20),
|
||||
mode VARCHAR(20)
|
||||
)"""
|
||||
|
||||
# table created
|
||||
cursorObject.execute(studentRecord)
|
||||
|
||||
# # insert into table
|
||||
# for i in range(10):
|
||||
# sql = "INSERT INTO CARRIER_STATUS (timestamp, value)\
|
||||
# VALUES (CURRENT_TIMESTAMP, %s)"
|
||||
# val = [str(i)]
|
||||
# cursorObject.execute(sql, val)
|
||||
# dataBase.commit()
|
||||
# time.sleep(1)
|
||||
|
||||
# disconnecting from server
|
||||
dataBase.close()
|
||||
|
||||
Reference in New Issue
Block a user