GithubHelp home page GithubHelp logo

yllibed / yllibed.homeassistant Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 2.0 60 KB

Framework to create app-like programs with strong integration into Home Assistant using powerful WebSocket API. This is a fork from rille111/HomeAssistant.AppStarter project.

License: Apache License 2.0

C# 100.00%

yllibed.homeassistant's Introduction

Yllibed HomeAssistant Framework

Fork Status

This project is a fork from Hass rille111's AppStarter https://github.com/rille111/HomeAssistant.AppStarter. Few changes has been done on the original project:

  • Updated to use System.Net.WebSockets
  • Refactoring of the code
  • Changed the name and the layout of the sources
  • New deployment process

Build Status Nuget

WARNING

The following documentation hasn't been updated yet for new version. Stay tuned for updated documentation!

Purpose

Home Assistant 'Hass' is a home automation system running on Unix-systems and AppDaemon is used along with it to further empower developers to write Python-based automations and apps, working with Hass.

I don't excel at either Unix or Python but I still enjoy Home Assistant and want to use .NET to accomplish things I couldn't with Hass-AppDaemon. Hence the birth of this project, and being inspired by AppDaemon I want to enable myself and others to use their existing .NET knowledge to write app-like implementations based on Hass.

It is easy, just nuget-install Rille.Hass.AppStarter and follow the steps and you'll be going in no time!

Installation

Usage - Create apps

  • Create a class that implements IHassApp
  • Filling out the various properties (see code for examples)
  • Implement ExecuteAsync() with your code

Usage - Configure & Run

Super easy! Better show with code:

        public async Task RunAppStarter()
        {
            await Task.Delay(0);

            var appRunner = new HassAppsRunner("ws://192.168.0.201:8123/api/websocket");

            appRunner.TraceOutput += (sender, args) => _logger.Trace(args.Exception, args.Text);
            appRunner.DebugOutput += (sender, args) => _logger.Debug(args.Exception, args.Text);
            appRunner.WarnOutput += (sender, args) => _logger.Warn(args.Exception, args.Text);
            appRunner.InfoOutput += (sender, args) => _logger.Info(args.Exception, args.Text);
            appRunner.ErrorOutput += (sender, args) => _logger.Error(args.Exception, args.Text);

            appRunner.Start();

            System.Console.WriteLine($"\n-- Connected. Press any key to exit --");
            System.Console.ReadKey();
            appRunner.Stop();
        }

And an app to help you wake up! (It will be found by the AppStarter since it scans for everything that implements IHassApp)

    public class WakeUpApp : IHassApp
    {
        public string TriggeredByEntities { get; set; } = "automation.wakeup_*"; // <-- yes, wildcards are supported!

        // Dependencies (IoC or Factories not supported right now)
        private readonly Logger _logger = LogManager.GetCurrentClassLogger();
        private readonly HassWebApiServiceProxy _hassApiProxy = new HassWebApiServiceProxy("http://192.168.0.201:8123/api");

        public async Task ExecuteAsync(EventData e, string rawData)
        {
            if (e.StateChangeData.OldState != "on" || e.StateChangeData.NewState != "on")
                return; // A trigger for an automation has both these states set to "on" by some reason.

            _logger.Info($"Executing {nameof(WakeUpApp)} for [{e.EntityId}]");

            // Turn on all lamps
            await TurnOnLightFor("light.dimmer_vardagsrum_level", 155);
            await TurnOnLightFor("light.dimmer_minihall_level", 155);
            await TurnOnLightFor("light.dimmer_hall_level", 155);
            await TurnOnLightFor("light.led_sovrum_tak_level", 255);
        }

        public bool IsExecuting { get; set; }

        private async Task TurnOnLightFor(string entity_id, int brightness)
        {
            await _hassApiProxy.CallHassService("light", "turn_on", new {entity_id, brightness});
        }
    }

Engine

Since Hass exposes a Websocket API, this lib will subscribe to all state_changed events via this Websocket, and connect your written apps with those events.

TODO

  • Since it's in alpha development it will crash! Feel free to contribute. :)

yllibed.homeassistant's People

Contributors

carldebilly avatar dependabot-preview[bot] avatar isabellaalstrom avatar rille111 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

sabuto moayyaed

yllibed.homeassistant's Issues

Refactor for DI and sample AP

This library is 'just what I'm looking for' and with a few tweaks I've got it working with the original ConsoleExample from rille111's version.

However I would like to tweak the flow relating to dependency injection, perhaps move to .net 5 and repurpose the console example as a reference app. What are your thoughts? I'm happy to take part as contributor, to discuss ideas via this thread, submit PR's or 'just leave it be' :-)

By way of context, my goal is around having a rich and configurable external rule based system for (amongst other things) lights that follow as you move around. Whilst HA is indeed amazing, it doesn't easily lend itself to the dynamic and reactive rules I have - hence shifting this to .Net.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.