All Projects β†’ qJake β†’ Hadotnet

qJake / Hadotnet

Licence: apache-2.0
🏑 A .NET Standard library for Home Assistant.

Projects that are alternatives of or similar to Hadotnet

Denonavr
Automation Library for Denon AVR receivers.
Stars: ✭ 104 (+100%)
Mutual labels:  api, home-assistant, home-automation
Home Assistant octopusagile
Octopus Agile custom component for Home Assistant
Stars: ✭ 30 (-42.31%)
Mutual labels:  home-assistant, home-automation
Python Common Cache
This project is a cache component based on the memory and it is lightweight, simple and customizable. 🐍 πŸ˜ƒ
Stars: ✭ 21 (-59.62%)
Mutual labels:  api, library
Hellobooks
A Single-Page Library Management App built with nodejs, express and react and redux
Stars: ✭ 37 (-28.85%)
Mutual labels:  api, library
Supervisor
🏑 Home Assistant Supervisor
Stars: ✭ 862 (+1557.69%)
Mutual labels:  home-assistant, home-automation
Gitter Api
[production-ready] Gitter API implementation for php 7.0+ allowing sync, async and streaming access.
Stars: ✭ 11 (-78.85%)
Mutual labels:  api, library
Hass Config
Configuration files for Home Assistant
Stars: ✭ 32 (-38.46%)
Mutual labels:  home-assistant, home-automation
Open Home Automation
Open Home Automation with Home Assistant, ESP8266/ESP32 and MQTT
Stars: ✭ 820 (+1476.92%)
Mutual labels:  home-assistant, home-automation
Open Home
Projeto de automação residencial usando softwares e hardwares open source.
Stars: ✭ 41 (-21.15%)
Mutual labels:  home-assistant, home-automation
Home Assistant Config
My Home Assistant configuration
Stars: ✭ 41 (-21.15%)
Mutual labels:  home-assistant, home-automation
Home Assistantconfig
🏑 My Home Assistant Configs. Be sure to 🌟 my repo, if it has been of any help
Stars: ✭ 43 (-17.31%)
Mutual labels:  home-assistant, home-automation
Abclinuxuapi
API for http://abclinuxu.cz.
Stars: ✭ 8 (-84.62%)
Mutual labels:  api, library
Homeassistant
Example Home Assistant Configs
Stars: ✭ 846 (+1526.92%)
Mutual labels:  home-assistant, home-automation
Android
πŸ“± Home Assistant Companion for Android
Stars: ✭ 881 (+1594.23%)
Mutual labels:  home-assistant, home-automation
Home Assistant Config
Home Assistant config files, rewritten to use the latest features, 100+ documented automations, automatically generated ToC 🏠 πŸ€–
Stars: ✭ 926 (+1680.77%)
Mutual labels:  home-assistant, home-automation
Restless
Express.js api, type safe validations and more
Stars: ✭ 32 (-38.46%)
Mutual labels:  api, library
Home Assistant Js
🐝 JavaScript implementation of the Home Assistant API using NuclearJS
Stars: ✭ 50 (-3.85%)
Mutual labels:  home-assistant, home-automation
Room Assistant
Presence tracking and more for automation on the room-level
Stars: ✭ 764 (+1369.23%)
Mutual labels:  home-assistant, home-automation
Yasumi
The easy PHP Library for calculating holidays
Stars: ✭ 788 (+1415.38%)
Mutual labels:  api, library
Lara Eye
Filter your Query\Builder using a structured query language
Stars: ✭ 39 (-25%)
Mutual labels:  api, library

HADotNet

Nuget ci-badge

Buy me a coffee

A simple, straighforward .NET Standard library for the Home Assistant API.

Features

  • .NET Standard 2.0 cross-platform library
  • DI-friendly client initialization (suitable for ASP.NET Core)
  • Home Assistant data is represented by strongly-typed, commented model classes

Supported Home Assistant APIs

  • Root API (Verifies the HA API is responding)
  • Automation API
  • Google Calendar API (Unofficial)
  • Discovery API
  • Entity API
  • Error Log API
  • Events API
  • History API
  • Logbook API
  • Services API
  • States API
  • Supervisor API (Supervisor-based installations only)
  • Template API

