Any interest in my .NET Core automation framework?

Howdy!

I've not run webCORE on HE because I saw some folks saying it caused problems or slowed down their HE device, but I needed something that could do more complex logic than Rules Engine. As a result, I built an app in .NET Core (I work for Microsoft) that uses Hubitat's Maker API to provide a framework for writing automations in C#.

For example, in SmartThings, I used a series of CORE rules to drive the logic related to my pantry door and light. Instead of rules, this logic is all handled in one method in C#:

/// <summary>
/// Handles pantry door events coming from the home automation controller.
/// </summary>
/// <param name="evt">The event passed from the automation controller.
/// In this case, the pantry door opening/closing.</param>
/// <param name="token">A .NET cancellation token received if this handler is to be cancelled. </param>
public void Handle(HubEvent evt, CancellationToken token)
{
    if(evt.value == "open")
    {
        _pantryLight.On();

        // Wait a bit
        Thread.Sleep(TimeSpan.FromMinutes(5));
        if (token.IsCancellationRequested) return;
        _kitchenSpeaker.Speak("Please close the pantry door");

        // Wait a bit more
        Thread.Sleep(TimeSpan.FromMinutes(5));
        if (token.IsCancellationRequested) return;
        _kitchenSpeaker.Speak("I said, please close the pantry door");

        // Wait a bit longer...
        Thread.Sleep(TimeSpan.FromMinutes(5));
        if (token.IsCancellationRequested) return;
        _kitchenSpeaker.Speak("Fine, I'll do it myself.");
        _pantryLight.Off();
    }
    else
    {
        _pantryLight.Off();
    }
}

Is this something you're interested in? If so, I'll anonymize it and throw it up on GitHub with a detailed README. Be warned, it's for people who are comfortable editing a C# file and recompiling the application with dotnet build. It's not hard, and I'll write it up in the README, but some might find it a little more complex than installing webCORE.

What do ya'll think?

7 Likes

Ignore the TimeSpan.FromSeconds(5), please. That should be TimeSpan.FromMinutes(5)

That was from testing and I can't edit it here. I'm assuming it's because I'm a new user here?

Edit: It was. I fixed the source.

Hello, I'm nobody here but I would like to test for sure. Thanks

1 Like

No worries, it's the general gist that matters. Similar to some of the scripts I use in another system. It uses .NET

Sound pretty nice, what kind of interface would there be to program it? I'm all in for writing own logic with C# because i've programmed alot in C#. Wouldn't mind testing it with you.

Sounds like a cool project (being a .NET fan myself), but i came to HE to help me eliminate man the in the middle scenarios.

So right now, it's one solution with 4 projects:

  • The first project is a common class library used as a dependency by all the other projects.
  • The next project is a web API that listens for webhooks from Hubitat and then passes the event data off to a program I call the executive. I originally had the entire project in web API, but I realized that long-running web API controller actions were probably a bad idea so now the web API just handles the webhook and then is done.
  • The executive is a service that takes the event data passed to it from the web API and figures out what instance of IAutomation to use for the event it was given and then calls it.
  • The last project is the only one you'll ever need to touch. It's just a project full of IAutomation instances. IAutomation implements a single method, Handle(). That's all the code for Handle() in my pantry automation above. Right now, this project is part of the solution, but before I start sharing this with everyone I want to refactor it just a little so it just reads the IAutomation assemblies at runtime.

Based on what you and some other people have said, this is definitely something some .NET folks like me could use. I'll get to work on a writeup for the README so you know how to build/run it. It's not really hard, and I actually write documentation for a living so I hope it turns out to be usable. :slight_smile:

5 Likes

Count me interested as well. I'm a .NET dev and was thinking of doing something similar but haven't had the time to do more than think about it. This seems like a great jumping off point.

1 Like

Oh, I totally get it! I wanted a platform I could extend to do integrations with Azure really easily. I realized that half of my time spent writing neat automations in Groovy was struggling with learning the language and platform, and I really didn't want to invest the time to become a Groovy expert when there are so many other cool things I could spend my time on. So I built this thing. It could also be pretty easily adapted to MQTT, too, I think.

1 Like

I'm definitely interested. Nice to see another .NET Core developer! I'm new to Hubitat but bought it for the development features. I'll be more than happy to test and give you whatever help I can.

I've been playing with Google Actions and Dialogue Flow using a .NET Core web API on Azure to make custom Google Assistant commands. Google makes some pretty cool stuff. Now to get it all to work with my new Hubitat haha.

2 Likes

Count me in. I've been developing in .NET since it was in beta - but haven't really done anything with .NET Core. Looking forward to it.

1 Like

Sorry for the necro post, but I was wondering whatever came of this. I am working on a hobby project for a locally run UI (asp.net core web app with React front end) and this would save me a lot of effort re: integration with Hubitat.

1 Like

Not a necro post at all! I actually talked about this at .NET Conf this year and I've been giving a 1-hour version of this talk all over the country.

Project is alive and well. If you'd like to fork it, I'll be happy to get you going!

Awesome! Watched the video and browsed the repo, this is great stuff!

I forked and cloned and it ran fine and detected a virtual switch turning off and on.

My initial thoughts are to refactor a service out of the main executable so it can run as a background service in my asp.net core web app. I've prototyped that in my local copy of the fork and the executable still runs fine.

What's the best method to discuss ideas? Are you open to pull requests?

1 Like

Issues for ideas, PRs for code. Let's do it. :slight_smile: