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.7.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_ha_ws_client-0.7.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for py_ha_ws_client-0.7.tar.gz
Algorithm Hash digest
SHA256 9503a2b9f644f70b10f32cc5781f6513f8e69fb6ae8ed596edd7d534532be4c3
MD5 5bc6e8e61bd33e9741b83ce0f1d76c36
BLAKE2b-256 49a145a471eadf1d2c2d98600ceac05782aff171214434ca060bf8f53ef00421

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_ha_ws_client-0.7-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for py_ha_ws_client-0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f064a997fe84cf392164d1e6e4787b2eccd66d039cdefe762af0d19d349ddd9a
MD5 3dab39b02d745c9cfcd0cf3f198d9d7a
BLAKE2b-256 ab1e963c1456d4e876fc98da63d9005b31bb2518e4e1c4f099f5a9d1addb8783

See more details on using hashes here.

Supported by

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