From a879196e78325e93a12779a4e9c942fd00c7e2b2 Mon Sep 17 00:00:00 2001 From: Ben Kristinsson Date: Sun, 6 Nov 2022 17:34:24 +0100 Subject: [PATCH] some template sensors, and testing sending data to influxdb --- roles/hass/files/templates.yaml | 6 ++++ roles/hass/tasks/hass.yml | 31 ++++++++++++++++++ roles/hass/templates/configuration.yaml.j2 | 37 ++++++++++++++++++++++ roles/hass/templates/git-hass-config.sh.j2 | 1 + roles/hass/templates/secrets.yaml.j2 | 7 +++- 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 roles/hass/files/templates.yaml diff --git a/roles/hass/files/templates.yaml b/roles/hass/files/templates.yaml new file mode 100644 index 0000000..4d5f219 --- /dev/null +++ b/roles/hass/files/templates.yaml @@ -0,0 +1,6 @@ + +- sensor: + - name: "chance_of_rain" + unit_of_measurement: "%" + icon: "mdi:weather-pouring" + state: "{{ state_attr('weather.hourly', 'forecast')[:2] | map(attribute='precipitation_probability') | list | max | float }}" diff --git a/roles/hass/tasks/hass.yml b/roles/hass/tasks/hass.yml index a6ea193..289ad36 100644 --- a/roles/hass/tasks/hass.yml +++ b/roles/hass/tasks/hass.yml @@ -130,6 +130,17 @@ tags: - hass-config +- name: copy home assistant templates file + copy: + src: templates.yaml + dest: "{{ systemuserlist.hass.home }}/home-assistant/config/templates.yaml" + owner: "{{ systemuserlist.hass.uid }}" + group: "{{ systemuserlist.hass.gid }}" + mode: 0644 + notify: restart hass container + tags: + - hass-config + - name: install git sync script template: src: git-hass-config.sh.j2 @@ -152,6 +163,16 @@ - hass-cron - hass-git + # the host needs to have bluez installed for the container to use bluetooth +- name: install bluetooth packages + apt: + name: + - bluez + - bluetooth + state: latest + tags: + - packages + # docker run --run -it -p 8091:8091 -p 3000:3000 --network #bridgewithdns --device /dev/ttyACM0:/dev/zwave -v # /home/ben/zwavejs:/usr/src/app/store zwavejs/zwavejs2mqtt:latest @@ -224,6 +245,16 @@ - type: bind source: "{{ systemuserlist.hass.home }}/home-assistant/media" target: /usr/var/media + # for bluetooth, container needs access to the dbus socket + # https://www.home-assistant.io/integrations/bluetooth/ + - type: bind + source: /run/dbus/ + target: /run/dbus/ + read_only: true + - type: bind + source: /etc/bluetooth/main.conf + target: /etc/bluetooth/main.conf + read_only: true # scripts from role: common # only depends on requests, which hass image has - type: bind diff --git a/roles/hass/templates/configuration.yaml.j2 b/roles/hass/templates/configuration.yaml.j2 index c50bd80..0f12ae1 100644 --- a/roles/hass/templates/configuration.yaml.j2 +++ b/roles/hass/templates/configuration.yaml.j2 @@ -66,6 +66,7 @@ tts: automation: !include automations.yaml script: !include scripts.yaml scene: !include scenes.yaml +template: !include templates.yaml {# calendar: # {% for item in hass_caldav.urls %} @@ -148,6 +149,42 @@ binary_sensor: country: DE workdays: [mon, tue, wed, thu, fri] excludes: [sat, sun, holiday] + {% for target in hass_ping -%} + - platform: ping + name: ping_{{ target.name }} + host: {{ target.host }} + count: 1 + scan_interval: {{ target.interval_secs }} + {% endfor %} + +device_tracker: + - platform: ping + hosts: + {% for target in hass_ping -%} + {{ target.name }}: {{ target.host }} + {% endfor %} + +# enabling bluetooth +bluetooth: + +influxdb: + host: "{{ influxdb_url }}" + port: 443 + database: hass + username: hass + password: !secret influxdb_pass + ssl: true + verify_ssl: true + max_retries: 3 + default_measurement: state + include: + entities: + - sensor.washing_machine_electric_consumption_w + - sensor.washing_machine_electric_consumption_kwh + tags: + instance: prod + source: hass + home: S21 shell_command: matrixmsg: /usr/local/bin/matrixmsg.py diff --git a/roles/hass/templates/git-hass-config.sh.j2 b/roles/hass/templates/git-hass-config.sh.j2 index 4090c66..9d8b408 100644 --- a/roles/hass/templates/git-hass-config.sh.j2 +++ b/roles/hass/templates/git-hass-config.sh.j2 @@ -23,6 +23,7 @@ if ! grep -q "secrets.y[a]ml" ${PATH_REPO}/.gitignore; then fi mkdir -p ${PATH_REPO}/config/ +mkdir -p ${PATH_REPO}/config/.storage {% for item in hass_config_repo_files -%} cp ${PATH_HASS}/config/{{ item }} ${PATH_REPO}/config/{{ item }} diff --git a/roles/hass/templates/secrets.yaml.j2 b/roles/hass/templates/secrets.yaml.j2 index 6b9fd93..84174ce 100644 --- a/roles/hass/templates/secrets.yaml.j2 +++ b/roles/hass/templates/secrets.yaml.j2 @@ -1,7 +1,12 @@ -# kind of dont need this file +# this file is _not_ synced to the {{ hass_config_repo_name }} repo, so +# we can "safely" template in the actual secrets here and keep them out of +# configuration.yaml, which does get synced to the repo. caldav_user: "{{ hass_caldav.user }}" caldav_passwd: "{{ hass_caldav.passwd }}" voicerss_api_key: {{ voicerss_api_key }} + +# see group_vars/monitoring.yml +influxdb_pass: {{ hass_influxdb_pass }} -- 2.40.1