private void SetupFan(StateMachine stateMachine, IArea room, HSREL5 hsrel5)
        {
            var fanPort0 = hsrel5.GetOutput(4);
            var fanPort1 = hsrel5.GetOutput(5);

            stateMachine.AddOffState().WithOutput(fanPort0, BinaryState.Low).WithOutput(fanPort1, BinaryState.Low);
            stateMachine.AddState(new StatefulComponentState("1")).WithOutput(fanPort0, BinaryState.High).WithOutput(fanPort1, BinaryState.Low);
            stateMachine.AddState(new StatefulComponentState("2")).WithOutput(fanPort0, BinaryState.High).WithOutput(fanPort1, BinaryState.High);
            stateMachine.TryTurnOff();
        }
        public void Setup()
        {
            const int SensorPin = 4;

            var i2cHardwareBridge = _controller.Device <I2CHardwareBridge>();

            var bathroom = _controller.CreateArea(Room.UpperBathroom)
                           .WithTemperatureSensor(UpperBathroom.TemperatureSensor, i2cHardwareBridge.DHT22Accessor.GetTemperatureSensor(SensorPin))
                           .WithHumiditySensor(UpperBathroom.HumiditySensor, i2cHardwareBridge.DHT22Accessor.GetHumiditySensor(SensorPin))
                           .WithMotionDetector(UpperBathroom.MotionDetector, _input5.GetInput(15))
                           .WithLamp(UpperBathroom.LightCeilingDoor, _hsrel5.GetOutput(0))
                           .WithLamp(UpperBathroom.LightCeilingEdge, _hsrel5.GetOutput(1))
                           .WithLamp(UpperBathroom.LightCeilingMirrorCabinet, _hsrel5.GetOutput(2))
                           .WithLamp(UpperBathroom.LampMirrorCabinet, _hsrel5.GetOutput(3))
                           .WithStateMachine(UpperBathroom.Fan, SetupFan);

            var combinedLights =
                bathroom.CombineActuators(UpperBathroom.CombinedCeilingLights)
                .WithActuator(bathroom.Lamp(UpperBathroom.LightCeilingDoor))
                .WithActuator(bathroom.Lamp(UpperBathroom.LightCeilingEdge))
                .WithActuator(bathroom.Lamp(UpperBathroom.LightCeilingMirrorCabinet))
                .WithActuator(bathroom.Lamp(UpperBathroom.LampMirrorCabinet));

            bathroom.SetupTurnOnAndOffAutomation()
            .WithTrigger(bathroom.MotionDetector(UpperBathroom.MotionDetector))
            .WithTarget(combinedLights)
            .WithOnDuration(TimeSpan.FromMinutes(8));

            new BathroomFanAutomation(AutomationIdFactory.CreateIdFrom <BathroomFanAutomation>(bathroom), _controller.Timer)
            .WithTrigger(bathroom.MotionDetector(UpperBathroom.MotionDetector))
            .WithSlowDuration(TimeSpan.FromMinutes(8))
            .WithFastDuration(TimeSpan.FromMinutes(12))
            .WithActuator(bathroom.StateMachine(UpperBathroom.Fan));
        }
