public async Task DoExport()
        {
            Log.Information("Starting ExportValuesForCaching.DoExport()");

            using (var api = new HouseDBAPI(new Uri(_houseDBSettings.Url)))
            {
                var clientModel = new DomoticzValuesForCachingClientModel
                {
                    DateTime = DateTime.Now,
                    DomoticzValuesForCachingValues = new List <DomoticzValuesForCachingValue>()
                };

                using (var client = new HttpClient())
                {
                    // Get the values for P1 (smart home meter)
                    clientModel.P1Values = await GetP1Values(client);

                    // Get the values to cache for every device
                    foreach (var device in _devices)
                    {
                        var value = await GetDataValues(device, client);

                        clientModel.DomoticzValuesForCachingValues.Add(value);
                    }
                }

                await api.ExporterInsertValuesForCachingPostAsync(clientModel);
            }
        }
Beispiel #2
0
        private static async Task ConfigureServices(IServiceCollection services)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .Enrich.FromLogContext()
                         .WriteTo.LiterateConsole()
                         .WriteTo.RollingFile("logs/log-{Date}.txt")
                         .CreateLogger();

            // Support typed Options
            services.AddOptions();

            var houseDBSettings = await GetHouseDBSettings();

            services.AddSingleton(houseDBSettings);

            // Get other settings via API
            using (var client = new HouseDBAPI(new Uri(houseDBSettings.Url)))
            {
                var domoticzSettings = await client.SettingsGetDomoticzSettingsGetAsync();

                services.AddSingleton(domoticzSettings);
            }

            services.AddTransient <Application>();
        }
        public ExportMotionDetection(HouseDBSettings houseDBSettings, DomoticzSettings domoticzSettings)
        {
            _houseDBSettings  = houseDBSettings;
            _domoticzSettings = domoticzSettings;

            using (var api = new HouseDBAPI(new Uri(_houseDBSettings.Url)))
            {
                _devices = api.DeviceGetAllMotionDetectionDevicesGet();
            }
        }
        public ExportKwhDeviceValues(HouseDBSettings houseDBSettings, DomoticzSettings domoticzSettings)
        {
            _houseDBSettings    = houseDBSettings;
            _domoticzSettings   = domoticzSettings;
            _lastExportDateTime = DateTime.Today.AddDays(-1);

            using (var api = new HouseDBAPI(new Uri(_houseDBSettings.Url)))
            {
                _devices = api.DeviceGetAllKwhExportDevicesGet();
            }
        }
        public async Task DoExport()
        {
            if (DateTime.Now.Hour == 0 && (DateTime.Now - _lastExportDateTime).Hours > 23)
            {
                _lastExportDateTime = DateTime.Now;
                Log.Debug("Starting ExportKwhDeviceValues - DoExport");

                using (var api = new HouseDBAPI(new Uri(_houseDBSettings.Url)))
                {
                    foreach (var device in _devices)
                    {
                        var clientModel = await GetDomoticzKwhValuesClientModel(device);

                        await api.ExporterInsertDomoticzKwhValuesPostAsync(clientModel);
                    }
                }
            }
        }
        public async Task DoExport()
        {
            Log.Debug("Starting ExportMotionDetection - DoExport");

            using (var api = new HouseDBAPI(new Uri(_houseDBSettings.Url)))
            {
                foreach (var device in _devices)
                {
                    var clientModel = await GetMotionDetectionClientModel(device, true);

                    if (clientModel == null)
                    {
                        continue;
                    }

                    await api.ExporterInsertMotionDetectionValuesPostAsync(clientModel);
                }
            }
        }
Beispiel #7
0
        public async Task DoExport()
        {
            Log.Information("Starting ExportDomoticzP1Consumption()");

            using (var client = new HttpClient())
            {
                // Get the list with values
                var url      = $"http://{_domoticzSettings.Host}:{_domoticzSettings.Port}/json.htm?type=graph&sensor=counter&idx={_domoticzSettings.WattIdx}&range=year";
                var response = await client.GetStringAsync(url);

                var    data       = JsonConvert.DeserializeObject <dynamic>(response);
                JArray resultList = data.result;

                // Cast resultList to objects
                var values = resultList.ToObject <List <DomoticzP1Consumption> >();

                // Post it away
                using (var api = new HouseDBAPI(new Uri(_houseDBSettings.Url)))
                {
                    await api.ExporterInsertDomoticzP1ConsumptionPostAsync(values);
                }
            }
        }
        public async Task DoExport()
        {
            // Check if we should export
            if (DateTime.Now.Hour != 0 || DateTime.Now.Minute != 0 || (DateTime.Now - _lastExportDatabase).TotalHours < 23)
            {
                return;
            }

            _lastExportDatabase = DateTime.Now;
            Log.Debug("Starting ExportDatabase");
            byte[] byteArray;

            // Get the database
            using (var client = new HttpClient())
            {
                client.Timeout = TimeSpan.FromMinutes(1);

                var url = $"http://{_domoticzSettings.Host}:{_domoticzSettings.Port}/backupdatabase.php";
                using (var response = client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).Result)
                {
                    response.EnsureSuccessStatusCode();
                    byteArray = await response.Content.ReadAsByteArrayAsync();
                }
            }

            // Post the database to the HouseDBAPI
            using (var api = new HouseDBAPI(new Uri(_houseDBSettings.Url)))
            {
                await api.ExporterUploadDatabasePostAsync(new DomoticzPostDatabaseFile
                {
                    ByteArray = byteArray,
                    DateTime  = DateTime.Now,
                    FileName  = "domoticz.db"
                });
            }
        }