Compare commits

..

9 Commits

12 changed files with 266 additions and 21 deletions

View File

@@ -12,7 +12,6 @@ appdaemon:
ha_url: http://10.0.0.21:8123
token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJiZThhYWI2ZTlkNmQ0NWU2YTk1ODU5OWJjOWM3MWJkYiIsImlhdCI6MTc3NjEwOTc0NCwiZXhwIjoyMDkxNDY5NzQ0fQ.BorkjFjWlWCZqnUa9-NMUxGsDiupDoRZ3cEgsmeSofM
cert_verify: True
q_timeout: 1200
ws_timeout: 00:10:00
http:
url: http://0.0.0.0:5050

View File

@@ -181,7 +181,7 @@ class AlarmClock(SmartObject):
wakeup_in = value
if wakeup_in > 0:
self.handle_prewakueup_cb = self.run_in(self.on_pre_wakeup, 5 * 60,wakeup_in = wakeup_in - 5)
self.handle_prewakueup_cb = self.run_in(self.on_pre_wakeup, 1 * 60,wakeup_in = wakeup_in - 1)
wakeup_message = "On se reveil dans " + str(wakeup_in) + " minutes"

78
apps/global/heating.yaml Normal file
View File

@@ -0,0 +1,78 @@
heating_sensors:
module: virtualsensors
class: VirtualSensorsApp
priority: 10 # default priority app is 50, since most of them require sensors created by virtual sensors, it's important that virtual_sensors start first
sensors:
binary_sensor.heatpump_winter_mode:
trigger_conditions: false #sensor.month >= 10 or sensor.month <= 4
value_selector.target_temperature_heatpump:
attributes:
unit_of_measurement: °C
device_class: temperature
icon: mdi:thermometer
values:
winter_mode:
conditions: binary_sensor.heatpump_winter_mode
value: 18
default:
conditions: True
value: 27
smart_heating_templates_library:
module: templatelibrary
class: TemplateLibrary
priority: 1
templates_library:
clim_conditions:
trigger_conditions:
- "not binary_sensor.heatpump_winter_mode and (ext_temperature >= room_temperature or ext_temperature >= target_temperature or cant_open_window) and room_temperature >= (quick_resume ? target_temperature : (target_temperature + 1))"
- not binary_sensor.heatpump_winter_mode and self and (ext_temperature >= target_temperature or cant_open_window)
- binary_sensor.heatpump_winter_mode and room_temperature <= (target_temperature - 1) and ext_temperature <= 10
- binary_sensor.heatpump_winter_mode and self and room_temperature < target_temperature
blocking_conditions:
- binary_sensor.is_everybody_sleeping and not sleeping_in_the_room and not stay_on_while_sleeping
- not room_occupancy
- not binary_sensor.someone_home #and not (binary_sensor.someone_in_town and sensor.day_interval == 'Nuit')
- window_open
desk_heatpump:
module: smartheatpump
class: SmartHeatpump
entity: climate.desk_heatpump
templates_library: smart_heating_templates_library
constants:
window_open: binary_sensor.desk_window
ext_temperature: sensor.ext_front_temperature
room_temperature: sensor.desk_temperature
room_occupancy: binary_sensor.desk_occupancy
target_temperature: sensor.target_temperature_heatpump
cant_open_window: false #binary_sensor.cant_open_window
sleeping_in_the_room: false #binary_sensor.is_bureau_sleeping
quick_resume: binary_sensor.desk_heatpump_quick_resume
stay_on_while_sleeping: false
virtual_sensors:
sensors:
value_selector.desk_heatpump_fan_mode:
auto: binary_sensor.heatpump_winter_mode
quiet: True
target_temperature: sensor.target_temperature_heatpump
hvac_mode: "binary_sensor.heatpump_winter_mode ? 'heat' : 'cool'"
fan_mode: sensor.desk_heatpump_fan_mode
smart_conditions:
callback_delay: 10 # on the morning it can happen that we ask to start and stop the heat pump immediately afterwards which in result in the heat pump ignoring the second command
template_conditions: <clim_conditions>
quick_resume:
sensor: binary_sensor.desk_heatpump_quick_resume
reset_event: good_morning
#input_buttons:
# turn_on: input_button.clim_du_bureau_turn_on
# turn_off: input_button.clim_du_bureau_turn_off

View File

