예제 #1
0
    public static bool AnyoneHome(this NetDaemonApp app)
    {
        try
        {
            var isa_location = app.GetState("person.isa")?.State?.ToString()?.ToLower();

            var stefan_location = app.GetState("person.stefan")?.State?.ToString()?.ToLower();
            if (isa_location != null || stefan_location != null)
            {
                if (stefan_location == "home" || stefan_location == "just arrived" ||
                    isa_location == "home" || isa_location == "just arrived")
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            // return true if null, assume someone could be home
            app.Log($"A person returned null as location state, assuming someone is home.");
            return(true);
        }
        catch (System.Exception e)
        {
            // return true if something goes wrong, assume someone could be home
            app.Log($"Error: {e}");
            return(true);
        }
    }
예제 #2
0
 public static bool AnyoneHome(this NetDaemonApp app)
 {
     try
     {
         var isa_location    = app.GetState(Isa.PersonEntity)?.State?.ToString()?.ToLower();
         var stefan_location = app.GetState(Stefan.PersonEntity)?.State?.ToString()?.ToLower();
         if (isa_location != null || stefan_location != null)
         {
             if (stefan_location == PresenceStatus.Home || stefan_location == PresenceStatus.JustArrived ||
                 isa_location == PresenceStatus.Home || isa_location == PresenceStatus.JustArrived)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         // return true if null, assume someone could be home
         app.Log($"A person returned null as location state, assuming someone is home.");
         return(true);
     }
     catch (System.Exception e)
     {
         // return true if something goes wrong, assume someone could be home
         app.Log($"Error: {e}");
         return(true);
     }
 }
예제 #3
0
    public static async Task SetTTSVolume(this NetDaemonApp app)
    {
        var deviceName = GetAudioNotificationDeviceName(AudioNotificationDevice.Home);

        if (app.GetState(deviceName) !.State != "playing")
        {
            await app.SetVolume(GetVolume(app), deviceName);
        }
    }
예제 #4
0
 public static async Task SetVolume(this NetDaemonApp app, decimal volume, string entityId)
 {
     if (((decimal?)app.GetState(entityId) !.Attribute !.volume_level).GetValueOrDefault(0) != volume)
     {
         await app.CallService("media_player", "volume_set", new
         {
             entity_id    = entityId,
             volume_level = volume
         }, true);
     }
 }
예제 #5
0
    private static async Task SendTTSNotifications(NetDaemonApp app, string message)
    {
        var ttsEnabled = app.GetState("input_boolean.tts_enabled") !.State;

        if (ttsEnabled == "on")
        {
            await app.CallService("media_player", "turn_on", new
            {
                entity_id = GetAudioNotificationDeviceName(AudioNotificationDevice.Home)
            }, true);

            await SetTTSVolume(app);

            await app.CallService("tts", "amazon_polly_say", new
            {
                entity_id = GetAudioNotificationDeviceName(AudioNotificationDevice.Home),
                message   = message
            });
        }
        else
        {
            await SendTextNotifications(app, "TTS TEST", message, NotificationCriteria.Always, new[] { TextNotificationDevice.Daniel });
        }
    }
    public static async Task NotifyIos(
        this NetDaemonApp app,
        string title,
        string message,
        string notifier = "",
        bool onlyIfHome = false,
        string threadId = "home-assistant",
        string category = "",
        bool critical   = false,
        string imageUrl = "")
    {
        var isHome = app.GetState("person.isa")?.State?.ToString()?.ToLower() == "home" ||
                     app.GetState("person.isa")?.State?.ToString()?.ToLower() == "just arrived";

        if (!onlyIfHome || (onlyIfHome && isHome))
        {
            // object sound = "";
            var contentType   = "";
            var hideThumbnail = "";
            var entityId      = "";

            if (!string.IsNullOrWhiteSpace(entityId))
            {
                contentType   = "jpeg";
                category      = "camera";
                hideThumbnail = "";
            }
            // if (critical)
            // {
            //     sound = new Dictionary<string, object>
            //     {
            //         ["name"] = "default",
            //         ["critical"] = 1,
            //         ["volume"] = 1.0
            //     };
            // }

            var data = new Dictionary <string, object>
            {
                ["title"]   = title,
                ["message"] = message,
                ["data"]    = new Dictionary <string, object>
                {
                    ["attachment"] = new Dictionary <string, object>
                    {
                        ["url"]            = imageUrl,
                        ["content-type"]   = contentType,
                        ["hide-thumbnail"] = hideThumbnail
                    },
                    ["push"] = new Dictionary <string, object>
                    {
                        ["thread-id"] = threadId,
                        ["badge"]     = 0,
                        // ["sound"] = sound,
                        ["category"] = category
                    },
                    ["entity_id"] = entityId
                }
            };
            if (string.IsNullOrWhiteSpace(notifier))
            {
                await app.CallService("notify", Isa.IosNotifier, data);
            }
            else
            {
                await app.CallService("notify", notifier, data, false);
            }
        }
    }