diff --git a/group_vars/all.yml b/group_vars/all.yml index eea0b7f..be2e892 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -174,9 +174,64 @@ wireguard: # - public_key: ZbLgn0EnkKbv8L6nxysix/fRoASNGFIIvEuLn/aLbm4= # allowed_ips: 10.100.0.3/32 -homeassistant: - version: 2024.1.3 - zigbee2mqtt: serial: - port: /dev/serial/by-id/usb-Silicon_Labs_Sonoff_Zigbee_3.0_USB_Dongle_Plus_0001-if00-port0 \ No newline at end of file + port: /dev/serial/by-id/usb-Silicon_Labs_Sonoff_Zigbee_3.0_USB_Dongle_Plus_0001-if00-port0 + +hydroqc2mqtt: + version: 1.2.0 + hydroquebec: + username: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 37396435663264653032376432313063666364353761303765356437383861303366323533363066 + 6661393635636230616264346235373132643164303436340a663937613063633432383932356638 + 35663432333137666133646633346431313934326263663962316361663938663132376566353433 + 3736633436616363630a623438373264393031363362356662313038393835386261653961633661 + 64386233613561663139343435636232623932353338333062396265373138393862 + password: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 61356433363930303239653231623766303130393962303666363438373365326133626131363230 + 3632656132336463386463373532396366393234326239340a643763393030626139313337326263 + 39616431636262616463386561636633653032346363313362646239643664633065363066336434 + 3339356430393765650a386561303332636434643935353735626234396266616132666465363033 + 62386336316437636233626332666361303963386365663733636533646163353561 + customer: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 32363839636334636261316134303366373731313966303365363031343935393033356635303161 + 3631393633616539363734373064356137393361346530620a303639356666306539613163636565 + 65643232663963393136396637623335396533313736616634316338616534633834653066343563 + 6663333737656464610a643161353236323630383837316562393233303361643339616630303934 + 3230 + account: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 38353533356530616532306539663561353266616364363963376432663666323131313739303265 + 6235646232323036623566346233626635643361616532370a626663623362653134303633383538 + 37616635326531623033353066316231393636333331643765616138386235343264376665393430 + 3830366336663861370a613464373866636136633361306433386430303864653139383731396434 + 3861 + contract: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 31616638626566366135386632303465383631646131633835386131366663353830316330323937 + 6161373134363433363737396434343462313335303735630a316338346332393139346434376231 + 65333362663362313638623064353365653464616638633139323361343162316130633131656230 + 3731326339666563360a396131373637343631623331373263663632336663626461646362363565 + 3532 + homeassistant: + token: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 31333333316533626430363132386665633238666537303936626438613738353134616437303635 + 3836636664363164313630303031663161653436323431320a393031656463376362633461653439 + 66643939643766306631303064653737633435636465333465343636623933393162303930366538 + 6465363062393038320a626139323362383263643662613737616266613535396334633566663833 + 66353638643465383539383539616337363333613366353865376666323736663633623236303239 + 63626134333765623138323231646234373234633163366433316439393762303763333865656331 + 34306431363239656161643964623565623232326366303362363330396263643636636636373435 + 65353234613433376531393836373635656165613539646133366238396139663665623465326436 + 30353539346332626564316335663731663631613965316433373863633137333564356233613139 + 63626330636561326564373431373961376332613836666562623832663632663764336333333036 + 62393635323130333535353634303238376161333462636437666436386663313464623661633030 + 37666361346139646534663632333762636464363566363933626634353730373163323231303162 + 66363939656339373365303532313365333964326139643261653832653132636237 + +homeassistant: + version: 2024.1.3 \ No newline at end of file diff --git a/playbook.yml b/playbook.yml index 85e7874..b71b00e 100644 --- a/playbook.yml +++ b/playbook.yml @@ -30,6 +30,7 @@ - hosts: home-assistant roles: - zigbee2mqtt + - hydroqc2mqtt - home-assistant tasks: - name: Install home-assistant binary_sensors config diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml new file mode 100644 index 0000000..5c16294 --- /dev/null +++ b/roles/docker/tasks/main.yml @@ -0,0 +1,22 @@ +- name: Download docker repository gpg key + get_url: + url: https://download.docker.com/linux/ubuntu/gpg + dest: /usr/share/keyrings/docker.asg + +- name: Add docker repository + apt_repository: + repo: deb [arch=amd64 signed-by=/usr/share/keyrings/docker.asg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable + +- name: Install docker + apt: + update_cache: true + name: + - docker-ce + - docker-ce-cli + - python3-docker + +- name: Enable docker service + systemd: + name: docker + state: started + enabled: yes \ No newline at end of file diff --git a/roles/home-assistant/meta/main.yml b/roles/home-assistant/meta/main.yml new file mode 100644 index 0000000..b456d40 --- /dev/null +++ b/roles/home-assistant/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - role: docker \ No newline at end of file diff --git a/roles/home-assistant/tasks/main.yml b/roles/home-assistant/tasks/main.yml index 033634e..2451da7 100644 --- a/roles/home-assistant/tasks/main.yml +++ b/roles/home-assistant/tasks/main.yml @@ -1,26 +1,3 @@ -- name: Download docker repository gpg key - get_url: - url: https://download.docker.com/linux/ubuntu/gpg - dest: /usr/share/keyrings/docker.asg - -- name: Add docker repository - apt_repository: - repo: deb [arch=amd64 signed-by=/usr/share/keyrings/docker.asg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable - -- name: Install docker - apt: - update_cache: true - name: - - docker-ce - - docker-ce-cli - - python3-docker - -- name: Enable docker service - systemd: - name: docker - state: started - enabled: yes - - name: Create home-assistant config directory file: path: /opt/homeassistant/config diff --git a/roles/hydroqc2mqtt/defaults/main.yml b/roles/hydroqc2mqtt/defaults/main.yml new file mode 100644 index 0000000..81126d4 --- /dev/null +++ b/roles/hydroqc2mqtt/defaults/main.yml @@ -0,0 +1,10 @@ +hydroqc2mqtt: + version: latest + hydroquebec: + username: + password: + customer: + account: + contract: + homeassistant: + token: \ No newline at end of file diff --git a/roles/hydroqc2mqtt/meta/main.yml b/roles/hydroqc2mqtt/meta/main.yml new file mode 100644 index 0000000..e886fef --- /dev/null +++ b/roles/hydroqc2mqtt/meta/main.yml @@ -0,0 +1,3 @@ +dependencies: + - role: docker + - role: mosquitto \ No newline at end of file diff --git a/roles/hydroqc2mqtt/tasks/main.yml b/roles/hydroqc2mqtt/tasks/main.yml new file mode 100644 index 0000000..a34454d --- /dev/null +++ b/roles/hydroqc2mqtt/tasks/main.yml @@ -0,0 +1,19 @@ +- name: Start hydroqc2mqtt + docker_container: + name: hydroqc2mqtt + image: registry.gitlab.com/hydroqc/hydroqc2mqtt:{{ hydroqc2mqtt.version }} + state: started + restart_policy: unless-stopped + network_mode: host + env: + MQTT_HOST: 'localhost' + MQTT_PORT: '1883' + HQ2M_CONTRACTS_0_NAME: 'home' + HQ2M_CONTRACTS_0_USERNAME: '{{ hydroqc2mqtt.hydroquebec.username }}' + HQ2M_CONTRACTS_0_PASSWORD: '{{ hydroqc2mqtt.hydroquebec.password }}' + HQ2M_CONTRACTS_0_CUSTOMER: '{{ hydroqc2mqtt.hydroquebec.customer }}' + HQ2M_CONTRACTS_0_ACCOUNT: '{{ hydroqc2mqtt.hydroquebec.account }}' + HQ2M_CONTRACTS_0_CONTRACT: '{{ hydroqc2mqtt.hydroquebec.contract }}' + HQ2M_CONTRACTS_0_SYNC_HOURLY_CONSUMPTION_ENABLED: "true" + HQ2M_CONTRACTS_0_HOME_ASSISTANT_WEBSOCKET_URL: 'http://localhost:8123/api/websocket' + HQ2M_CONTRACTS_0_HOME_ASSISTANT_TOKEN: '{{ hydroqc2mqtt.homeassistant.token }}' \ No newline at end of file diff --git a/roles/zigbee2mqtt/tasks/mosquitto.yml b/roles/mosquitto/tasks/main.yml similarity index 100% rename from roles/zigbee2mqtt/tasks/mosquitto.yml rename to roles/mosquitto/tasks/main.yml diff --git a/roles/zigbee2mqtt/meta/main.yml b/roles/zigbee2mqtt/meta/main.yml new file mode 100644 index 0000000..9afca2e --- /dev/null +++ b/roles/zigbee2mqtt/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - role: mosquitto \ No newline at end of file diff --git a/roles/zigbee2mqtt/tasks/main.yml b/roles/zigbee2mqtt/tasks/main.yml index da0cdf5..20e08f2 100644 --- a/roles/zigbee2mqtt/tasks/main.yml +++ b/roles/zigbee2mqtt/tasks/main.yml @@ -1,2 +1,64 @@ -- include_tasks: mosquitto.yml -- include_tasks: zigbee2mqtt.yml \ No newline at end of file +- name: Download NodeSource repository gpg key + get_url: + url: https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key + dest: /usr/share/keyrings/nodesource.asc + +- name: Add NodeSource nodejs repository + apt_repository: + repo: deb [arch=amd64 signed-by=/usr/share/keyrings/nodesource.asc] https://deb.nodesource.com/node_20.x nodistro main + +- name: Install required packages + apt: + update_cache: true + name: + - git + - nodejs + +- name: Clone a zigbee2mqtt git repository + git: + repo: https://github.com/Koenkk/zigbee2mqtt.git + dest: /opt/zigbee2mqtt + depth: 1 + update: false + register: git_clone + +- name: Install zigbee2mqtt + shell: + chdir: /opt/zigbee2mqtt + cmd: npm ci && npm run build + when: git_clone.changed + notify: Restart zigbee2mqtt + +- name: Enable zigbee2mqtt home-assistant integration + lineinfile: + path: /opt/zigbee2mqtt/data/configuration.yaml + line: "homeassistant: true" + regexp: '^homeassistant:' + notify: Restart zigbee2mqtt + +- name: Enable zigbee2mqtt frontend + lineinfile: + path: /opt/zigbee2mqtt/data/configuration.yaml + line: 'frontend: true' + regexp: '^frontend:' + notify: Restart zigbee2mqtt + +- name: Disable zigbee2mqtt network join + lineinfile: + path: /opt/zigbee2mqtt/data/configuration.yaml + line: 'permit_join: false' + regexp: '^permit_join:' + notify: Restart zigbee2mqtt + +- name: Install zigbee2mqtt systemd unit + template: + src: zigbee2mqtt.service + dest: /etc/systemd/system/zigbee2mqtt.service + mode: 0644 + notify: Restart zigbee2mqtt + +- name: Enable zigbee2mqtt service + systemd: + name: zigbee2mqtt + daemon_reload: yes + enabled: yes \ No newline at end of file diff --git a/roles/zigbee2mqtt/tasks/zigbee2mqtt.yml b/roles/zigbee2mqtt/tasks/zigbee2mqtt.yml deleted file mode 100644 index 20e08f2..0000000 --- a/roles/zigbee2mqtt/tasks/zigbee2mqtt.yml +++ /dev/null @@ -1,64 +0,0 @@ -- name: Download NodeSource repository gpg key - get_url: - url: https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key - dest: /usr/share/keyrings/nodesource.asc - -- name: Add NodeSource nodejs repository - apt_repository: - repo: deb [arch=amd64 signed-by=/usr/share/keyrings/nodesource.asc] https://deb.nodesource.com/node_20.x nodistro main - -- name: Install required packages - apt: - update_cache: true - name: - - git - - nodejs - -- name: Clone a zigbee2mqtt git repository - git: - repo: https://github.com/Koenkk/zigbee2mqtt.git - dest: /opt/zigbee2mqtt - depth: 1 - update: false - register: git_clone - -- name: Install zigbee2mqtt - shell: - chdir: /opt/zigbee2mqtt - cmd: npm ci && npm run build - when: git_clone.changed - notify: Restart zigbee2mqtt - -- name: Enable zigbee2mqtt home-assistant integration - lineinfile: - path: /opt/zigbee2mqtt/data/configuration.yaml - line: "homeassistant: true" - regexp: '^homeassistant:' - notify: Restart zigbee2mqtt - -- name: Enable zigbee2mqtt frontend - lineinfile: - path: /opt/zigbee2mqtt/data/configuration.yaml - line: 'frontend: true' - regexp: '^frontend:' - notify: Restart zigbee2mqtt - -- name: Disable zigbee2mqtt network join - lineinfile: - path: /opt/zigbee2mqtt/data/configuration.yaml - line: 'permit_join: false' - regexp: '^permit_join:' - notify: Restart zigbee2mqtt - -- name: Install zigbee2mqtt systemd unit - template: - src: zigbee2mqtt.service - dest: /etc/systemd/system/zigbee2mqtt.service - mode: 0644 - notify: Restart zigbee2mqtt - -- name: Enable zigbee2mqtt service - systemd: - name: zigbee2mqtt - daemon_reload: yes - enabled: yes \ No newline at end of file