Implemented early light
This commit is contained in:
parent
4cb31afdb8
commit
36bd835412
1 changed files with 43 additions and 8 deletions
|
@ -1,5 +1,7 @@
|
||||||
|
from typing import Dict
|
||||||
from interface.philips_hue import PhilipsHue
|
from interface.philips_hue import PhilipsHue
|
||||||
from sensor.people_counter import PeopleCounter
|
from sensor.people_counter import PeopleCounter
|
||||||
|
from sensor.tof_sensor import Directions
|
||||||
from sensor.vl53l1x_sensor import VL53L1XSensor
|
from sensor.vl53l1x_sensor import VL53L1XSensor
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -15,18 +17,22 @@ hue_conf = {
|
||||||
hue = PhilipsHue(hue_conf)
|
hue = PhilipsHue(hue_conf)
|
||||||
counter = PeopleCounter(VL53L1XSensor())
|
counter = PeopleCounter(VL53L1XSensor())
|
||||||
peopleCount = 0
|
peopleCount = 0
|
||||||
|
early_light_state = False
|
||||||
|
|
||||||
logging.getLogger().setLevel(logging.INFO)
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
def count_change(change: int) -> None:
|
def count_change(change: int) -> None:
|
||||||
|
global hue
|
||||||
global peopleCount
|
global peopleCount
|
||||||
|
global early_light_state
|
||||||
|
|
||||||
# Are lights on at the moment?
|
# Are lights on at the moment?
|
||||||
previous_lights_state = hue.get_group(hue_conf['light_group'])['state']['any_on']
|
previous_lights_state = hue.get_group(hue_conf['light_group'])[
|
||||||
|
'state']['any_on']
|
||||||
|
|
||||||
# Apply correction
|
# Apply correction
|
||||||
if peopleCount <= 0 and previous_lights_state:
|
if peopleCount <= 0 and previous_lights_state and not early_light_state:
|
||||||
# User indicates, that people count was not actually 0
|
# User indicates, that people count was not actually 0
|
||||||
peopleCount = 1
|
peopleCount = 1
|
||||||
logging.debug(f'People count corrected to {peopleCount}')
|
logging.debug(f'People count corrected to {peopleCount}')
|
||||||
|
@ -45,11 +51,40 @@ def count_change(change: int) -> None:
|
||||||
|
|
||||||
# Return, if there is no change
|
# Return, if there is no change
|
||||||
if previous_lights_state == target_light_state:
|
if previous_lights_state == target_light_state:
|
||||||
|
if previous_lights_state:
|
||||||
|
early_light_state = False
|
||||||
return
|
return
|
||||||
|
|
||||||
hue.set_group(hue_conf['light_group'], {'on': target_light_state})
|
hue.set_group(hue_conf['light_group'], {'on': target_light_state})
|
||||||
logging.debug(f'Light state changed to {target_light_state}')
|
logging.debug(f'Light state changed to {target_light_state}')
|
||||||
|
|
||||||
|
|
||||||
|
def trigger_change(triggerState: Dict):
|
||||||
|
global hue
|
||||||
|
global early_light_state
|
||||||
|
|
||||||
|
target_light_state = None
|
||||||
|
|
||||||
|
# Is someone walking close to the door?
|
||||||
|
target_light_state = triggerState[Directions.INSIDE] or triggerState[Directions.OUTSIDE]
|
||||||
|
|
||||||
|
# Only look at changing situations
|
||||||
|
if target_light_state == early_light_state:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Are lights on at the moment?
|
||||||
|
previous_lights_state = hue.get_group(hue_conf['light_group'])['state']['any_on']
|
||||||
|
if target_light_state == previous_lights_state:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Adjust light as necessary
|
||||||
|
hue.set_group(hue_conf['light_group'], {'on': target_light_state})
|
||||||
|
logging.debug(f'Light state changed to {target_light_state}')
|
||||||
|
|
||||||
|
early_light_state = target_light_state
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
counter.hookCounting(count_change)
|
counter.hookCounting(count_change)
|
||||||
|
counter.hookTrigger(trigger_change)
|
||||||
counter.run()
|
counter.run()
|
||||||
|
|
Loading…
Reference in a new issue