py-ha-ws-client


Namepy-ha-ws-client JSON
Version 0.6 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_time2024-08-18 14:58:10
maintainerNone
docs_urlNone
authorfoxy82
requires_pythonNone
licenseApache 2.0
keywords home assistant websocket
VCS
bugtrack_url
requirements No requirements were recorded.
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/95/d9/43dbb67d1557f6e6e5f5857511857359886391ae871a22726e44bc318f35/py_ha_ws_client-0.6.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.6",
    "project_urls": {
        "Download": "https://github.com/designer-living/py-ha-ws-client/archive/0.6.tar.gz",
        "Homepage": "https://github.com/designer-living/py-ha-ws-client"
    },
    "split_keywords": [
        "home assistant",
        " websocket"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6b05dec8b078411c518a3beeccba70dfe1d8f21537b3ce64489742f3a825540e",
                "md5": "66a28e56f8dcdedd4a5b820617c00bfb",
                "sha256": "e33b63020baba5b9fabdf0753fb6dc00997f613b1c06f0dd03587241fcd18aa8"
            },
            "downloads": -1,
            "filename": "py_ha_ws_client-0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "66a28e56f8dcdedd4a5b820617c00bfb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10058,
            "upload_time": "2024-08-18T14:58:08",
            "upload_time_iso_8601": "2024-08-18T14:58:08.932771Z",
            "url": "https://files.pythonhosted.org/packages/6b/05/dec8b078411c518a3beeccba70dfe1d8f21537b3ce64489742f3a825540e/py_ha_ws_client-0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "95d943dbb67d1557f6e6e5f5857511857359886391ae871a22726e44bc318f35",
                "md5": "7f606d2b67f4246a852166310b7ca94a",
                "sha256": "447f5173b02b0c84a0ba2ed8f501361bb01cae88f4db65bcc7f96524b664898d"
            },
            "downloads": -1,
            "filename": "py_ha_ws_client-0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "7f606d2b67f4246a852166310b7ca94a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9546,
            "upload_time": "2024-08-18T14:58:10",
            "upload_time_iso_8601": "2024-08-18T14:58:10.067927Z",
            "url": "https://files.pythonhosted.org/packages/95/d9/43dbb67d1557f6e6e5f5857511857359886391ae871a22726e44bc318f35/py_ha_ws_client-0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-18 14:58:10",
    "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": [],
    "lcname": "py-ha-ws-client"
}
        
Elapsed time: 0.33514s