Skip to content

Commit

Permalink
HA improvements (#144)
Browse files Browse the repository at this point in the history
* Remove theme automation

* Update filter sensors

* Add climate calendar

* Use statistics instead of filter

* zigbee2mqtt: update

* Add new automation

* Add HA restic backup
  • Loading branch information
pedorich-n authored Jan 5, 2025
1 parent 6278e61 commit 81089e9
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 73 deletions.
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
- id: "climate"
alias: Climate
description: ""
triggers:
- trigger: calendar
entity_id: calendar.climate
event: start
conditions:
- condition: state
entity_id: input_boolean.vacation_mode
state: "off"
actions:
- variables:
duration: >
{% set start = trigger.calendar_event.start | as_datetime %}
{% set next_midnight = (start + timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0) %}
{% set end = trigger.calendar_event.end | as_datetime %}
{% if end == next_midnight %}
{{ None }}
{% else %}
{{ end - start }}
{% endif %}
summary: |
{{ trigger.calendar_event.summary.split(" ") }}
entities: |
{% set room = summary[0] | lower %}
{{
{
"climate": "climate.{{ room }}_ac",
"temperature": "sensor.{{ room }}_temperature_avg"
}
}}
mode: |
{{ summary[1] | lower }}
temp: |
{% if mode == "heat" %}
{{
{
"target": 24,
"cmp": "lte",
"cmp_target": 20
}
}}
{% elif mode == "cool" %}
{{
{
"target": 27,
"cmp": "gte",
"cmp_target": 26
}
}}
{% endif %}
- alias: If temperature condition matches
if:
- condition: template
value_template: |-
{% if temp.cmp == "lte" %}
{{ float(states(entities.temperature)) <= temp.cmp_target }}
{% elif temp.cmp == "gte" %}
{{ float(states(entities.temperature)) >= temp.cmp_target }}
{% endif %}
then:
- action: climate.set_temperature
metadata: {}
data:
hvac_mode: "{{ mode }}"
temperature: "{{ temp.target }}"
target:
entity_id: "{{ entities.climate }}"
alias: Enable climate
- alias: Maybe wait to turn off
if:
- condition: template
value_template: "{{ duration != None }}"
alias: If duration is not empty
then:
- alias: Wait for climate to turn off
wait_template: |
{{ is_state(entities.climate, "off") }}
timeout: "{{ duration }}"
continue_on_timeout: true
- alias: Turn off if timed out
if:
- condition: template
value_template: "{{ not wait.completed }}"
alias: If timed out
then:
- action: climate.turn_off
metadata: {}
data: {}
target:
entity_id: "{{ entities.climate }}"
mode: parallel
max: 10
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
state: unavailable
alias: Humidifier is online
- condition: numeric_state
entity_id: sensor.avg_ldk_humidity
entity_id: sensor.ldk_humidity_avg
below: 45
actions:
- action: select.select_option
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ automation.set_theme_on_startup:

automation.hallway_wardrobe_light:
icon: mdi:lightbulb-auto-outline

automation.climate:
icon: mdi:home-thermometer-outline
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
sensor.avg_bedroom_temperature:
sensor.bedroom_temperature_avg:
icon: mdi:home-thermometer-outline

sensor.avg_bedroom_humidity:
sensor.bedroom_humidity_avg:
icon: mdi:cloud-percent-outline

sensor.avg_ldk_temperature:
sensor.ldk_temperature_avg:
icon: mdi:home-thermometer-outline

sensor.avg_ldk_humidity:
sensor.ldk_humidity_avg:
icon: mdi:cloud-percent-outline

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
- platform: statistics
name: Bedroom temperature AVG
unique_id: bedroom_temperature_avg
entity_id: sensor.bedroom_temperature_humidity_1_temperature
state_characteristic: average_step
keep_last_sample: true
percentile: 50
precision: 2
max_age:
hours: 1

- platform: statistics
name: Bedroom humidity AVG
unique_id: bedroom_humidity_avg
entity_id: sensor.bedroom_temperature_humidity_1_humidity
state_characteristic: average_step
keep_last_sample: true
percentile: 50
precision: 2
max_age:
hours: 1

- platform: statistics
name: LDK temperature AVG
unique_id: ldk_temperature_avg
entity_id: sensor.ldk_temperature_humidity_1_temperature
state_characteristic: average_step
keep_last_sample: true
percentile: 50
precision: 2
max_age:
hours: 1

- platform: statistics
name: LDK humidity AVG
unique_id: ldk_humidity_avg
entity_id: sensor.ldk_temperature_humidity_1_humidity
state_characteristic: average_step
keep_last_sample: true
percentile: 50
precision: 2
max_age:
hours: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Custom ICS Generator//EN
CALSCALE:GREGORIAN

BEGIN:VEVENT
UID:workday-bedroom-heat
DTSTAMP:20241228T000000Z
DTSTART;TZID=Asia/Tokyo:20241101T073000
DTEND;TZID=Asia/Tokyo:20241101T083000
RRULE:FREQ=YEARLY;BYMONTH=11,12,1,2,3;BYDAY=MO,TU,WE,TH,FR
SUMMARY:Bedroom Heat
DESCRIPTION:
LOCATION:
END:VEVENT

BEGIN:VEVENT
UID:weekend-bedroom-heat
DTSTAMP:20241228T000000Z
DTSTART;TZID=Asia/Tokyo:20241101T083000
DTEND;TZID=Asia/Tokyo:20241101T093000
RRULE:FREQ=YEARLY;BYMONTH=11,12,1,2,3;BYDAY=SA,SU
SUMMARY:Bedroom Heat
DESCRIPTION:
LOCATION:
END:VEVENT

BEGIN:VEVENT
UID:workday-ldk-heat
DTSTAMP:20241228T000000Z
DTSTART;TZID=Asia/Tokyo:20241101T073000
DTEND;TZID=Asia/Tokyo:20241102T000000
RRULE:FREQ=YEARLY;BYMONTH=11,12,1,2,3;BYDAY=MO,TU,WE,TH,FR
SUMMARY:LDK Heat
DESCRIPTION:
LOCATION:
END:VEVENT

BEGIN:VEVENT
UID:weekend-ldk-heat
DTSTAMP:20241228T000000Z
DTSTART;TZID=Asia/Tokyo:20241101T083000
DTEND;TZID=Asia/Tokyo:20241101T120000
RRULE:FREQ=YEARLY;BYMONTH=11,12,1,2,3;BYDAY=SA,SU
SUMMARY:LDK Heat
DESCRIPTION:
LOCATION:
END:VEVENT

END:VCALENDAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ lib, ... }:
{
#NOTE - See also global config at
#LINK - machines/geekomA5/modules/system/services/restic.nix
services.restic.backups = {
homeassistant = {
paths = lib.map (rel: "/mnt/store/home-automation/homeassistant/${rel}") [
"automations"
"configuration"
"custom_components"
"deps"
"local"
"resources"
".storage"
"themes"
"ui_lovelace_minimalist"
"www"
"automations.yaml"
"configuration.yaml"
];

pruneOpts = [
"--keep-daily 7"
"--keep-weekly 4"
"--keep-monthly 6"
];
};
};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
homeassistant: true
permit_join: false
homeassistant:
enabled: true
mqtt:
base_topic: zigbee2mqtt
server: mqtt://mosquitto
Expand All @@ -10,20 +11,16 @@ mqtt:
version: 4
serial:
port: /dev/ttyZigbee
frontend: true
adapter: zstack
frontend:
enabled: true
advanced:
network_key: "!secrets.yaml network_key"
homeassistant_legacy_entity_attributes: false
homeassistant_legacy_triggers: false
legacy_api: false
legacy_availability_payload: false
log_level: info
log_output:
- file
- console
channel: 25
last_seen: ISO_8601
device_options:
legacy: false
devices:
"0xa4c1387f4ac9519d":
friendly_name: tuya_temperature_bedroom_1
Expand All @@ -50,3 +47,4 @@ devices:
homeassistant:
name: Bedroom Temperature Humidity 1
groups: {}
version: 4
1 change: 1 addition & 0 deletions machines/geekomA5/modules/system/services/restic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ in
grist.timerConfig.OnCalendar = mkEveryDayAt "02:30:00";
maloja.timerConfig.OnCalendar = mkEveryDayAt "02:35:00";
paperless.timerConfig.OnCalendar = mkEveryDayAt "02:40:00";
homeassistant.timerConfig.OnCalendar = mkEveryDayAt "02:45:00";
};
};
}

0 comments on commit 81089e9

Please sign in to comment.