def __init__(self, bridge_ip: str = None): """ Args: bridge_ip: str, ip address to the Philips Hue bridge. default is resolved from ip """ # Set path to bridge ip h = Hosts() if bridge_ip is None: bridge_ip = h.get_ip_from_host('ot-huehub') super().__init__(bridge_ip) # Bridge button may need to be pressed the first time this is used self.connect() self.api = self.get_api()
def setUpClass(cls) -> None: cls.logg = LogWithInflux('cam-test', log_to_file=False) cam_ip = Hosts().get_ip_from_host('ac-garaaz') cls.cam = Amcrest(cam_ip, parent_log=cls.logg)
def setUpClass(cls) -> None: cls.host = Hosts()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Determines if mobile is connected to local network. If not, will arm the cameras""" from servertools import Amcrest, OpenWRT from kavalkilu import LogWithInflux, Hosts # Initiate Log, including a suffix to the log name to denote which instance of log is running log = LogWithInflux('cam_active') ow = OpenWRT() hosts = Hosts() # Get only cameras without numbers in the name cam_info_list = hosts.get_hosts_and_ips(r'(?!^ac-.*(\d.*|doorbell)$)^ac-.+$') res_list = [] currently_active_ips = ow.get_active_connections() # Check if mobile(s) are connected to LAN for ip in [i['ip'] for i in hosts.get_hosts_and_ips('an-[bm]a.*')]: res_list.append(ip in currently_active_ips.keys()) # If anyone home, don't arm, otherwise arm arm_cameras = not any(res_list) arm_status = 'ARMED' if arm_cameras else 'UNARMED' if not arm_cameras: log.debug( 'One of the devices are currently in the network. Disabling motion detection.' ) else: log.debug( 'None of the devices are currently in the network. Enabling motion detection.' ) for cam_dict in cam_info_list:
def homeauto(): ip = Hosts().get_ip_from_host('pi-elutuba') return redirect(f'http://{ip}:8123/lovelace/default_view')
def pihole_lookup(client: str): # Lookup client ip ip = Hosts().get_ip_from_host(client) return redirect(f'http://tinyserv.local/admin/index.php?client={ip}')
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Activates nighttime mode on cameras""" from servertools import Amcrest from kavalkilu import LogWithInflux, Hosts # Initiate Log, including a suffix to the log name to denote which instance of log is running log = LogWithInflux('cam_night') hosts = Hosts() # Get only cameras without numbers in the name cam_info_list = hosts.get_hosts_and_ips(r'^ac-(ga|el)') for cam_dict in cam_info_list: # Instantiate cam & arm cam = Amcrest(cam_dict['ip']) if cam.camera_type != 'doorbell': cam.arm_camera(True) # publish.single(f'sensors/cameras/{cam.name}/status', 'ARMED', hostname='tinyserv.local') log.close()
import os from datetime import datetime as dt, timedelta from kavalkilu import LogWithInflux, DateTools, InfluxDBLocal, InfluxDBPiHole, SQLLiteLocal, Hosts from servertools import SlackComm logg = LogWithInflux('pihole_etl', log_to_db=True) sc = SlackComm(parent_log=logg) hosts = {x['ip']: x['name'] for x in Hosts().get_all_hosts()} datetools = DateTools() FTL_DB_PATH = os.path.join('/etc', *['pihole', 'pihole-FTL.db']) sqll = SQLLiteLocal(FTL_DB_PATH) INTERVAL_MINS = 60 end = dt.now().astimezone().replace(second=0, microsecond=0) start = (end - timedelta(minutes=INTERVAL_MINS)) unix_start = datetools.dt_to_unix(start, from_tz='US/Central') unix_end = datetools.dt_to_unix(end, from_tz='US/Central') query = f""" SELECT client , domain , CASE WHEN status = 0 THEN 'UNKNOWN' WHEN status = 1 OR status > 3 THEN 'BLOCKED' WHEN status = 2 OR status = 3 THEN 'ALLOWED' ELSE 'UNKNOWN' END AS query_status , CASE WHEN status = 0 THEN 'NO ANSWER'
Note: depends on `rf_stream` already being running and feeding data to port 1433 via `rtl_433 -F syslog::1433` """ import json from json import JSONDecodeError import socket from datetime import datetime import pandas as pd from kavalkilu import InfluxDBLocal, InfluxDBHomeAuto, LogWithInflux, \ GracefulKiller, Hosts, HOME_SERVER_HOSTNAME, HAHelper from servertools import SlackComm logg = LogWithInflux('rf_temp') sc = SlackComm(parent_log=logg) UDP_IP = Hosts().get_ip_from_host(HOME_SERVER_HOSTNAME) UDP_PORT = 1433 # device id to device-specific data mapping mappings = { 210: {'name': 'neighbor-porch'}, 3092: {'name': 'ylemine-r6du'}, 5252: {'name': 'elutuba'}, 6853: {'name': 'kontor-wc'}, 8416: {'name': 'alumine-r6du'}, 9459: {'name': 'freezer'}, 9533: {'name': 'kontor'}, 10246: {'name': 'v2lisuks'}, 12476: {'name': 'suur-wc'}, 14539: {'name': 'fridge'}, 15227: {'name': 'mushroom-station'}
import subprocess from kavalkilu import LogWithInflux, HOME_SERVER_HOSTNAME, Hosts logg = LogWithInflux('rf_stream', log_dir='rf') serv_ip = Hosts().get_ip_from_host(HOME_SERVER_HOSTNAME) cmd = ['/usr/local/bin/rtl_433', '-F', f'syslog:{serv_ip}:1433'] logg.info(f'Sending command: {" ".join(cmd)}') process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) process_output, _ = process.communicate() logg.debug(f'Process output: {process_output}')
} }, { 'names': ['-i', '--interval'], 'other': { 'action': 'store', 'default': '60' } }] ap = ArgParse(args, parse_all=False) CAMERA = ap.arg_dict.get('camera') INTERVAL_MINS = int(ap.arg_dict.get('interval')) start_dt = (dt.now() - timedelta(minutes=INTERVAL_MINS)).replace(second=0, microsecond=0) end_dt = (start_dt + timedelta(minutes=INTERVAL_MINS)) cam_ip = Hosts().get_ip_from_host(CAMERA) cam = Amcrest(cam_ip) vt = VidTools(640, 360, resize_perc=0.5, speed_x=5) temp_dir = tempfile.gettempdir() motion_logs = cam.get_motion_log(start_dt, end_dt) logg.info(f'Found {len(motion_logs)} motion events for the range selected.') buffer = 30 # give the clips an x second buffer before and after motion was detected already_downloaded = [] files = [] for mlog in motion_logs: start = mlog['start'] - timedelta(seconds=buffer) end = mlog['end'] + timedelta(seconds=buffer) logg.info(
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import time from datetime import datetime as dtt from kavalkilu import LogWithInflux, Keys, NetTools, Hosts, HOME_SERVER_HOSTNAME from servertools import BrowserAction, SlackComm ip = NetTools().get_ip() debug = Hosts().get_ip_from_host(HOME_SERVER_HOSTNAME) != ip logg = LogWithInflux('vpulse_auto') # TODO # build out a table of when monthly, weekly things were last done. # Handle weekly tasks either based on DOW or recorded table with date_last_done and freq columns # Get credentials creds = Keys().get_key('vpulse-creds') def message_channel_and_log(msg): slack_comm.send_message(notify_channel, msg) if debug: logg.debug(msg) def get_vpoints(): """Collects amount of points currently available""" points_script = "return document.getElementById('progress-bar-menu-points-total-value')" points = ba.driver.execute_script(points_script).get_attribute( 'textContent').strip()