-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
3,336 additions
and
3,722 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
// }); | ||
|
||
} | ||
} | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
// }); | ||
|
||
} | ||
} | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
// } | ||
//} |
Oops, something went wrong.