diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4a28548..734b5b1 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,8 +18,7 @@ repos: - repo: local hooks: - id: update-readme - name: update-readme + name: Update README.md entry: python helpers/update_readme.py language: python - pass_filenames: false additional_dependencies: [pyyaml] diff --git a/README.md b/README.md old mode 100755 new mode 100644 index 030319f..147c2ef --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ [![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://stand-with-ukraine.pp.ua/) -> [!WARNING] -> My configuration is in the process of migration. Some things might break. Some docs might be outdated. Please keep that in mind. Subscribe for updates. - -# Denys Dovhan Home Assistant Config +# Denys Dovhan's Home Assistant Config ![Home](https://user-images.githubusercontent.com/3459374/152371766-1d2a1e17-34d3-4fe6-9e6d-aded02f14de1.png) @@ -20,6 +17,123 @@ This is my personal Home Assistant configuration, awakening my home with automat I also have a [public Notion board](https://www.notion.so/denysdovhan/f09ea06da5db4cfa84d3ca50417b93b2?v=5fccab53c2fd4ac188ee0b92c2ca1cb9) with ideas and tasks for my smart home. You can follow and comment my plans there. +## Addons + +running these addons + + + +- [Advanced SSH & Web Terminal](https://github.com/hassio-addons/addon-ssh) v17.2.0 – A supercharged SSH & Web Terminal access to your Home Assistant instance +- [File editor](https://github.com/home-assistant/addons/tree/master/configurator) v5.8.0 – Simple browser-based file editor for Home Assistant +- [ESPHome](https://esphome.io/) v2024.3.2 – ESPHome add-on for intelligently managing all your ESP8266/ESP32 devices +- [PS5 MQTT](https://github.com/FunkeyFlo/ps5-mqtt/tree/main/add-ons/ps5-mqtt) v1.3.3 – Control Sony PlayStation 5 devices via MQTT +- [AirCast](https://github.com/hassio-addons/addon-aircast) v4.2.1 – AirPlay capabilities for your Chromecast devices. +- [Home Assistant Google Drive Backup](https://github.com/sabeechen/hassio-google-drive-backup) v0.112.1 – Automatically manage backups between Home Assistant and Google Drive +- [Samba share](https://github.com/home-assistant/addons/tree/master/samba) v12.3.1 – Expose Home Assistant folders with SMB/CIFS +- [Mosquitto broker](https://github.com/home-assistant/addons/tree/master/mosquitto) v6.4.0 – An Open Source MQTT broker +- [Zigbee2MQTT](https://github.com/zigbee2mqtt/hassio-zigbee2mqtt/tree/master/zigbee2mqtt) v1.36.1-1 – Use your ZigBee devices without the vendor's bridge or gateway + + +## Automation + + + +1. [🚨 Alarm](#-alarm) (2 automation) +1. [🔔 Alert](#-alert) (11 automation) +1. [🌡️ Climate](#-climate) (8 automation) +1. [⚡️ Energy](#-energy) (1 automation) +1. [💡 Light](#-light) (6 automation) +1. [🎵 Media](#-media) (3 automation) +1. [🚦 Mode](#-mode) (4 automation) +1. [🔘 Presence](#-presence) (2 automation) +1. [🖥️ System](#-system) (2 automation) +1. [🧹 Vacuum](#-vacuum) (8 automation) +1. [💦 Water](#-water) (1 automation) + +Total number of automations: **48**️ + +### 🚨 Alarm + +- [Notification for Triggered](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L75) – Make an announcement when Alarm is getting triggered +- [Triggering](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L52) + +### 🔔 Alert + +- [Air Siren in Kyiv](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L2) – Оголошення повітряної тривоги у Києві +- [Bad Air Quality](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L401) – Notify when the air quality is bad +- [Car Washing](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L516) – Notify when it’s okay or not okay to wash a car +- [HACS Releases](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L271) – Notify when new HACS components are released +- [Home Assistant Release](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L240) – Notify Denys about new Home Assistant releases +- [Home Assistant Start](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L308) – Notify Denys when Home Assistant starts +- [Humidifier No Water](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L490) – Notify when humidifier's water tank is empty +- [Monthly Energy Usage](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L639) – Switch energy tariff and notify about the consumption +- [Snow/Winter Tires](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L566) – Notify when it's time to change car tires +- [System Peaks ](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L328) – Alerts for high server usage, overloading, overheating, disk space +- [Water is Heated](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1853) – When we ask to let us know when the boiler has done heating, it should notify about that. + +### 🌡️ Climate + +- [Preheat Balcony for a Workday](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L933) – When Denys wakes up, ask if he is going to work on balcony, start heating and notify when temperature is comfortable. +- [Suggest turning on AC when it's hot](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#LNone) – When temperature raises over certain level, send an actionable notification for turning on ACs +- [Switch Heaters during Heating Season](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L768) – Turn on/off heaters when Heating Season in on +- [Sync Bedroom TRV temperature](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L759) +- [Sync Living Room TRV temperature](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L750) +- [Turn off Balcony Heater](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L881) – Turn off Balcony Heater when the working display or desk lamp are off for some time +- [Turn on Balcony Heater](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L841) – Turn on Balcony Heater when it's cold and Desk Lamp or Working Display are turned on +- [Turn on Humidifier only during sleep time](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1979) + +### ⚡️ Energy + +- [Electricity Meter](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L679) – Switch tarrifs for energy utility meter + +### 💡 Light + +- [Presence Simulation in Away Mode](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1319) – Toggle Presence Simulation during Night in Away Mode +- [Toggle Desk Lamp with Working Display](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1234) – Sync Desk lamp with Working Display +- [Turn off Corridor Light When Door is Closed](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1158) – Turn off Corridor Light when Front Door closes. If the light is still on, then send a notification with an action to turn off the light. +- [Turn on Corridor Light when Door is open](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1135) – Turn on Corridor Light when Front Door opens and then turn it off after a few minutes +- [Turn on lights on Sunset](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1027) – Turn on lights when sun goes below the horizon +- [Turn on lights on low illuminance](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1076) – Turn on lights on low illuminance + +### 🎵 Media + +- [Turn off Samsung TV when PlayStation turns off](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L95) – Turn off Samsung TV when PS5 goes to sleep mode +- [Turn on Apple TV when Samsung TV turns on](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L2148) – Turn on Apple TV when Samsung TV turns on and PS5 is off +- [Turn on Apple TV when Samsung TV turns on](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L2148) – Turn on Apple TV when Samsung TV turns on and PS5 is off + +### 🚦 Mode + +- [Away Flow](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1285) – Toggle Away mode depending on the Away input boolean +- [Away on Leaving City](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1295) – Toggle Away mode depending on proximity to the Kyiv city +- [Do Not Disturb Activation](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1250) – Adjust devices to Do Not Disturb mode +- [Do Not Disturb on Focus](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1267) – Switch Do Not Disturb while camera, mic or focus are on + +### 🔘 Presence + +- [Everyone is Arriving](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1347) – Turn on things when people are arriving +- [Everyone is Leaving](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1427) – Turn off things when people are leaving + +### 🖥️ System + +- [Magic Cube Actions](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L118) +- [Power Outage Recovery](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1921) + +### 🧹 Vacuum + +- [Ask Regular Cleaning](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1499) – Regular vacuum cleaning every two days +- [Ask for Maintenance](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1638) – Send vacuum near trash bin and ask for maintenance +- [Clean Counting](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L2202) – Count cleanings via counter +- [Error Alert](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1610) – Notify when error with vacuum occured +- [Finish Alert](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1577) – Notify when vacuum finished cleaning and we are not home. +- [Replacements Alert](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1702) – Notify when vacuum parts need to be replaced +- [Stop cleaning when we return home](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1559) – Send vacuum home when somebody comes home +- [iOS Actions](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L1782) – Handle iOS actions for vacuum cleaner + +### 💦 Water + +- [Keep Water Heater turned On](https://github.com/denysdovhan/home-assistant-config/blob/8f02ddd1de928b2458f20fd0b5010300ab95931f/automations.yaml#L2175) – When Water Heater was accidentally turned off, automatically turn in on + + ## License [MIT][license-url] © [Denys Dovhan][denysdovhan] diff --git a/automations.yaml b/automations.yaml index c3fa6e5..a2cf676 100644 --- a/automations.yaml +++ b/automations.yaml @@ -273,6 +273,7 @@ trigger: - platform: state entity_id: sensor.hacs + to: variables: hacs_updates: '{% for repo in state_attr(''sensor.hacs'', ''repositories'') -%} @@ -485,26 +486,6 @@ milliseconds: 0 alias: Wait for 3 hours before the next announcement mode: single -- id: torrent_completed_notification - alias: 'Alert: Downloaded Torrents' - description: Notify about downloaded Transmission torrents - trigger: - - platform: event - event_type: transmission_downloaded_torrent - action: - - service: script.announcement - data: - title: Transmission ⬇️ - speak: false - messages: - - Торрент {{ trigger.event.data.name }} завантажено! - - Завантажено торрент {{ trigger.event.data.name }}! - - Торрент {{ trigger.event.data.name }} викачаний! - - Торрент {{ trigger.event.data.name }} готовий! - notify_data: - url: /torrents - group: system - alias: Notify about completed torrent - id: humidifier_no_water alias: 'Alert: Humidifier No Water' description: Notify when humidifier's water tank is empty @@ -1363,7 +1344,7 @@ data: {} alias: Toggle presence simulation - id: everyone_is_arriving - alias: 'Flow: Everyone is Arriving' + alias: 'Presence: Everyone is Arriving' description: Turn on things when people are arriving trigger: - platform: state @@ -1443,7 +1424,7 @@ data: {} mode: restart - id: everyone_is_leaving - alias: 'Flow: Everyone is Leaving' + alias: 'Presence: Everyone is Leaving' description: Turn off things when people are leaving trigger: - platform: state @@ -1544,10 +1525,9 @@ condition: state entity_id: binary_sensor.time_to_clean state: 'on' - - alias: We are not out of the city - condition: numeric_state - entity_id: sensor.home_nearest_distance - below: 25 + - condition: state + entity_id: input_boolean.away + state: 'off' action: - service: script.announcement data: @@ -1589,10 +1569,10 @@ entity_id: vacuum.roborock state: cleaning action: - - service: vacuum.return_to_base - data: {} - target: - entity_id: vacuum.roborock + - device_id: 88ae8bfa1cb56b3d6462805180f8af6f + domain: vacuum + entity_id: a57807c72667f32589b274e79f83b6a3 + type: dock - id: vacuum_finish_notification alias: 'Vacuum: Finish Alert' description: Notify when vacuum finished cleaning and we are not home. @@ -1633,7 +1613,9 @@ - platform: state entity_id: - sensor.roborock_vacuum_error - to: + not_to: + - unavailable + - unknown not_from: - unknown - unavailable diff --git a/helpers/update_readme.py b/helpers/update_readme.py index 34e6d8c..743f012 100755 --- a/helpers/update_readme.py +++ b/helpers/update_readme.py @@ -6,7 +6,7 @@ import yaml from pathlib import Path -README = Path("README.new.md") +README = Path("README.md") AUTOMATIONS = Path("automations.yaml") URL = "https://github.com/denysdovhan/home-assistant-config/blob/{commit_hash}/{fname}" @@ -20,6 +20,9 @@ def git_latest_edit_hash(filename): def slugify(s): return s.lower().strip().replace(" ", "-").encode("ascii", "ignore").decode("ascii") +def to_file(lines): + return "".join(lines) + def get_emoji(group): emojis = { "Alarm": "🚨", @@ -42,13 +45,54 @@ def read_file(fname): def write_file(fname, content): with open(fname, 'w') as file: - file.write("".join(content)) + file.write(to_file(content)) def read_yaml(fname): with fname.open() as file: # return sorted(yaml.safe_load(file), key=lambda automation: automation['alias']) return yaml.safe_load(file); +def remove_text(content, start, end): + do_append = True + new = [] + for line in content: + if end in line: + do_append = not do_append + if do_append: + new.append(line) + if start in line: + do_append = not do_append + return new + +def modify_lines(to_insert, lines, tag): + MARKDOWN_COMMENT = "" + start_tag = MARKDOWN_COMMENT.format(f"start-{tag}") + end_tag = MARKDOWN_COMMENT.format(f"end-{tag}") + + # Find indices of start and end comments + start_index, end_index = None, None + for i, line in enumerate(lines): + if start_tag in line: + start_index = i + elif end_tag in line: + end_index = i + break + + if start_index is None or end_index is None: + print("Start or end tag not found. Text not inserted.") + return lines + + # Remove existing text between start and end comments + lines[start_index + 1:end_index] = [] + # Insert empty line after start comment + lines.insert(start_index + 1, '\n') + + # Insert new text between start and end comments + insertion_index = start_index + 2 + lines[insertion_index:insertion_index] = [line + '\n' for line in to_insert] + + return lines + def get_alias(automation): return automation['alias'] @@ -99,31 +143,11 @@ def render_automation_amount(amount): def render_automation(fname, commit_hash, title, line, description): href = permalink(fname, commit_hash) + f"#L{line}" - item = f"* [{title}]({href})" + item = f"- [{title}]({href})" if description: return f"{item} – {description}" return item -def remove_text(content, start, end): - do_append = True - new = [] - for line in content: - if end in line: - do_append = not do_append - if do_append: - new.append(line) - if start in line: - do_append = not do_append - return new - -def modify_lines(to_insert, lines, tag): - MARKDOWN_COMMENT = "" - start = MARKDOWN_COMMENT.format(f"start-{tag}") - end = MARKDOWN_COMMENT.format(f"end-{tag}") - new_lines = remove_text(lines, start, end) - i = next((i for (i, line) in enumerate(new_lines) if start in line)) + 1 - return new_lines[:i] + [s + "\n" for s in to_insert] + new_lines[i:] - def render_automations_toc(grouped_automations): text = [] total_automations = 0 @@ -161,7 +185,7 @@ def render_addon(addon): version = addon["version"] url = addon["url"] description = addon["description"] - return f"* [{name}]({url}) v{version} – {description}" + return f"- [{name}]({url}) v{version} – {description}" def render_addons(): text = [] @@ -171,12 +195,15 @@ def render_addons(): return text def main(): - readme = read_file(README) - automations = render_automations() - addons = render_addons() - readme = modify_lines(automations, readme, "automations") - readme = modify_lines(addons, readme, "addons") - write_file(README, readme) + old_readme = read_file(README) + new_readme = old_readme.copy() + + new_readme = modify_lines(render_addons(), new_readme, 'addons') + new_readme = modify_lines(render_automations(), new_readme, 'automations') + + # Write only when changes applied + if to_file(new_readme) != to_file(old_readme): + write_file(README, new_readme) if __name__ == "__main__": main()