Dinner presence

This commit is contained in:
2026-09-15 10:49:12 +03:00
parent 9108ba9c8f
commit d1bdd2eb67
+29 -2
View File
@@ -45,8 +45,8 @@ eventLights = AFRP.changes >>> arr (fmap presenceLights)
presenceLights Occupied = LightsOn presenceLights Occupied = LightsOn
presenceLights Unoccupied = LightsOff presenceLights Unoccupied = LightsOff
kitchenMotionController :: HASS (Event Value) () kitchenCeilingController :: HASS (Event Value) ()
kitchenMotionController = proc x -> do kitchenCeilingController = proc x -> do
now <- AFRP.currentTime -< () now <- AFRP.currentTime -< ()
p <- kitchenMotion >>> kitchenPresence -< x p <- kitchenMotion >>> kitchenPresence -< x
ev <- eventLights -< p ev <- eventLights -< p
@@ -57,3 +57,30 @@ kitchenMotionController = proc x -> do
_ -> returnA -< () _ -> returnA -< ()
where where
lightsAllowed (LocalTime _ tod) = not (tod > TimeOfDay 1 45 0 && tod < TimeOfDay 5 0 0) lightsAllowed (LocalTime _ tod) = not (tod > TimeOfDay 1 45 0 && tod < TimeOfDay 5 0 0)
dinnerLightLevel :: HASS (Event Value) Int
dinnerLightLevel = entityRead "sensor.sijainti_keittio_light_level" >>> AFRP.hold 0
dinnerPresence :: HASS (Event Value) Presence
dinnerPresence = presence "binary_sensor.sijainti_keittio_occupancy" >>> AFRP.hold Unoccupied
dinnerLightEvents :: HASS (Event Value) (Event Lights)
dinnerLightEvents = ((,) <$> dinnerLightLevel <*> dinnerPresence)
>>> arr lightWanted
>>> AFRP.changes
>>> arr (fmap (bool LightsOff LightsOn))
where
-- This means that both light level and occupancy can change the light state
lightWanted (lightLevel, occ) = occ == Occupied && lightLevel < 13
dinnerTableController :: HASS (Event Value) ()
dinnerTableController = proc x -> do
ev <- dinnerLightEvents -< x
case ev of
Event LightsOn -> callServiceDyn (light [EntityId "light.kitchen_dining_large"]) -< On Nothing
Event LightsOff -> callServiceDyn (light [EntityId "light.kitchen_dining_large"]) -< Off
_ -> returnA -< ()
kitchenMotionController :: HASS (Event Value) ()
kitchenMotionController = kitchenCeilingController <> dinnerTableController