Mohlsson / ReplayLightsHistory

AppDaemon App for Home Assistant to replay light switch history when no one is home.
Apache License 2.0
29 stars 5 forks source link
appdaemon appdaemon-apps home-assistant homeassistant lights replay vacation

ReplayLightsHistory hacs_badge

This is an AppDaemon App for Home Assistant that is designed to replay your lights behavior when no one is home. There are multiple other approaches out there that try to simulate behavior, which is hard. This approach simply uses your smart devices previous behavior to control their pending behavior. As the code exist today it has been tested with lights and smart switches. The smart switches include TP Link smart switches and plugs, as they are both labeled switch entities in Home Assistant. It has also been used with shelly 2 switches. It currently can only be configured to control one category of entities, which is specified in the configuration information.

Manually installing this AppDaemon App is relatively simply. The replay_lights.py file needs to be placed in the appdaemon/apps/ directory on your Home assistant install. Then you need to added lines to the appdaemon/apps/apps.yaml file to enable this application. At a minimum you would add these lines to the file apps/yaml file:

replay_lights: module: replay_lights class: ReplayLights

A maximum configuration can include the following lines, modified for your install:

replay_lights:
  hassDir: '/home/jondoe/.homeassistant'
  databaseType: sqlite3
  databaseHost: "localhost"
  databaseUser: "homeassistant"
  databasePassword: "PASSWORD"
  databaseSchema: "homeassistant"
  module: replay_lights
  class: ReplayLights
  numberOfDaysBack: 7
  deviceType: "light"
  enableTag: "alarm_control.home_alarm"
  enableVal: "armed_away"
  smartControlledByDumb: "switch.master_bed,switch.living_room_lamp"
  excludeList: "switch.garage,switch.garagecam"
  log_level: INFO

example_apps.yaml in the repo includes similar records

All of the parameters are optional. Their use follows:

NOTE: A recent update added the ability to use MariaDB as an alternative to sqlite3. This change requires the python package to be included in your appdaemon docker container. You include PyMySQL by adding it to the addons.json file found in the home assistant base directory. The easist way to make this modification is directly from the Home Assistant GUI. From Supervisor -> AppDaemon -> Configuration you can update the configuration to look like this:

system_packages: []
python_packages:
  - PyMySQL
init_commands: []

For the change to take effect you need to restart AppDaemon, which can be done from the AppDaemon Info tab.