Skip to content

Commit

Permalink
new office routine
Browse files Browse the repository at this point in the history
  • Loading branch information
dteske25 committed Dec 20, 2023
1 parent a7763df commit 4e349bb
Show file tree
Hide file tree
Showing 9 changed files with 3,336 additions and 3,722 deletions.
2,237 changes: 1,005 additions & 1,232 deletions HomeAssistantGenerated.cs

Large diffs are not rendered by default.

446 changes: 108 additions & 338 deletions NetDaemonCodegen/EntityMetaData.json

Large diffs are not rendered by default.

3,865 changes: 1,969 additions & 1,896 deletions NetDaemonCodegen/ServicesMetaData.json

Large diffs are not rendered by default.

74 changes: 37 additions & 37 deletions apps/HallwayAutomation.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
namespace TeskeHomeAssistant.apps;
//namespace TeskeHomeAssistant.apps;

[NetDaemonApp]
public class HallwayAutomation
{
public HallwayAutomation(IHaContext ha, IScheduler scheduler, Entities entities, ILogger<HallwayAutomation> logger)
{
var hallwayLights = new List<Entity>
{
entities.Light.Hallway1,
entities.Light.Hallway2,
};
//[NetDaemonApp]
//public class HallwayAutomation
//{
// public HallwayAutomation(IHaContext ha, IScheduler scheduler, Entities entities, ILogger<HallwayAutomation> logger)
// {
// var hallwayLights = new List<Entity>
// {
// entities.Light.Hallway1,
// entities.Light.Hallway2,
// };

new MotionBuilder(entities.BinarySensor.HallwaySensorMotion, scheduler, logger)
.WithMotionAllowed(entities.Switch.HallwaySensorMotion)
.WithOnAction(_ =>
{
if (entities.Light.HallwaySwitch.State == "off")
{
entities.Light.HallwaySwitch.TurnOn();
}
hallwayLights.TurnOn();
})
.WithOffAction(_ => hallwayLights.TurnOff(), TimeSpan.FromMinutes(2))
.Build();
// new MotionBuilder(entities.BinarySensor.HallwaySensorMotion, scheduler, logger)
// .WithMotionAllowed(entities.Switch.HallwaySensorMotion)
// .WithOnAction(_ =>
// {
// if (entities.Light.HallwaySwitch.State == "off")
// {
// entities.Light.HallwaySwitch.TurnOn();
// }
// hallwayLights.TurnOn();
// })
// .WithOffAction(_ => hallwayLights.TurnOff(), TimeSpan.FromMinutes(2))
// .Build();

ha.Events.Where(ZigbeeDeviceName.HallwaySwitch, ZigbeeSwitchCommands.On).Subscribe(_ =>
{
entities.Switch.HallwaySensorMotion.TurnOff();
scheduler.Schedule(TimeSpan.FromHours(2), () => entities.Switch.HallwaySensorMotion.TurnOn());
hallwayLights.TurnOn();
});
// ha.Events.Where(ZigbeeDeviceName.HallwaySwitch, ZigbeeSwitchCommands.On).Subscribe(_ =>
// {
// entities.Switch.HallwaySensorMotion.TurnOff();
// scheduler.Schedule(TimeSpan.FromHours(2), () => entities.Switch.HallwaySensorMotion.TurnOn());
// hallwayLights.TurnOn();
// });

ha.Events.Where(ZigbeeDeviceName.HallwaySwitch, ZigbeeSwitchCommands.Off).Subscribe(_ =>
{
entities.Switch.HallwaySensorMotion.TurnOff();
scheduler.Schedule(TimeSpan.FromHours(6), () => entities.Switch.HallwaySensorMotion.TurnOn());
hallwayLights.TurnOff();
});
// ha.Events.Where(ZigbeeDeviceName.HallwaySwitch, ZigbeeSwitchCommands.Off).Subscribe(_ =>
// {
// entities.Switch.HallwaySensorMotion.TurnOff();
// scheduler.Schedule(TimeSpan.FromHours(6), () => entities.Switch.HallwaySensorMotion.TurnOn());
// hallwayLights.TurnOff();
// });

}
}
// }
//}
220 changes: 110 additions & 110 deletions apps/HomeSchedule.cs
Original file line number Diff line number Diff line change
@@ -1,125 +1,125 @@
namespace TeskeHomeAssistant.apps;
//namespace TeskeHomeAssistant.apps;

