# 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": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "Home Assistant,Websocket",
"author": "foxy82",
"author_email": "foxy82.github@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d9/d6/861d6bcc05cfb2990b0a51a8dcd58a448c8313b2bf2b8a86f06a03dc00e4/py_ha_ws_client-0.4.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.4",
"project_urls": {
"Download": "https://github.com/designer-living/py-ha-ws-client/archive/0.4.tar.gz",
"Homepage": "https://github.com/designer-living/py-ha-ws-client"
},
"split_keywords": [
"home assistant",
"websocket"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "435fe9d0e69ccbc3f1ab46e0c8380ec7d9507e5e7312086261ac1cb6efeefbee",
"md5": "299b7c1a4ee18d114f3c6866a839c2b1",
"sha256": "bd24c6ff07b8ee0b6aa45b0e3d74ead97376f9d021882978d58b26f7eccd7559"
},
"downloads": -1,
"filename": "py_ha_ws_client-0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "299b7c1a4ee18d114f3c6866a839c2b1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 10006,
"upload_time": "2024-01-05T11:06:19",
"upload_time_iso_8601": "2024-01-05T11:06:19.395461Z",
"url": "https://files.pythonhosted.org/packages/43/5f/e9d0e69ccbc3f1ab46e0c8380ec7d9507e5e7312086261ac1cb6efeefbee/py_ha_ws_client-0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d9d6861d6bcc05cfb2990b0a51a8dcd58a448c8313b2bf2b8a86f06a03dc00e4",
"md5": "80e6aba71be01631b99bb62a1375fcdc",
"sha256": "d6af99c125e1248270cbea9d5c5f39efe5313b1726d22329d4e2651be2e6a0b2"
},
"downloads": -1,
"filename": "py_ha_ws_client-0.4.tar.gz",
"has_sig": false,
"md5_digest": "80e6aba71be01631b99bb62a1375fcdc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9505,
"upload_time": "2024-01-05T11:06:20",
"upload_time_iso_8601": "2024-01-05T11:06:20.863650Z",
"url": "https://files.pythonhosted.org/packages/d9/d6/861d6bcc05cfb2990b0a51a8dcd58a448c8313b2bf2b8a86f06a03dc00e4/py_ha_ws_client-0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-05 11:06:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "designer-living",
"github_project": "py-ha-ws-client",
"github_not_found": true,
"lcname": "py-ha-ws-client"
}