reactive-banana-automation-0.1.1: home (etc) automation using reactive-banana

Safe HaskellNone
LanguageHaskell98

Reactive.Banana.Automation.Examples

Description

Automation examples. View source for the code.

These examples are tested by doctest when building this library.

Patches adding examples welcomed!

Synopsis

Documentation

data Sensors Source #

We'll use a single Sensors type containing all the sensors used by the examples below.

data Actuators Source #

And a single Actuators type containing all the actuators used by the examples below.

mkSensors :: IO Sensors Source #

For running the examples, you'll need this, to construct a Sensors

fridge :: Automation Sensors Actuators Source #

A fridge, containing the fridgeTemperature sensor and with its power controlled by the FridgePower actuator.

The fridge starts running when its temperature exceeds a maximum safe value. Once the temperature falls below a minimim value, the fridge stops running. Note that opening the door of this fridge for a minute typically won't cause it to run, unless it was already close to being too warm. This behavior was chosen to minimise starts of the compressor, but of course other fridge behaviors are also possible; this is only an example.

To give this example a try, import this module in ghci and run:

>>> runner <- observeAutomation fridge mkSensors
>>> runner $ \sensors -> fridgeTemperature sensors =: 6
[FridgePower PowerOn]
>>> runner $ \sensors -> fridgeTemperature sensors =: 3
[]
>>> runner $ \sensors -> fridgeTemperature sensors =: 0.5
[FridgePower PowerOff]

motionActivatedLight :: Automation Sensors Actuators Source #

A light that comes on when the motionSensor detects movement, and remains on for 5 minutes after the last movement.

If this were run in real code, the motion sensor would be triggered by running sensedNow.

But, for testing, it's useful to specify the time that the sensor is triggered, using sensedAt. Import this module in ghci and run:

>>> runner <- observeAutomation motionActivatedLight mkSensors
>>> runner $ \sensors -> sensedAt 0 (motionSensor sensors) True
[LightSwitch PowerOn]
>>> runner $ \sensors -> sensedAt 30 (motionSensor sensors) False
[]
>>> runner $ \sensors -> sensedAt 60 (motionSensor sensors) True
[LightSwitch PowerOn]
>>> runner $ \sensors -> sensedAt 120 (motionSensor sensors) False
[]
>>> runner $ \sensors -> sensedAt 400 (motionSensor sensors) False
[LightSwitch PowerOff]