[NetDaemonApp]
public class HomeSchedule
{
public HomeSchedule(IScheduler scheduler, Entities entities, IHaContext ha, ILogger<HomeSchedule> logger)
{
var bedroomLights = new List<Entity>
{
entities.Light.Lamp,
entities.Light.Nightstand,
entities.Light.ElementsAc4b,
};
//[NetDaemonApp]
//public class HomeSchedule
//{
// public HomeSchedule(IScheduler scheduler, Entities entities, IHaContext ha, ILogger<HomeSchedule> logger)
// {
// var bedroomLights = new List<Entity>
// {
// entities.Light.Lamp,
// entities.Light.Nightstand,
// entities.Light.ElementsAc4b,
// };

var drivewayLights = new List<Entity>
{
entities.Light.DrivewaySwitchLight,
entities.Light.HueFilamentBulb1,
entities.Light.HueFilamentBulb2,
entities.Light.HueFilamentBulb3,
};
// var drivewayLights = new List<Entity>
// {
// entities.Light.DrivewaySwitchLight,
// entities.Light.HueFilamentBulb1,
// entities.Light.HueFilamentBulb2,
// entities.Light.HueFilamentBulb3,
// };

var fadeDuration = (int)TimeSpan.FromMinutes(5).TotalSeconds;
// var fadeDuration = (int)TimeSpan.FromMinutes(5).TotalSeconds;

List<IDisposable> alarmSchedule = new();
entities.Sensor.DteskePixelNextAlarm.StateChanges().Subscribe(e =>
{
var alarmString = e.New?.State;
var result = DateTimeOffset.TryParse(alarmString, out DateTimeOffset nextAlarm);
nextAlarm = nextAlarm.ToOffset(DateTimeOffset.Now.Offset);
// List<IDisposable> alarmSchedule = new();
// entities.Sensor.DteskePixelNextAlarm.StateChanges().Subscribe(e =>
// {
// var alarmString = e.New?.State;
// var result = DateTimeOffset.TryParse(alarmString, out DateTimeOffset nextAlarm);
// nextAlarm = nextAlarm.ToOffset(DateTimeOffset.Now.Offset);

logger.LogInformation("Detected alarm state change, new alarm time detected as {@alarmString}, parsed as {@nextAlarm}", alarmString, nextAlarm.LocalDateTime);
// Clean up previously scheduled items
foreach (var scheduled in alarmSchedule)
{
scheduled.Dispose();
}
logger.LogDebug("Cleaned up {@count} previously scheduled events", alarmSchedule.Count);
alarmSchedule.Clear();
// logger.LogInformation("Detected alarm state change, new alarm time detected as {@alarmString}, parsed as {@nextAlarm}", alarmString, nextAlarm.LocalDateTime);
// // Clean up previously scheduled items
// foreach (var scheduled in alarmSchedule)
// {
// scheduled.Dispose();
// }
// logger.LogDebug("Cleaned up {@count} previously scheduled events", alarmSchedule.Count);
// alarmSchedule.Clear();

if (result)
{
alarmSchedule.Add(scheduler.Schedule(nextAlarm, () =>
{
bedroomLights.TurnOn(GlobalConfiguration.BRIGHTNESS_HIGH);
ha.Message("Home Schedule", "Bedroom Lights On", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
}));
// if (result)
// {
// alarmSchedule.Add(scheduler.Schedule(nextAlarm, () =>
// {
// bedroomLights.TurnOn(GlobalConfiguration.BRIGHTNESS_HIGH);
// ha.Message("Home Schedule", "Bedroom Lights On", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
// }));

nextAlarm = nextAlarm.Subtract(TimeSpan.FromMinutes(5));
alarmSchedule.Add(scheduler.Schedule(nextAlarm, () =>
{
bedroomLights.TurnOn(GlobalConfiguration.BRIGHTNESS_HIGH, fadeDuration);
}));
ha.Message("Home Schedule", $"Lights scheduled to turn on at {nextAlarm.LocalDateTime}", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
// nextAlarm = nextAlarm.Subtract(TimeSpan.FromMinutes(5));
// alarmSchedule.Add(scheduler.Schedule(nextAlarm, () =>
// {
// bedroomLights.TurnOn(GlobalConfiguration.BRIGHTNESS_HIGH, fadeDuration);
// }));
// ha.Message("Home Schedule", $"Lights scheduled to turn on at {nextAlarm.LocalDateTime}", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);

nextAlarm = nextAlarm.AddMinutes(5).AddHours(2);
alarmSchedule.Add(scheduler.Schedule(nextAlarm, () =>
{
bedroomLights.TurnOff();
ha.Message("Home Schedule", "Bedroom Lignts Off", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
}));
}
else
{
ha.Message("Home Schedule", $"**Unable to parse alarm string!**", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
}
});
// nextAlarm = nextAlarm.AddMinutes(5).AddHours(2);
// alarmSchedule.Add(scheduler.Schedule(nextAlarm, () =>
// {
// bedroomLights.TurnOff();
// ha.Message("Home Schedule", "Bedroom Lignts Off", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
// }));
// }
// else
// {
// ha.Message("Home Schedule", $"**Unable to parse alarm string!**", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
// }
// });

List<IDisposable> sunSchedule = new();
entities.Sun.Sun.StateChanges().Subscribe(e =>
{
var sunsetString = e.New?.Attributes?.NextSetting;
var result = DateTimeOffset.TryParse(sunsetString, out DateTimeOffset sunset);
// List<IDisposable> sunSchedule = new();
// entities.Sun.Sun.StateChanges().Subscribe(e =>
// {
// var sunsetString = e.New?.Attributes?.NextSetting;
// var result = DateTimeOffset.TryParse(sunsetString, out DateTimeOffset sunset);

logger.LogInformation("Detected sun state change, new sun time detected as {@sunString}, parsed as {@nextAlarm}", sunsetString, sunset.LocalDateTime);
// Clean up previously scheduled items
foreach (var scheduled in sunSchedule)
{
scheduled.Dispose();
}
logger.LogDebug("Cleaned up {@count} previously scheduled events", sunSchedule.Count);
sunSchedule.Clear();
// logger.LogInformation("Detected sun state change, new sun time detected as {@sunString}, parsed as {@nextAlarm}", sunsetString, sunset.LocalDateTime);
// // Clean up previously scheduled items
// foreach (var scheduled in sunSchedule)
// {
// scheduled.Dispose();
// }
// logger.LogDebug("Cleaned up {@count} previously scheduled events", sunSchedule.Count);
// sunSchedule.Clear();

if (result)
{
// If we got a sunset from HA, set the schedule for 30 min before that
sunset = sunset.Subtract(TimeSpan.FromMinutes(30));
sunSchedule.Add(scheduler.Schedule(sunset, () =>
{
drivewayLights.TurnOn(GlobalConfiguration.BRIGHTNESS_HIGH);
bedroomLights.TurnOn(GlobalConfiguration.BRIGHTNESS_HIGH);
ha.Message("Home Schedule", "Outside & Bedroom Lights On", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
}));
ha.Message("Home Schedule", $"Lights scheduled to turn on at {sunset.LocalDateTime}", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
}
else
{
ha.Message("Home Schedule", $"**Unable to parse sunset!**", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
}
});
// if (result)
// {
// // If we got a sunset from HA, set the schedule for 30 min before that
// sunset = sunset.Subtract(TimeSpan.FromMinutes(30));
// sunSchedule.Add(scheduler.Schedule(sunset, () =>
// {
// drivewayLights.TurnOn(GlobalConfiguration.BRIGHTNESS_HIGH);
// bedroomLights.TurnOn(GlobalConfiguration.BRIGHTNESS_HIGH);
// ha.Message("Home Schedule", "Outside & Bedroom Lights On", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
// }));
// ha.Message("Home Schedule", $"Lights scheduled to turn on at {sunset.LocalDateTime}", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
// }
// else
// {
// ha.Message("Home Schedule", $"**Unable to parse sunset!**", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
// }
// });

// 11:00 PM
scheduler.ScheduleCron("00 23 * * *", () =>
{
drivewayLights.TurnOff();
ha.Message("Home Schedule", "11:00 PM Outside Lights Off", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
});
// // 11:00 PM
// scheduler.ScheduleCron("00 23 * * *", () =>
// {
// drivewayLights.TurnOff();
// ha.Message("Home Schedule", "11:00 PM Outside Lights Off", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
// });

// 11:15 PM
scheduler.ScheduleCron("15 23 * * *", () =>
{
entities.Light.Lamp.TurnOff(fadeDuration);
entities.Light.Nightstand.TurnOff(fadeDuration);
ha.Message("Home Schedule", "11:15 PM Fade Bedroom Lights", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
});
// // 11:15 PM
// scheduler.ScheduleCron("15 23 * * *", () =>
// {
// entities.Light.Lamp.TurnOff(fadeDuration);
// entities.Light.Nightstand.TurnOff(fadeDuration);
// ha.Message("Home Schedule", "11:15 PM Fade Bedroom Lights", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
// });

// 11:30 PM
scheduler.ScheduleCron("25 23 * * *", () =>
{
entities.Light.ElementsAc4b.TurnOff(fadeDuration);
ha.Message("Home Schedule", "11:25 PM Fade Bedroom Nanoleaf", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
});
// // 11:30 PM
// scheduler.ScheduleCron("25 23 * * *", () =>
// {
// entities.Light.ElementsAc4b.TurnOff(fadeDuration);
// ha.Message("Home Schedule", "11:25 PM Fade Bedroom Nanoleaf", entities.InputBoolean.NetdaemonAutomationsHomeSchedule.EntityId);
// });

}
}
// }
//}
34 changes: 17 additions & 17 deletions apps/LaundryRoomAutomation.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
namespace TeskeHomeAssistant.apps;
//namespace TeskeHomeAssistant.apps;

[NetDaemonApp]
public class LaundryRoomAutomation
{
public LaundryRoomAutomation(IScheduler scheduler, Entities entities, ILogger<LaundryRoomAutomation> logger)
{
var laundryRoomLights = new List<Entity>
{
entities.Light.LaundryRoomLight
};
//[NetDaemonApp]
//public class LaundryRoomAutomation
//{
// public LaundryRoomAutomation(IScheduler scheduler, Entities entities, ILogger<LaundryRoomAutomation> logger)
// {
// var laundryRoomLights = new List<Entity>
// {
// entities.Light.LaundryRoomLight
// };

new MotionBuilder(entities.BinarySensor.LaundryRoomSensorMotion, scheduler, logger)
.WithMotionAllowed(entities.Switch.LaundryRoomSensorMotion)
.WithOnAction(_ => laundryRoomLights.TurnOn(60))
.WithOffAction(_ => laundryRoomLights.TurnOff(), TimeSpan.FromMinutes(5))
.Build();
}
}
// new MotionBuilder(entities.BinarySensor.LaundryRoomSensorMotion, scheduler, logger)
// .WithMotionAllowed(entities.Switch.LaundryRoomSensorMotion)
// .WithOnAction(_ => laundryRoomLights.TurnOn(60))
// .WithOffAction(_ => laundryRoomLights.TurnOff(), TimeSpan.FromMinutes(5))
// .Build();
// }
//}
Loading

0 comments on commit 4e349bb

Please sign in to comment.