Getting Started

From NuGet (Recommended)

Nuget

Install HADotNet.Core from NuGet:

Install-Package HADotNet.Core

From Source

Clone this repo and either include the HADotNet.Core library in your project, or build the project and include the DLL as a reference.

Examples

Initializing The Client Factory

The ClientFactory class is reponsible for initializing all other clients in a reusable way, so you only have to define your instance URL and API key once.

To initialize the ClientFactory, pass in your base Home Assistant URL and a long-lived access token that you created on your profile page.

ClientFactory.Initialize("https://my-home-assistant-url/", "AbCdEf0123456789...");

Getting Home Assistant's Current Configuration

Get a ConfigClient and then call GetConfiguration():

var configClient = ClientFactory.GetClient<ConfigClient>();
var config = await configClient.GetConfiguration();
// config.LocationName: "Home"
// config.Version: 0.96.1

Retrieving All Entities

Get an EntityClient and then call GetEntities():

var entityClient = ClientFactory.GetClient<EntityClient>();
var entityList = await entityClient.GetEntities();

Retrieving Entities By Domain

Get an EntityClient and then call GetEntities("domainName"):

var entityClient = ClientFactory.GetClient<EntityClient>();
var filteredEntityList = await entityClient.GetEntities("light");

Retrieving All Entity States

Get a StatesClient and then call GetStates():

var statesClient = ClientFactory.GetClient<StatesClient>();
var allMyStates = await statesClient.GetStates();

Retrieving State By Entity

Get a StatesClient and then call GetState(entity):

var statesClient = ClientFactory.GetClient<StatesClient>();
var state = await statesClient.GetState("sun.sun");
// state.EntityId: "sun.sun"
// state.State: "below_horizon"

Retrieving All Service Definitions

Get a ServiceClient and then call GetServices():

var serviceClient = ClientFactory.GetClient<ServiceClient>();
var services = await serviceClient.GetServices();

Retrieving Calendar Events

Get a CalendarClient and then call GetEvents(calEntity):

var calClient = ClientFactory.GetClient<CalendarClient>();
var myEvents = await calClient.GetEvents("calendar.my_calendar");

Calling a Service

Get a ServiceClient and then call CallService():

var serviceClient = ClientFactory.GetClient<ServiceClient>();

var resultingState = await serviceClient.CallService("homeassistant", "restart");
// Or
var resultingState = await serviceClient.CallService("light", "turn_on", new { entity_id = "light.my_light" });
// Or
var resultingState = await serviceClient.CallService("light.turn_on", new { entity_id = "light.my_light" });
// Or
var resultingState = await serviceClient.CallService("light.turn_on", @"{""entity_id"":""light.my_light""}");

Retrieving History for an Entity

Get a HistoryClient and then call GetHistory(entityId):

var historyClient = ClientFactory.GetClient<HistoryClient>();
var historyList = await historyClient.GetHistory("sun.sun");

// historyList.EntityId: "sun.sun"
// historyList[0].State: "above_horizon"
// historyList[0].LastUpdated: 2019-07-25 07:25:00
// historyList[1].State: "below_horizon"
// historyList[1].LastUpdated: 2019-07-25 20:06:00

Rendering a Template

Get a TemplateClient and then call RenderTemplate(templateBody):

var templateClient = ClientFactory.GetClient<TemplateClient>();
var myRenderedTemplate = await templateClient.RenderTemplate("The sun is {{ states('sun.sun') }}");

// myRenderedTemplate: The sun is above_horizon

Testing

To run the unit tests, you must first set two environment variables:

  • HADotNet:Tests:Instance = https://my-home-assistant-url/
  • HADotNet:Tests:ApiKey = AbCdEf0123456789...

Collaborating

Fork the project, make some changes, and submit a pull request!

Be sure to follow the same coding style (generally, the standard Microsoft C# coding guidelines) and comment all publicly-visible types and members with XMLDoc comments.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].