public async Task <IActionResult> OnPostSwitchOffAsync(int action) { if (!User.Identity.IsAuthenticated) { return(Redirect("/")); } var accessToken = await HttpContext.GetTokenAsync("access_token"); return(await ActionsApi.RunActionsAsync( accessToken, new ActionToRun { DeviceID = Id, Actions = new List <ActionToRunItem> { new ActionToRunItem(HexStringHelper.ByteArrayToString(ObisCodes.SmartMeSpecificPhaseSwitchL1), 0.0) } }, new ResultHandler <ActionToRun> { OnError = DefaultErrorHandler.Handle } )); }
public static async Task ActionsAsync(UserPassword credentials) { // We will use this device to fetch its details later Device sampleDevice; // Get all devices { Helpers.WriteConsoleTitle("Get all devices"); List <Device> devices = await DevicesApi.GetDevicesAsync(credentials); foreach (var device in devices) { Console.WriteLine($"Id: {device.Id}, Name: {device.Name}"); } // Store the first device. Make sure you have at least one device in your smart-me account. sampleDevice = devices.First(); } // Get Actions { Helpers.WriteConsoleTitle("Get Actions"); List <SmartMeApiClient.Containers.Action> actions = await ActionsApi.GetActionsAsync(credentials, sampleDevice.Id); foreach (var action in actions) { Console.WriteLine($"Name: {action.Name}, ObisCode: {action.ObisCode}"); } } // Run Actions { Helpers.WriteConsoleTitle("Run Actions"); await ActionsApi.RunActionsAsync(credentials, new ActionToRun { DeviceID = sampleDevice.Id, Actions = new List <ActionToRunItem> { new ActionToRunItem(HexStringHelper.ByteArrayToString(ObisCodes.SmartMeSpecificPhaseSwitchL1), 1.0) } }); Console.WriteLine("Switch on"); Thread.Sleep(5000); await ActionsApi.RunActionsAsync(credentials, new ActionToRun { DeviceID = sampleDevice.Id, Actions = new List <ActionToRunItem> { new ActionToRunItem(HexStringHelper.ByteArrayToString(ObisCodes.SmartMeSpecificPhaseSwitchL1), 0.0) } }); Console.WriteLine("Switch off"); } }