Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System.Threading.Tasks;
  2. using JoySoftware.HomeAssistant.NetDaemon.Common;
  3. using System.Linq;
  4. public class BatteryManager : NetDaemonApp
  5. {
  6.     public override async Task InitializeAsync()
  7.     {
  8.         foreach (var device in State.Where(n => n.Attribute.battery_level < 20))
  9.         {
  10.             Log($"{device.EntityId} : {device.Attribute.battery_level}");
  11.         }
  12.  
  13.         foreach (var device in State.Where(n => n.EntityId.Contains("battery_level") && n.State < 20))
  14.         {
  15.             // Remove 14 characters from end (battery_level) to get entity id
  16.             Log($"{device.EntityId[0..^14]} : {device.State}");
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement