diff --git a/group_vars/all.yml b/group_vars/all.yml index 8a69379..eea0b7f 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -171,8 +171,8 @@ wireguard: - public_key: 3mkPtY29F3/0WhSIEUkSAHJexJWOJfFzc6LOzBX9Hjc= allowed_ips: 10.100.0.2/32 # pallet - - public_key: ZbLgn0EnkKbv8L6nxysix/fRoASNGFIIvEuLn/aLbm4= - allowed_ips: 10.100.0.3/32 + # - public_key: ZbLgn0EnkKbv8L6nxysix/fRoASNGFIIvEuLn/aLbm4= + # allowed_ips: 10.100.0.3/32 homeassistant: version: 2024.1.3 diff --git a/home-assistant/automations/pixel_4a_bssid_to_mqtt.yaml b/home-assistant/automations/pixel_4a_bssid_to_mqtt.yaml new file mode 100644 index 0000000..c965a1b --- /dev/null +++ b/home-assistant/automations/pixel_4a_bssid_to_mqtt.yaml @@ -0,0 +1,25 @@ +# https://blog.ceard.tech/2023/01/wifi-sensor-to-device-tracker +- id: 'pixel_4a_wifi_to_mqtt_location' + alias: 'Pixel 4a wifi to MQTT location' + initial_state: 'on' + trigger: + - platform: state + entity_id: sensor.pixel_4a_wifi_bssid + to: ~ + action: + - choose: + - conditions: + - condition: template + value_template: "{{ 'e6:63:da:e8:c7:e5' in states('sensor.pixel_4a_wifi_bssid') }}" + sequence: + - service: mqtt.publish + data: + topic: location/pixel_4a_wifi + payload: 'home' + retain: true + default: + - service: mqtt.publish + data: + topic: location/pixel_4a_wifi + payload: 'not_home' + retain: true \ No newline at end of file diff --git a/home-assistant/binary_sensors/anyone_home.yaml b/home-assistant/binary_sensors/anyone_home.yaml new file mode 100644 index 0000000..c720c8f --- /dev/null +++ b/home-assistant/binary_sensors/anyone_home.yaml @@ -0,0 +1,6 @@ +- platform: template + sensors: + anyone_home: + device_class: occupancy + friendly_name: 'Anyone Home' + value_template: "{{ states.person | selectattr('state','eq','home') | list | count > 0 }}" \ No newline at end of file diff --git a/home-assistant/mqtt/pixel_4a_location.yaml b/home-assistant/mqtt/pixel_4a_location.yaml new file mode 100644 index 0000000..724f613 --- /dev/null +++ b/home-assistant/mqtt/pixel_4a_location.yaml @@ -0,0 +1,5 @@ +device_tracker: + - name: "Pixel 4a wifi" + state_topic: 'location/pixel_4a_wifi' + source_type: router + unique_id: "mqtt_pixel_4a_wifi" diff --git a/playbook.yml b/playbook.yml index 6393d5f..85e7874 100644 --- a/playbook.yml +++ b/playbook.yml @@ -31,6 +31,19 @@ roles: - zigbee2mqtt - home-assistant + tasks: + - name: Install home-assistant binary_sensors config + copy: + src: home-assistant/binary_sensors + dest: /opt/homeassistant/config/binary_sensors + - name: Install home-assistant mqtt config + copy: + src: home-assistant/mqtt + dest: /opt/homeassistant/config/mqtt + - name: Install home-assistant automations + copy: + src: home-assistant/automations + dest: /opt/homeassistant/config/automations - hosts: cups roles: diff --git a/roles/home-assistant/files/configuration.yaml b/roles/home-assistant/files/configuration.yaml index d9f34fe..8bb2d9c 100644 --- a/roles/home-assistant/files/configuration.yaml +++ b/roles/home-assistant/files/configuration.yaml @@ -4,6 +4,11 @@ frontend: themes: !include_dir_merge_named themes automation: !include automations.yaml +automation extra: !include_dir_merge_list automations + +binary_sensor: !include_dir_merge_list binary_sensors + +mqtt: !include_dir_merge_named mqtt http: use_x_forwarded_for: true diff --git a/roles/home-assistant/tasks/main.yml b/roles/home-assistant/tasks/main.yml index 4b92108..033634e 100644 --- a/roles/home-assistant/tasks/main.yml +++ b/roles/home-assistant/tasks/main.yml @@ -26,6 +26,15 @@ path: /opt/homeassistant/config state: directory +- name: Create home-assistant extra config directories + file: + path: '{{ item }}' + state: directory + with_items: + - /opt/homeassistant/config/binary_sensors + - /opt/homeassistant/config/mqtt + - /opt/homeassistant/config/automations + - name: Copy home-assistant config copy: src: configuration.yaml