Example app

This application shows basic capabilities of the fluent API of NetDaemon. It has two files, ExampleApp.yaml that contains basic configuration of the instance and ExampleApp.cs that contains the app logic.

ExampleApp.yaml

example_app:
class: ExampleApp

ExampleApp.cs

using System;
using System.Reactive.Linq;
using NetDaemon.Common.Reactive;
/// <summary>
/// Example app
/// </summary>
public class ExampleApp : NetDaemonRxApp
{
public override void Initialize()
{
Entity("binary_sensor.my_motion_sensor")
.StateChanges
.Where(e.New?.State == "off")
.NDSameStateFor(TimeSpan.FromMinutes(10))
.Subscribe(s => Entity("light.light1").TurnOff());
}

The NetDaemonApp base class

public class ExampleApp : NetDaemonRxApp

All applications in netdaemon have to inherit the NetDaemonApp base class. This provides discoverability and functionality to the application.

The Initialize function

public override void Initialize()

This function is called by the daemon and it´s purpose is to do all the initialization of your application. Never block this function! Typically you configure what should happen when a state change or run a function every minute for an example.

Example:

Entity("binary_sensor.my_motion_sensor")
.StateChanges
.Where(e.New?.State == "off")
.NDSameStateFor(TimeSpan.FromMinutes(10))
.Subscribe(s => Entity("light.light1").TurnOff());
FunctionDescription
EntitySelects one or more entities where actions are applied
StateChangesIf state changes on previously defined entity do action
WhereLamda expression of when to do action
NDSameStateForDo action only if state has not change for a period of time (10 minutes)
SubscribeCalls any code/action when criteras met
TurnOffThe action on previously selected entity/ies

Real-world example apps

Please check out the apps being developed for netdaemon. Since documentation is still lacking behind it will be best looking at real code 😊

UserDescription
@helto4realMy own netdaemon apps running in production (Use V2 veriosn of API)
@isabellaalstromIsabella's netdaemon apps, check them out, nice stuff
@Horizon0156Stefan W's netdaemon apps, good example extending netdaemon functionality