Esempio n. 3
0
        public void Setup()
        {
            var       i2cHardwareBridge = _controller.Device <I2CHardwareBridge>();
            const int SensorPin         = 6;

            var bedroom = _controller.CreateArea(Room.Bedroom)
                          .WithTemperatureSensor(Bedroom.TemperatureSensor, i2cHardwareBridge.DHT22Accessor.GetTemperatureSensor(SensorPin))
                          .WithHumiditySensor(Bedroom.HumiditySensor, i2cHardwareBridge.DHT22Accessor.GetHumiditySensor(SensorPin))
                          .WithMotionDetector(Bedroom.MotionDetector, _input5.GetInput(12))
                          .WithLamp(Bedroom.LightCeiling, _hsrel5.GetOutput(5).WithInvertedState())
                          .WithLamp(Bedroom.LightCeilingWindow, _hsrel5.GetOutput(6).WithInvertedState())
                          .WithLamp(Bedroom.LightCeilingWall, _hsrel5.GetOutput(7).WithInvertedState())
                          .WithSocket(Bedroom.SocketWindowLeft, _hsrel5.GetOutput(0))
                          .WithSocket(Bedroom.SocketWindowRight, _hsrel5.GetOutput(1))
                          .WithSocket(Bedroom.SocketWall, _hsrel5.GetOutput(2))
                          .WithSocket(Bedroom.SocketWallEdge, _hsrel5.GetOutput(3))
                          .WithSocket(Bedroom.SocketBedLeft, _hsrel8.GetOutput(7))
                          .WithSocket(Bedroom.SocketBedRight, _hsrel8.GetOutput(9))
                          .WithLamp(Bedroom.LampBedLeft, _hsrel5.GetOutput(4))
                          .WithLamp(Bedroom.LampBedRight, _hsrel8.GetOutput(8).WithInvertedState())
                          .WithButton(Bedroom.ButtonDoor, _input5.GetInput(11))
                          .WithButton(Bedroom.ButtonWindowUpper, _input5.GetInput(10))
                          .WithButton(Bedroom.ButtonWindowLower, _input5.GetInput(13))
                          .WithButton(Bedroom.ButtonBedLeftInner, _input4.GetInput(2))
                          .WithButton(Bedroom.ButtonBedLeftOuter, _input4.GetInput(0))
                          .WithButton(Bedroom.ButtonBedRightInner, _input4.GetInput(1))
                          .WithButton(Bedroom.ButtonBedRightOuter, _input4.GetInput(3))
                          .WithRollerShutter(Bedroom.RollerShutterLeft, _hsrel8.GetOutput(6), _hsrel8.GetOutput(5))
                          .WithRollerShutter(Bedroom.RollerShutterRight, _hsrel8.GetOutput(3), _hsrel8.GetOutput(4))
                          .WithRollerShutterButtons(Bedroom.RollerShutterButtonsUpper, _input5.GetInput(6), _input5.GetInput(7))
                          .WithRollerShutterButtons(Bedroom.RollerShutterButtonsLower, _input5.GetInput(4), _input5.GetInput(5))
                          .WithWindow(Bedroom.WindowLeft, w => w.WithCenterCasement(_input5.GetInput(2)))
                          .WithWindow(Bedroom.WindowRight, w => w.WithCenterCasement(_input5.GetInput(3)));

            bedroom.RollerShutter(Bedroom.RollerShutterLeft)
            .ConnectWith(bedroom.RollerShutterButtons(Bedroom.RollerShutterButtonsUpper));
            bedroom.RollerShutter(Bedroom.RollerShutterRight)
            .ConnectWith(bedroom.RollerShutterButtons(Bedroom.RollerShutterButtonsLower));

            bedroom.CombineActuators(Bedroom.CombinedCeilingLights)
            .WithActuator(bedroom.Lamp(Bedroom.LightCeilingWall))
            .WithActuator(bedroom.Lamp(Bedroom.LightCeilingWindow))
            .ConnectToggleActionWith(bedroom.Button(Bedroom.ButtonDoor))
            .ConnectToggleActionWith(bedroom.Button(Bedroom.ButtonWindowUpper));

            bedroom.Button(Bedroom.ButtonDoor).WithLongAction(() =>
            {
                bedroom.Lamp(Bedroom.LampBedLeft).TurnOff();
                bedroom.Lamp(Bedroom.LampBedRight).TurnOff();
                bedroom.Lamp(Bedroom.CombinedCeilingLights).TurnOff();
            });

            bedroom.SetupRollerShutterAutomation()
            .WithRollerShutters(bedroom.GetAllRollerShutters())
            .WithDoNotOpenBefore(TimeSpan.FromHours(7).Add(TimeSpan.FromMinutes(15)))
            .WithCloseIfOutsideTemperatureIsGreaterThan(24)
            .WithDoNotOpenIfOutsideTemperatureIsBelowThan(3);

            bedroom.SetupTurnOnAndOffAutomation()
            .WithTrigger(bedroom.MotionDetector(Bedroom.MotionDetector))
            .WithTarget(bedroom.BinaryStateOutput(Bedroom.LightCeiling))
            .WithOnDuration(TimeSpan.FromSeconds(15))
            .WithTurnOnIfAllRollerShuttersClosed(bedroom.RollerShutter(Bedroom.RollerShutterLeft), bedroom.RollerShutter(Bedroom.RollerShutterRight))
            .WithEnabledAtNight(_controller.Device <IWeatherStation>())
            .WithSkipIfAnyActuatorIsAlreadyOn(bedroom.Lamp(Bedroom.LampBedLeft), bedroom.Lamp(Bedroom.LampBedRight));

            bedroom.WithStateMachine(Bedroom.Fan, SetupFan);

            bedroom.Button(Bedroom.ButtonBedLeftInner).WithShortAction(() => bedroom.Lamp(Bedroom.LampBedLeft).Toggle());
            bedroom.Button(Bedroom.ButtonBedLeftInner).WithLongAction(() => bedroom.BinaryStateOutput(Bedroom.CombinedCeilingLights).Toggle());
            bedroom.Button(Bedroom.ButtonBedLeftOuter).WithShortAction(() => bedroom.StateMachine(Bedroom.Fan).SetNextState());
            bedroom.Button(Bedroom.ButtonBedLeftOuter).WithLongAction(() => bedroom.StateMachine(Bedroom.Fan).TurnOff());

            bedroom.Button(Bedroom.ButtonBedRightInner).WithShortAction(() => bedroom.Lamp(Bedroom.LampBedRight).Toggle());
            bedroom.Button(Bedroom.ButtonBedRightInner).WithLongAction(() => bedroom.BinaryStateOutput(Bedroom.CombinedCeilingLights).Toggle());
            bedroom.Button(Bedroom.ButtonBedRightOuter).WithShortAction(() => bedroom.StateMachine(Bedroom.Fan).SetNextState());
            bedroom.Button(Bedroom.ButtonBedRightOuter).WithLongAction(() => bedroom.StateMachine(Bedroom.Fan).TurnOff());
        }