Skip to content

Commit

Permalink
program buttons together
Browse files Browse the repository at this point in the history
  • Loading branch information
dteske25 committed Jan 29, 2024
1 parent c69e9d3 commit a3277c1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Enums/ZigbeeEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public enum ZigbeeButtonCommands
public enum ZigbeeDeviceName
{
Unknown = 0,
LivingRoomButton,
MeganBedroomButton,
LivingRoomSwitch,
LivingRoomOutlet,
LivingRoomTable,
OfficeButton,
HallwaySwitch,
MasterBedroomButton
DaricBedroomButton
}
}
4 changes: 2 additions & 2 deletions GlobalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public static int GetBrightness()

public static string GetZigbeeDeviceId(ZigbeeDeviceName device) => device switch
{
ZigbeeDeviceName.LivingRoomButton => "00:12:4b:00:25:16:bd:64",
ZigbeeDeviceName.LivingRoomSwitch => "84:fd:27:ff:fe:bc:cc:8e",
ZigbeeDeviceName.LivingRoomOutlet => "00:12:4b:00:25:3d:67:7f",
ZigbeeDeviceName.LivingRoomTable => "00:12:4b:00:25:3d:6a:08",
ZigbeeDeviceName.OfficeButton => "00:12:4b:00:25:14:6f:60",
ZigbeeDeviceName.HallwaySwitch => "84:fd:27:ff:fe:bc:cc:65",
ZigbeeDeviceName.MasterBedroomButton => "00:12:4b:00:25:16:b2:ca",
ZigbeeDeviceName.MeganBedroomButton => "00:12:4b:00:25:16:bd:64",
ZigbeeDeviceName.DaricBedroomButton => "00:12:4b:00:25:16:b2:ca",
_ => ""
};

Expand Down
9 changes: 9 additions & 0 deletions Helpers/ZigbeeEventHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ public static IObservable<Event<ZhaEventData>> Where(this IObservable<Event> eve
.Where(e => e.Data?.DeviceIeee == deviceId && e.Data?.Command == command);
}

public static IObservable<Event<ZhaEventData>> Where(this IObservable<Event> eventSource, IEnumerable<ZigbeeDeviceName> zigbeeDeviceNames, ZigbeeButtonCommands buttonCommand)
{
var deviceIds = zigbeeDeviceNames.Select(GlobalConfiguration.GetZigbeeDeviceId).ToHashSet();

var command = GlobalConfiguration.GetZigbeeCommand(buttonCommand);
return eventSource.Filter<ZhaEventData>("zha_event")
.Where(e => deviceIds.Contains(e.Data?.DeviceIeee ?? "") && e.Data?.Command == command);
}

public static IObservable<Event<ZhaEventData>> Where(this IObservable<Event> eventSource, ZigbeeDeviceName zigbeeDeviceName, ZigbeeSwitchCommands switchCommands)
{
var deviceId = GlobalConfiguration.GetZigbeeDeviceId(zigbeeDeviceName);
Expand Down
12 changes: 9 additions & 3 deletions apps/BedroomAutomation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@ public BedroomAutomation(IScheduler scheduler, IHaContext ha, Entities entities)
{
var dimmer = new Dimmer(100, 20, 2);

ha.Events.Where(ZigbeeDeviceName.MasterBedroomButton, ZigbeeButtonCommands.LongPress).Subscribe(_ =>
var buttons = new List<ZigbeeDeviceName>
{
ZigbeeDeviceName.DaricBedroomButton,
ZigbeeDeviceName.MeganBedroomButton
};

ha.Events.Where(buttons, ZigbeeButtonCommands.LongPress).Subscribe(_ =>
{
entities.Light.BedroomFan.TurnOff();
entities.Light.BedroomLamp.TurnOff();
entities.Light.BedroomLamp2.TurnOff();
dimmer.SetStep(1);
});

ha.Events.Where(ZigbeeDeviceName.MasterBedroomButton, ZigbeeButtonCommands.Press).Subscribe(_ =>
ha.Events.Where(buttons, ZigbeeButtonCommands.Press).Subscribe(_ =>
{
var brightnessPercentage = dimmer.Next();
entities.Light.BedroomLamp.TurnOn(brightnessPct: brightnessPercentage);
entities.Light.BedroomLamp2.TurnOn(brightnessPct: brightnessPercentage);
});

ha.Events.Where(ZigbeeDeviceName.MasterBedroomButton, ZigbeeButtonCommands.DoublePress).Subscribe(_ =>
ha.Events.Where(buttons, ZigbeeButtonCommands.DoublePress).Subscribe(_ =>
{
entities.Light.BedroomFan.Toggle();
});
Expand Down

0 comments on commit a3277c1

Please sign in to comment.