Untested three-state for dinner table
This commit is contained in:
@@ -6,14 +6,13 @@ import AFRP (Event (..))
|
|||||||
import qualified AFRP
|
import qualified AFRP
|
||||||
import Data.Aeson (Value)
|
import Data.Aeson (Value)
|
||||||
import Control.Arrow ((>>>), Arrow (..), returnA)
|
import Control.Arrow ((>>>), Arrow (..), returnA)
|
||||||
import Data.Bool (bool)
|
|
||||||
import Prelude hiding (id)
|
import Prelude hiding (id)
|
||||||
import Data.Time (LocalTime(..), TimeOfDay (..))
|
import Data.Time (LocalTime(..), TimeOfDay (..))
|
||||||
|
|
||||||
|
|
||||||
-- Kitchen has two "presence" sensors. One IKEA motion sensor and one SwitchBot presence sensor
|
-- Kitchen has two "presence" sensors. One IKEA motion sensor and one SwitchBot presence sensor
|
||||||
|
|
||||||
data Lights = LightsOn | LightsOff
|
data Lights = LightsOn | LightsOff | LightsSleep
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
kitchenPresence :: HASS (Event Value) Presence
|
kitchenPresence :: HASS (Event Value) Presence
|
||||||
@@ -46,21 +45,43 @@ dinnerPresence :: HASS (Event Value) Presence
|
|||||||
dinnerPresence = presence "binary_sensor.sijainti_keittio_occupancy" >>> AFRP.hold Unoccupied
|
dinnerPresence = presence "binary_sensor.sijainti_keittio_occupancy" >>> AFRP.hold Unoccupied
|
||||||
|
|
||||||
dinnerLightEvents :: HASS (Event Value) (Event Lights)
|
dinnerLightEvents :: HASS (Event Value) (Event Lights)
|
||||||
dinnerLightEvents = ((,) <$> dinnerLightLevel <*> dinnerPresence)
|
dinnerLightEvents =
|
||||||
|
((,) <$> dinnerLightLevel <*> dinnerPresence)
|
||||||
>>> arr lightWanted
|
>>> arr lightWanted
|
||||||
>>> AFRP.changes
|
>>> (sleepEvent &&& offEvent &&& onEvent)
|
||||||
>>> arr (fmap (bool LightsOff LightsOn))
|
>>> arr (\(s, (o, n)) -> s `AFRP.lMerge` o `AFRP.lMerge` n)
|
||||||
where
|
where
|
||||||
-- This means that both light level and occupancy can change the light state
|
|
||||||
lightWanted (lightLevel, occ) = occ == Occupied && lightLevel < 13
|
lightWanted (lightLevel, occ) = occ == Occupied && lightLevel < 13
|
||||||
|
|
||||||
|
onEvent =
|
||||||
|
AFRP.edge
|
||||||
|
>>> arr (fmap (const LightsOn))
|
||||||
|
|
||||||
|
sleepEvent =
|
||||||
|
arr not
|
||||||
|
>>> AFRP.edge
|
||||||
|
>>> arr (fmap (const LightsSleep))
|
||||||
|
|
||||||
|
offEvent =
|
||||||
|
arr not
|
||||||
|
>>> AFRP.waitFor 300
|
||||||
|
>>> arr (fmap (const LightsOff))
|
||||||
|
|
||||||
dinnerTableController :: HASS (Event Value) ()
|
dinnerTableController :: HASS (Event Value) ()
|
||||||
dinnerTableController = proc x -> do
|
dinnerTableController = proc x -> do
|
||||||
ev <- dinnerLightEvents -< x
|
ev <- dinnerLightEvents -< x
|
||||||
case ev of
|
case ev of
|
||||||
Event LightsOn -> callServiceDyn (light [EntityId "light.kitchen_dining_large"]) -< On Nothing
|
Event LightsOn -> do
|
||||||
Event LightsOff -> callServiceDyn (light [EntityId "light.kitchen_dining_large"]) -< Off
|
sleep -< False
|
||||||
|
callServiceDyn (light [EntityId "light.kitchen_dining_large"]) -< On Nothing
|
||||||
|
Event LightsOff -> do
|
||||||
|
sleep -< False
|
||||||
|
callServiceDyn (light [EntityId "light.kitchen_dining_large"]) -< Off
|
||||||
|
Event LightsSleep -> do
|
||||||
|
sleep -< True
|
||||||
_ -> returnA -< ()
|
_ -> returnA -< ()
|
||||||
|
where
|
||||||
|
sleep = callServiceDyn (switch [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"])
|
||||||
|
|
||||||
kitchenMotionController :: HASS (Event Value) ()
|
kitchenMotionController :: HASS (Event Value) ()
|
||||||
kitchenMotionController = kitchenCeilingController <> dinnerTableController
|
kitchenMotionController = kitchenCeilingController <> dinnerTableController
|
||||||
|
|||||||
Reference in New Issue
Block a user