@@ -14,12 +14,18 @@ motion_tracker:
restroom:
motion_sensors: binary_sensor.restroom_motion
garage:
motion_sensors: binary_sensor.garage_motion
door_generate_motion: true
motion_sensors:
- binary_sensor.garage_motion
door_sensors:
- binary_sensor.garage_entrance
- binary_sensor.garage_door
kitchen:
motion_sensors: binary_sensor.kitchen_motion
mezzanine:
motion_sensors: binary_sensor.mezzanine_motion
living_room:
update_on_both_front: true
motion_sensors: binary_sensor.living_room_presence_presence
occupancy_sensors:
@@ -28,9 +34,15 @@ occupancy_sensors:
priority: 8 # default priority app is 50, since most of them require sensors created by virtual sensors, it's important that virtual_sensors start first
sensors:
binary_sensor.occupancy_living_room:
binary_sensor.living_room_occupancy:
trigger_conditions: sensor.living_room_last_motion <= 5
binary_sensor.occupancy_kitchen:
binary_sensor.kitchen_occupancy:
trigger_conditions: sensor.kitchen_last_motion <= 5
binary_sensor.occupancy_restroom:
binary_sensor.restroom_occupancy:
trigger_conditions: sensor.restroom_last_motion <= 3
retain_condition.desk_occupancy:
retain_time: 5 * 60
conditions:
trigger_conditions:
- binary_sensor.alienware_r10
- sensor.macbook_m3_pro_de_pierre_frontmost_app != 'loginwindow' and sensor.macbook_m3_pro_de_pierre_displays == 2

View File

@@ -0,0 +1,14 @@
virtual_sensors:
module: virtualsensors
class: VirtualSensorsApp
priority: 10 # default priority app is 50, since most of them require sensors created by virtual sensors, it's important that virtual_sensors start first
sensors:
continuous_condition.is_apple_tv_idle:
time: 5
conditions: media_player.apple_tv == 'paused' or media_player.apple_tv == 'idle' or media_player.apple_tv == 'standby'
binary_sensor.is_apple_tv_on: media_player.apple_tv != 'off'
binary_sensor.someone_home: person.maeva == 'home' or person.pierre == 'home'
binary_sensor.is_everybody_sleeping: input_boolean.sleeping

View File

@@ -29,12 +29,14 @@ import time
# update_on_both_front: true # optional, default false
# When true, motion is also recorded on the falling edge
# (sensor going on→off), not only on the rising edge.
# While any configured motion sensor remains on, the area
# timestamp is refreshed during the periodic update loop.
# max_time: <minutes> # optional
# Per-area cap, overrides the app-level max_time.
# door_sensor: <entity_id> # optional
# Binary sensor for the area door. When the door closes
# (on→off), the close timestamp is stored and exposed as
# a sensor (see OUTPUT ENTITIES below).
# door_sensors: <entity_id | list of entity_ids> # optional
# One or more binary sensors for the area door. When any
# door closes (on→off), the close timestamp is stored and
# exposed as a sensor (see OUTPUT ENTITIES below).
# # Shorthand form (no extra options needed):
# <area_name>: <entity_id | list of entity_ids>
#
@@ -98,7 +100,7 @@ import time
# - binary_sensor.living_room_motion_1
# - binary_sensor.living_room_motion_2
# max_time: 60
# door_sensor: binary_sensor.living_room_door
# door_sensors: binary_sensor.living_room_door
# garage:
# motion_sensors: binary_sensor.garage_motion
# update_on_both_front: true
@@ -150,6 +152,7 @@ class MotionTracker(SmartObject):
self.output_last_motion_sensors = dict()
self.output_last_motion_time_sensors = dict()
self.output_door_close_time_sensors = dict()
self.area_motion_sensors = dict()
self.app_max_time = self.args.get('max_time', self.MAX_TIME)
self.areas_max_time = dict()
self.update_cb_handle = None
@@ -159,16 +162,18 @@ class MotionTracker(SmartObject):
current_time = time.time()
for area in self.args['areas']:
update_on_both_front = False
door_generate_motion = False
self.output_last_motion_sensors[area] = self.create_entity(f"sensor.{area}_last_motion")
self.output_last_motion_time_sensors[area] = self.create_entity(f"sensor.{area}_last_motion_time")
self.area_motion_sensors[area] = list()
if isinstance(self.args['areas'][area], dict):
sensor_entities = self.args['areas'][area]['motion_sensors']
try: update_on_both_front = self.args['areas'][area]['update_on_both_front']
except KeyError: pass
update_on_both_front = self.args['areas'][area].get('update_on_both_front', False)
door_generate_motion = self.args['areas'][area].get('door_generate_motion', False)
if 'max_time' in self.args['areas'][area]:
self.areas_max_time[area] = self.args['areas'][area]['max_time']
if 'door_sensor' in self.args['areas'][area]:
if 'door_sensors' in self.args['areas'][area]:
self.output_door_close_time_sensors[area] = self.create_entity(f"sensor.{area}_door_close_time")
if not area in self.dataset['areas_door_close_time']:
@@ -177,7 +182,13 @@ class MotionTracker(SmartObject):
if not self.output_door_close_time_sensors[area].exists():
self.output_door_close_time_sensors[area].set_state(state = self.dataset['areas_door_close_time'][area],attributes = {'unit_of_measurement' : "s"})
self.listen_state(self.on_door_close,self.args['areas'][area]['door_sensor'],new = 'off', old = 'on',area = area)
door_sensor_entities = self.args['areas'][area]['door_sensors']
if not isinstance(door_sensor_entities, list):
door_sensor_entities = [door_sensor_entities]
for door_entity in door_sensor_entities:
self.listen_state(self.on_door_close, door_entity, new = 'off', old = 'on', area = area)
if door_generate_motion:
self.listen_state(self.on_motion_detected, door_entity, area = area)
else:
sensor_entities = self.args['areas'][area]
@@ -233,6 +244,7 @@ class MotionTracker(SmartObject):
self.log(f"Registering sensor {sensor_entity} for area {area}")
if sensor_entity not in self.input_sensors:
self.input_sensors[sensor_entity] = area
self.area_motion_sensors[area].append(sensor_entity)
self.listen_state(self.on_motion_detected,sensor_entity,old = "off", new = "on", area = area)
if update_on_both_front:
self.listen_state(self.on_motion_detected,sensor_entity,old = "on", new = "off", area = area)
@@ -247,6 +259,11 @@ class MotionTracker(SmartObject):
assert time_elapsed != None
self.output_last_motion_sensors[area].set_state(state = int(time_elapsed),attributes = {'unit_of_measurement' : "min"})
# Returns True when at least one motion sensor in the area is currently on.
# Used for presence sensors that can remain latched on for long periods.
def is_area_active(self,area):
return any(self.get_state(sensor_entity) == "on" for sensor_entity in self.area_motion_sensors.get(area, []))
# Returns True when the area is listed under
# areas_excluded_from_last_area_with_movement and should not update
# sensor.last_area_with_movement
@@ -283,7 +300,11 @@ class MotionTracker(SmartObject):
#For example if A = 5 and B = 6 and add 2 to the both of them starting by A
#A will be bigger than B (A = 7 and B = 6) for a very short time, and might trigger some automation
for area in sorted(self.dataset['areas_movement_time'], key = lambda area: self.dataset['areas_movement_time'][area]):
if (self.is_area_initialized(area)): self.update_area_sensor(area,current_time)
if (self.is_area_initialized(area)):
if self.is_area_active(area):
self.dataset['areas_movement_time'][area] = current_time
self.output_last_motion_time_sensors[area].set_state(state = current_time)
self.update_area_sensor(area,current_time)
self.output_last_area_with_movement_sensor.set_state(self.dataset['last_area_with_movement'])
self.update_cb_handle = self.run_in(self.update_areas_data,30)

View File

@@ -158,7 +158,7 @@ bed_ledstrip:
on_events_with_transition:
wake_up_events:
transition_time: 120
brightness_pct: 50
brightness_pct: 100
events:
WAKEUP_IN:
event_name: WAKEUP_IN

View File

@@ -5,7 +5,7 @@ light_kitchen_sink:
smart_conditions:
- light.kitchen_sink_switch
- binary_sensor.occupancy_kitchen and (sensor.kitchen_motion_light_level < 10 or self)
- binary_sensor.kitchen_occupancy and (sensor.kitchen_motion_light_level < 10 or self)
light_brightness_pct:
100: light.kitchen_sink_switch

View File

@@ -25,3 +25,19 @@ light_mezzanine_02:
5: input_boolean.sleeping
25: binary_sensor.day_interval_night
100: True
light_bookshelves:
module: smartlight
class: SmartLight
entity: light.living_room_bookshelves
smart_conditions:
trigger_conditions: binary_sensor.living_room_occupancy
blocking_conditions:
- sensor.mezzanine_motion_light_level > 10
- binary_sensor.is_apple_tv_on and not binary_sensor.is_apple_tv_idle
#light_brightness_pct:
# 5: input_boolean.sleeping
# 25: binary_sensor.day_interval_night
# 100: True

102
apps/smartheatpump.py Normal file
View File

@@ -0,0 +1,102 @@
import ad_toolbox.smartcondition as SmartCondition
import ad_toolbox.smartvalue as SmartValue
from ad_toolbox.smartobject import SmartObject
import time
class SmartHeatpump(SmartObject):
def on_initialize_smart_object(self):
super().on_initialize_smart_object()
if 'quick_resume' in self.args:
self.quick_resume_sensor = self.create_entity(self.args['quick_resume']['sensor'])
#is_on = 'on' if self.entity.get_state() != 'off' else 'off'
#if self.get_state(self.args['quick_resume']['sensor']) != 'on': # if the sensor doesn't exist I wan't to set it as well
# self.set_state(self.args['quick_resume']['sensor'],state = is_on)
self.listen_event(lambda event_name, data, kwargs: self.set_state(self.args['quick_resume']['sensor'],state = 'off'),self.args['quick_resume']['reset_event'])
self.target_temperature = SmartValue.Evaluator(self,self.args['target_temperature'], expression_name = 'target_temperature', on_change_cb = self.on_change_target_temperature, constants = self.constants)
self.hvac_mode = SmartValue.Evaluator(self,self.args['hvac_mode'], expression_name = 'hvac_mode', on_change_cb = self.on_change_hvac_mode, constants = self.constants)
if 'horizontal_vane' in self.args:
self.horizontal_vane = SmartValue.Evaluator(self,self.args['horizontal_vane'], expression_name = 'horizontal_vane', on_change_cb = self.on_change_horizontal_vane, constants = self.constants)
else:
self.horizontal_vane = None
self.fan_mode = SmartValue.Evaluator(self,self.args['fan_mode'], expression_name = 'fan_mode', on_change_cb = self.on_change_fan_mode, constants = self.constants)
self.smart_conditions_evaluator = SmartCondition.Evaluator(self,self.args['smart_conditions'],condition_name = "smart_conditions",on_change_cb = self.on_smart_conditions_change,constants = self.constants, templates_library = self.templates_library)
if 'input_buttons' in self.args:
if 'turn_on' in self.args['input_buttons']:
self.listen_state(lambda entity, attribute, old, new, kwargs: self.on_turn_on_button(),self.args['input_buttons']['turn_on'])
if 'turn_off' in self.args['input_buttons']:
self.listen_state(lambda entity, attribute, old, new, kwargs: self.on_turn_off_button(),self.args['input_buttons']['turn_off'])
def on_turn_on_button(self): self.start_cooling()
def on_turn_off_button(self):
self.stop_cooling()
# we don't wan't quick resum if we force turn off the a/c
if 'quick_resume' in self.args:
self.set_state(self.args['quick_resume']['sensor'],state = 'off')
def start_cooling(self):
if 'quick_resume' in self.args:
self.set_state(self.args['quick_resume']['sensor'],state = 'on')
temperature = self.target_temperature.evaluate(False)
hvac_mode = self.hvac_mode.evaluate(False)
fan_mode = self.fan_mode.evaluate(False)
self.log_info(f"Starting Heatpump in {hvac_mode} mode, with target_temperature of {temperature}° and {fan_mode} fan speed")
#self.turn_on(self.entity_id)
#time.sleep(2)
self.call_service("climate/set_hvac_mode", entity_id = self.entity_id,hvac_mode = hvac_mode)
time.sleep(1)
self.call_service("climate/set_temperature", entity_id = self.entity_id,temperature = temperature,hvac_mode = hvac_mode)
time.sleep(1)
self.call_service("climate/set_fan_mode", entity_id = self.entity_id,fan_mode = fan_mode)
if self.horizontal_vane:
time.sleep(1)
horizontal_vane = self.horizontal_vane.evaluate(False)
self.set_horizontal_vane(horizontal_vane)
def stop_cooling(self):
self.log_info("Setting Heatpump hvac_mode to off")
self.call_service("climate/set_hvac_mode", entity_id = self.entity_id,hvac_mode = "off")
def on_smart_conditions_change(self,prev_result,result):
if result == SmartCondition.Result.Succeeded:
self.start_cooling()
else:
self.log_info("Turning Off Heatpump")
self.stop_cooling()
def on_change_target_temperature(self,prev_result,result):
if self.entity.get_state() != 'off':
self.log_info(f"Setting target temperature to {result}°")
self.call_service("climate/set_temperature", entity_id = self.entity_id,temperature = result)
def on_change_hvac_mode(self,prev_result,result):
if self.entity.get_state() != 'off':
self.log_info(f"Setting hvac_mode to {result}")
self.call_service("climate/set_hvac_mode", entity_id = self.entity_id,hvac_mode = result)
def on_change_fan_mode(self,prev_result,result):
if self.entity.get_state() != 'off':
self.log_info(f"Setting fan_mode to {result}")
self.call_service("climate/set_fan_mode", entity_id = self.entity_id,fan_mode = result)
def set_horizontal_vane(self,value):
device, entity = self.split_entity(self.entity_id)
self.call_service("select/select_option", entity_id = f"select.{entity}_horizontal_vane",option = value)
#self.set_state(f"select.{entity}_horizontal_vane",state = value)
def on_change_horizontal_vane(self,prev_result,result):
if self.entity.get_state() != 'off':
self.log_info(f"Setting horizontal_vane to {result}")
self.set_horizontal_vane(result)

View File

@@ -2,6 +2,9 @@
# Archive log files from the logs directory into a timestamped subdirectory, then delete them.
# Add to dockerStart.sh to run this script at startup, after the configuration setup:
# sh $CONF/archiveLogs.sh
LOGS_DIR=/conf/logs
ARCHIVE_DIR=$LOGS_DIR/archive
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")