Beispiel #1
0
 public async static Task Notify(this NetDaemonApp app, string message)
 {
     await app.CallService("notify", "hass_discord", new
     {
         message = message,
         target  = "511278310584746008"
     });
 }
 /// <summary>
 ///     Takes a snapshot of given entity id of camera and sends to private discord server
 /// </summary>
 /// <param name="app">NetDaemonApp to extend</param>
 /// <param name="camera">Unique id of the camera</param>
 public async static Task CameraSnapshot(this NetDaemonApp app, string camera, string snapshotPath)
 {
     await app.CallService("camera", "snapshot", new
     {
         entity_id = camera,
         filename  = snapshotPath
     });
 }
        /// <summary>
        ///     Takes a snapshot of given entity id of camera and sends to private discord server
        /// </summary>
        /// <param name="app">NetDaemonApp to extend</param>
        /// <param name="camera">Unique id of the camera</param>
        /// <returns>The path to the snapshot</returns>
        public async static Task <string> CameraSnapshot(this NetDaemonApp app, string camera)
        {
            var resultingFilename = $"/config/www/motion/{camera}_latest.jpg";
            await app.CallService("camera", "snapshot", new
            {
                entity_id = camera,
                filename  = resultingFilename
            });

            return(resultingFilename);
        }
Beispiel #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);
     }
 }
Beispiel #5
0
 public async static void NotifyDiscord(
     this NetDaemonApp app,
     string channel,
     string message,
     bool mention = false)
 {
     await app.CallService("notify", "hass_discord", new
     {
         message = message,
         target  = channel
     });
 }
Beispiel #6
0
 public async static void NotifyDiscord(
     this NetDaemonApp app,
     string channel,
     string message,
     Dictionary <string, IEnumerable <string> > data,
     bool mention = false)
 {
     await app.CallService("notify", "hass_discord", new
     {
         data    = data,
         message = message,
         target  = channel
     });
 }
Beispiel #7
0
    public static async Task Notify(this NetDaemonApp app, Uri audio, decimal?volume = null, params AudioNotificationDevice[] devices)
    {
        foreach (var device in devices)
        {
            await app.CallService("media_player", "turn_on", new
            {
                entity_id = GetAudioNotificationDeviceName(device)
            }, true);

            await app.CallService("media_player", "volume_set", new
            {
                entity_id    = GetAudioNotificationDeviceName(device),
                volume_level = volume ?? GetVolume(app)
            }, true);

            await app.CallService("media_player", "play_media", new
            {
                entity_id          = GetAudioNotificationDeviceName(device),
                media_content_id   = audio.ToString(),
                media_content_type = "music"
            });
        }
        // todo: get volume before, raise volume, set volume back to previous
    }
Beispiel #8
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 });
        }
    }
Beispiel #9
0
    public async static Task NotifyImage(this NetDaemonApp app, string message, string imagePath)
    {
        var dict = new Dictionary <string, IEnumerable <string> >
        {
            ["images"] = new List <string> {
                imagePath
            }
        };

        await app.CallService("notify", "hass_discord", new
        {
            data    = dict,
            message = message,
            target  = "511278310584746008"
        });
    }
Beispiel #10
0
    private static async Task SendTextNotifications(NetDaemonApp app, string category, string message,
                                                    NotificationCriteria textNotificationCriteria, TextNotificationDevice[] devices, NotificationAction[]?notificationActions = null, string?imageUrl = null)
    {
        var effectiveDevices = devices.ToList();

        if (devices.Contains(TextNotificationDevice.All))
        {
            effectiveDevices = Enums.GetValues <TextNotificationDevice>().Where(d => d != TextNotificationDevice.All)
                               .ToList();
        }

        foreach (var device in effectiveDevices)
        {
            if (textNotificationCriteria == NotificationCriteria.Home)
            {
                var person = app.State.Single(e => e.EntityId == $"person.{device.AsString(EnumFormat.Name)}".ToLower());

                if (person.State == "not_home")
                {
                    continue;
                }
            }

            // todo: support iphone and lookup notification type
            await app.CallService("notify", device.AsString(EnumFormat.DisplayName, EnumFormat.Name) !, new
            {
                message = $"{DateTime.Now:t}:{message}",
                title   = category,
                data    = new
                {
                    ttl      = 0,
                    priority = "high",
                    actions  = notificationActions?.Select(n => new { action = n.EventId, title = n.Title }),
                    image    = imageUrl
                }
            });
        }
    }
    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);
            }
        }
    }