py-ha-ws-client


Namepy-ha-ws-client JSON
Version 0.7 PyPI version JSON
download
home_pagehttps://github.com/designer-living/py-ha-ws-client
SummaryA Python client to make it easy to connect and consume data from the Home Assistant web socket API.
upload_time2025-01-18 13:19:26
maintainerNone
docs_urlNone
authorfoxy82
requires_pythonNone
licenseApache 2.0
keywords home assistant websocket
VCS
bugtrack_url
requirements ws4py
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # py-ha-ws-client
A Python client to make it easy to connect and consume data from the [Home Assistant web socket API](https://developers.home-assistant.io/docs/api/websocket/).


## Example

```
from time import sleep
from py_ha_ws_client.client import HomeAssistantWsClient

hostname = "<Home Assistant IP>"
#token = "<from Home Assistant>"

client = HomeAssistantWsClient.with_host_and_port(token, hostname)
# Or if in use in a Home Assistant Add on
# client = HomeAssistantWsClient.in_ha_addon()

client.connect()

while not client.connected():
    sleep(1)

# Get all the states as a list
print("Get all States")
states = client.get_states()
print("Print one state as an example")
print(states[0])


entity_id = "media_player.amplifier"

# Define a call back
def my_callback(entity_id, message):
    print(entity_id, message)

# Get the state of a single entity
state = client.get_state(entity_id)
print(state)    

# Register for updates for a specfic entity
client.subscribe_to_trigger(
    entity_id="media_player.studio_amplifier",
    callback=my_callback,
)

sleep(10)

# Send a turn on command
client.turn_on(
    entity_id=entity_id
)

sleep(10)

# Send a change volume command
client.call_service(
    domain="media_player",
    service="volume_set",
    entity_id=entity_id,
    service_data={
        "volume_level" : "0.50"
    }
)

sleep(10)

# Send a turn off command
client.turn_off(
    entity_id=entity_id
)

sleep(60)

```

## TODO

This is a work in progress there are a lot of TODOs in the code.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/designer-living/py-ha-ws-client",
    "name": "py-ha-ws-client",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "Home Assistant, Websocket",
    "author": "foxy82",
    "author_email": "foxy82.github@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/49/a1/45a471eadf1d2c2d98600ceac05782aff171214434ca060bf8f53ef00421/py_ha_ws_client-0.7.tar.gz",
    "platform": null,
    "description": "# py-ha-ws-client\nA Python client to make it easy to connect and consume data from the [Home Assistant web socket API](https://developers.home-assistant.io/docs/api/websocket/).\n\n\n## Example\n\n```\nfrom time import sleep\nfrom py_ha_ws_client.client import HomeAssistantWsClient\n\nhostname = \"<Home Assistant IP>\"\n#token = \"<from Home Assistant>\"\n\nclient = HomeAssistantWsClient.with_host_and_port(token, hostname)\n# Or if in use in a Home Assistant Add on\n# client = HomeAssistantWsClient.in_ha_addon()\n\nclient.connect()\n\nwhile not client.connected():\n    sleep(1)\n\n# Get all the states as a list\nprint(\"Get all States\")\nstates = client.get_states()\nprint(\"Print one state as an example\")\nprint(states[0])\n\n\nentity_id = \"media_player.amplifier\"\n\n# Define a call back\ndef my_callback(entity_id, message):\n    print(entity_id, message)\n\n# Get the state of a single entity\nstate = client.get_state(entity_id)\nprint(state)    \n\n# Register for updates for a specfic entity\nclient.subscribe_to_trigger(\n    entity_id=\"media_player.studio_amplifier\",\n    callback=my_callback,\n)\n\nsleep(10)\n\n# Send a turn on command\nclient.turn_on(\n    entity_id=entity_id\n)\n\nsleep(10)\n\n# Send a change volume command\nclient.call_service(\n    domain=\"media_player\",\n    service=\"volume_set\",\n    entity_id=entity_id,\n    service_data={\n        \"volume_level\" : \"0.50\"\n    }\n)\n\nsleep(10)\n\n# Send a turn off command\nclient.turn_off(\n    entity_id=entity_id\n)\n\nsleep(60)\n\n```\n\n## TODO\n\nThis is a work in progress there are a lot of TODOs in the code.\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "A Python client to make it easy to connect and consume data from the Home Assistant web socket API.",
    "version": "0.7",
    "project_urls": {
        "Download": "https://github.com/designer-living/py-ha-ws-client/archive/0.7.tar.gz",
        "Homepage": "https://github.com/designer-living/py-ha-ws-client"
    },
    "split_keywords": [
        "home assistant",
        " websocket"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ab1e963c1456d4e876fc98da63d9005b31bb2518e4e1c4f099f5a9d1addb8783",
                "md5": "3dab39b02d745c9cfcd0cf3f198d9d7a",
                "sha256": "f064a997fe84cf392164d1e6e4787b2eccd66d039cdefe762af0d19d349ddd9a"
            },
            "downloads": -1,
            "filename": "py_ha_ws_client-0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3dab39b02d745c9cfcd0cf3f198d9d7a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10118,
            "upload_time": "2025-01-18T13:19:25",
            "upload_time_iso_8601": "2025-01-18T13:19:25.684238Z",
            "url": "https://files.pythonhosted.org/packages/ab/1e/963c1456d4e876fc98da63d9005b31bb2518e4e1c4f099f5a9d1addb8783/py_ha_ws_client-0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "49a145a471eadf1d2c2d98600ceac05782aff171214434ca060bf8f53ef00421",
                "md5": "5bc6e8e61bd33e9741b83ce0f1d76c36",
                "sha256": "9503a2b9f644f70b10f32cc5781f6513f8e69fb6ae8ed596edd7d534532be4c3"
            },
            "downloads": -1,
            "filename": "py_ha_ws_client-0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "5bc6e8e61bd33e9741b83ce0f1d76c36",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9640,
            "upload_time": "2025-01-18T13:19:26",
            "upload_time_iso_8601": "2025-01-18T13:19:26.659614Z",
            "url": "https://files.pythonhosted.org/packages/49/a1/45a471eadf1d2c2d98600ceac05782aff171214434ca060bf8f53ef00421/py_ha_ws_client-0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-18 13:19:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "designer-living",
    "github_project": "py-ha-ws-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "ws4py",
            "specs": [
                [
                    "==",
                    "0.5.1"
                ]
            ]
        }
    ],
    "lcname": "py-ha-ws-client"
}
        
Elapsed time: 0.44877s