Turn on sleep mode only if there are any lights already on
This commit is contained in:
1 parent
5f8b3cbe00
commit
889ad1c091
1 file changed
+5
-2
@@ -64,7 +64,8 @@ bedroomPresenceController :: HASS (Event Value) ()
|
|||||||
bedroomPresenceController = proc x -> do
|
bedroomPresenceController = proc x -> do
|
||||||
p <- presenceLightEvents >>> traceEvent -< x
|
p <- presenceLightEvents >>> traceEvent -< x
|
||||||
capped <- lightLevel >>> arr (< 4) -< x
|
capped <- lightLevel >>> arr (< 4) -< x
|
||||||
snap <- (doSnapshot &&& bedroomLightStatus) >>> AFRP.snapshot M.empty >>> arr Snapshot -< x
|
st <- bedroomLightStatus -< x
|
||||||
|
snap <- first doSnapshot >>> AFRP.snapshot M.empty >>> arr Snapshot -< (x,st)
|
||||||
-- This line is just for debugging
|
-- This line is just for debugging
|
||||||
_ <- AFRP.changes >>> traceEvent -< snap
|
_ <- AFRP.changes >>> traceEvent -< snap
|
||||||
case p of
|
case p of
|
||||||
@@ -73,10 +74,12 @@ bedroomPresenceController = proc x -> do
|
|||||||
Event LightingOn -> do
|
Event LightingOn -> do
|
||||||
callServicesDyn "Turn on lights (capped)" (\(c,xs) -> concatMap (uncurry (toLight c)) xs) -< (capped, M.toList (getSnapshot snap))
|
callServicesDyn "Turn on lights (capped)" (\(c,xs) -> concatMap (uncurry (toLight c)) xs) -< (capped, M.toList (getSnapshot snap))
|
||||||
returnA -< ()
|
returnA -< ()
|
||||||
Event LightingSleep -> do
|
Event LightingSleep | anyLightsAreOn st -> do
|
||||||
callService "Turn on sleep" (activateScene "scene.makuuhuone_lepotila") -< ()
|
callService "Turn on sleep" (activateScene "scene.makuuhuone_lepotila") -< ()
|
||||||
_ -> returnA -< ()
|
_ -> returnA -< ()
|
||||||
where
|
where
|
||||||
|
anyLightsAreOn :: Foldable f => f LightObservation -> Bool
|
||||||
|
anyLightsAreOn = any observedOn
|
||||||
toLight :: Bool -> T.Text -> LightObservation -> [Service]
|
toLight :: Bool -> T.Text -> LightObservation -> [Service]
|
||||||
toLight _ entityId LightObservation{observedOn=False} = [light [EntityId entityId] Off]
|
toLight _ entityId LightObservation{observedOn=False} = [light [EntityId entityId] Off]
|
||||||
toLight capped entityId LightObservation{observedOn=True, observedTemperature=t, observedBrightness=b} =
|
toLight capped entityId LightObservation{observedOn=True, observedTemperature=t, observedBrightness=b} =
|
||||||
|
|||||||
Reference in new issue
Block a user