{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import os\n", "import dotenv\n", "from homeassistant_api import Client\n", "from langchain.tools import BaseTool\n", "from homeassistant_api.errors import EndpointNotFoundError\n", "\n", "dotenv.load_dotenv()\n", "\n", "ha_client = Client(\n", " os.environ.get('HA_URL', 'http://localhost:8123'),\n", " os.environ.get('HA_API_KEY', '')\n", ")\n" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['Config', '__abstractmethods__', '__annotations__', '__class__', '__class_vars__', '__config__', '__custom_root_type__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__exclude_fields__', '__fields__', '__fields_set__', '__format__', '__ge__', '__get_validators__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__include_fields__', '__init__', '__init_subclass__', '__iter__', '__json_encoder__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__post_root_validators__', '__pre_root_validators__', '__pretty__', '__private_attributes__', '__reduce__', '__reduce_ex__', '__repr__', '__repr_args__', '__repr_name__', '__repr_str__', '__rich_repr__', '__schema_cache__', '__setattr__', '__setstate__', '__signature__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '__try_update_forward_refs__', '__validators__', '_abc_impl', '_calculate_keys', '_copy_and_set_values', '_decompose_class', '_enforce_dict_if_root', '_get_value', '_init_private_attributes', '_iter', 'async_get_history', 'async_get_state', 'async_update_state', 'construct', 'copy', 'dict', 'entity_id', 'from_orm', 'get_history', 'get_state', 'group', 'json', 'parse_file', 'parse_obj', 'parse_raw', 'schema', 'schema_json', 'slug', 'state', 'update_forward_refs', 'update_state', 'validate']\n" ] }, { "data": { "text/plain": [ "State(entity_id='camera.lab', state='idle', attributes={'access_token': '3cf7f417701f843b6bfdc0315513692cd71249f0b358d5d8af01070eaf7eac28', 'frontend_stream_type': 'hls', 'entity_picture': '/api/camera_proxy/camera.lab?token=3cf7f417701f843b6bfdc0315513692cd71249f0b358d5d8af01070eaf7eac28', 'friendly_name': 'LabCamera', 'supported_features': 2}, last_changed=datetime.datetime(2023, 5, 9, 16, 33, 16, 991327, tzinfo=datetime.timezone.utc), last_updated=datetime.datetime(2023, 5, 9, 16, 33, 16, 991327, tzinfo=datetime.timezone.utc), context=Context(id='01H00NRA5ZBJB7WF5DDPZ9DC6P'))" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "camera = ha_client.get_entity(entity_id=\"camera.lab\")\n", "print(dir(camera))\n", "camera.get_state()" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'enable_motion_detection': Service(service_id='enable_motion_detection', name='Enable motion detection', description='Enable the motion detection in a camera.', fields={}), 'disable_motion_detection': Service(service_id='disable_motion_detection', name='Disable motion detection', description='Disable the motion detection in a camera.', fields={}), 'turn_off': Service(service_id='turn_off', name='Turn off', description='Turn off camera.', fields={}), 'turn_on': Service(service_id='turn_on', name='Turn on', description='Turn on camera.', fields={}), 'snapshot': Service(service_id='snapshot', name='Take snapshot', description='Take a snapshot from a camera.', fields={'filename': ServiceField(description='Template of a Filename. Variable is entity_id.', example='/tmp/snapshot_{{ entity_id.name }}.jpg', selector={'text': None}, name='Filename', required=True)}), 'play_stream': Service(service_id='play_stream', name='Play stream', description='Play camera stream on supported media player.', fields={'media_player': ServiceField(description='Name(s) of media player to stream to.', example=None, selector={'entity': {'domain': 'media_player'}}, name='Media Player', required=True), 'format': ServiceField(description='Stream format supported by media player.', example=None, selector={'select': {'options': ['hls']}}, name='Format', required=None)}), 'record': Service(service_id='record', name='Record', description='Record live camera feed.', fields={'filename': ServiceField(description='Template of a Filename. Variable is entity_id. Must be mp4.', example='/tmp/snapshot_{{ entity_id.name }}.mp4', selector={'text': None}, name='Filename', required=True), 'duration': ServiceField(description='Target recording length.', example=None, selector={'number': {'min': 1, 'max': 3600, 'unit_of_measurement': 'seconds'}}, name='Duration', required=None), 'lookback': ServiceField(description='Target lookback period to include in addition to duration. Only available if there is currently an active HLS stream.', example=None, selector={'number': {'min': 0, 'max': 300, 'unit_of_measurement': 'seconds'}}, name='Lookback', required=None)})}\n" ] } ], "source": [ "camera = ha_client.get_domain(\"camera\")\n", "print(camera.services)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "()" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "camera.snapshot(entity_id=\"camera.lab\", filename=\"snapshot_{{ entity_id.name }}.jpg\")" ] } ], "metadata": { "kernelspec": { "display_name": "openai", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.11" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }