Skip to main content

A Python client to make it easy to connect and consume data from the Home Assistant web socket API.

Project description

py-ha-ws-client

A Python client to make it easy to connect and consume data from the Home Assistant web socket API.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_ha_ws_client-0.6.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

py_ha_ws_client-0.6-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file py_ha_ws_client-0.6.tar.gz.

File metadata

  • Download URL: py_ha_ws_client-0.6.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for py_ha_ws_client-0.6.tar.gz
Algorithm Hash digest
SHA256 447f5173b02b0c84a0ba2ed8f501361bb01cae88f4db65bcc7f96524b664898d
MD5 7f606d2b67f4246a852166310b7ca94a
BLAKE2b-256 95d943dbb67d1557f6e6e5f5857511857359886391ae871a22726e44bc318f35

See more details on using hashes here.

File details

Details for the file py_ha_ws_client-0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for py_ha_ws_client-0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e33b63020baba5b9fabdf0753fb6dc00997f613b1c06f0dd03587241fcd18aa8
MD5 66a28e56f8dcdedd4a5b820617c00bfb
BLAKE2b-256 6b05dec8b078411c518a3beeccba70dfe1d8f21537b3ce64489742f3a825540e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page