From d579391c348e570e139fb6a49dbdc0736aea6416 Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Sat, 8 Jun 2024 21:45:32 +0200 Subject: [PATCH] Add sensors-polling deployment. --- deploy.yml | 82 +------ tasks/deploy_sensors-polling.yml | 70 ++++++ tasks/deploy_thermostat.yml | 78 +++++++ templates/sensors-polling-conf.j2 | 201 ++++++++++++++++++ .../{conf.yml.j2 => thermostat-conf.yml.j2} | 0 5 files changed, 355 insertions(+), 76 deletions(-) create mode 100644 tasks/deploy_sensors-polling.yml create mode 100644 tasks/deploy_thermostat.yml create mode 100644 templates/sensors-polling-conf.j2 rename templates/{conf.yml.j2 => thermostat-conf.yml.j2} (100%) diff --git a/deploy.yml b/deploy.yml index 391ffb8..0c95575 100644 --- a/deploy.yml +++ b/deploy.yml @@ -37,80 +37,10 @@ - /mnt/apps/volumes/homeassistant_conf:/config become: true - - name: create docker-mounted-files directory - ansible.builtin.file: - path: "/usr/local/docker-mounted-files/docker-thermostat" - state: directory - become: true + - name: Include deploy_thermostat tasks + ansible.builtin.include_tasks: "tasks/deploy_thermostat.yml" + tags: deploy_thermostat - - name: Template thermostat conf.yml - ansible.builtin.template: - src: templates/conf.yml.j2 - dest: /usr/local/docker-mounted-files/docker-thermostat/conf.yml - become: true - - - name: Build thermostat image - ansible.builtin.include_role: - name: role_build_container_image - vars: - image: "{{ item }}" - with_items: - - repo_url: https://git.scimetis.net/yohan/docker-thermostat.git - repo_name: docker-thermostat - name: thermostat - result_var: build_result - - - debug: var=build_result - when: build_result.changed - - - name: Gather facts on thermostat container - containers.podman.podman_container_info: - name: thermostat - register: container_info - become: true - - - debug: var=container_info.containers[0].Config.Annotations.git_commit - when: container_info.containers | length == 1 - - - name: Set fact bool_recreate to true - set_fact: - bool_recreate: true - when: - - container_info.containers | length == 1 - - container_info.containers[0].Config.Annotations.git_commit != commit - - - name: create thermostat volume - ansible.builtin.file: - path: "/mnt/apps/volumes/thermostat" - state: directory - become: true - - - name: Delete thermostat container - containers.podman.podman_container: - name: thermostat - state: absent - become: true - when: bool_recreate | default(false) - - - name: Create thermostat container - containers.podman.podman_container: - name: thermostat - image: localhost/thermostat:latest - network: - - host - env: - TZ: "Europe/Paris" - GUNICORN_CMD_ARGS: "--bind=0.0.0.0:3002" - privileged: true - restart_policy: always - volume: - - /usr/local/docker-mounted-files/docker-thermostat/conf.yml:/root/conf.yml - - /mnt/apps/volumes/thermostat:/root/instance - - /run/udev:/run/udev - become: true - when: bool_recreate | default(false) or container_info.containers | length == 0 - - - name: Prune images - containers.podman.podman_prune: - image: true - become: true + - name: Include deploy_sensors-polling tasks + ansible.builtin.include_tasks: "tasks/deploy_sensors-polling.yml" + tags: deploy_sensors-polling diff --git a/tasks/deploy_sensors-polling.yml b/tasks/deploy_sensors-polling.yml new file mode 100644 index 0000000..5525610 --- /dev/null +++ b/tasks/deploy_sensors-polling.yml @@ -0,0 +1,70 @@ +--- +- name: create docker-mounted-files directory + ansible.builtin.file: + path: "/usr/local/docker-mounted-files/docker-sensors-polling" + state: directory + become: true + +- name: Template sensors-polling conf.yml + ansible.builtin.template: + src: templates/sensors-polling-conf.yml.j2 + dest: /usr/local/docker-mounted-files/docker-sensors-polling/conf.yml + become: true + +- name: Build sensors-polling image + ansible.builtin.include_role: + name: role_build_container_image + vars: + image: "{{ item }}" + with_items: + - repo_url: https://git.scimetis.net/yohan/docker-sensors-polling.git + repo_name: docker-sensors-polling + name: sensors-polling + result_var: build_result + +- debug: var=build_result + when: build_result.changed + +- name: Gather facts on sensors-polling container + containers.podman.podman_container_info: + name: sensors-polling + register: container_info + become: true + +- debug: var=container_info.containers[0].Config.Annotations.git_commit + when: container_info.containers | length == 1 + +- name: Set fact bool_recreate to true + set_fact: + bool_recreate: true + when: + - container_info.containers | length == 1 + - container_info.containers[0].Config.Annotations.git_commit != commit + +- name: Delete sensors-polling container + containers.podman.podman_container: + name: sensors-polling + state: absent + become: true + when: bool_recreate | default(false) + +- name: Create sensors-polling container + containers.podman.podman_container: + name: sensors-polling + image: localhost/sensors-polling:latest + network: + - host + env: + TZ: "Europe/Paris" + privileged: true + restart_policy: always + volume: + - /usr/local/docker-mounted-files/docker-sensors-polling/conf.yml:/root/conf.yml + - /run/udev:/run/udev + become: true + when: bool_recreate | default(false) or container_info.containers | length == 0 + +- name: Prune images + containers.podman.podman_prune: + image: true + become: true diff --git a/tasks/deploy_thermostat.yml b/tasks/deploy_thermostat.yml new file mode 100644 index 0000000..cac9cae --- /dev/null +++ b/tasks/deploy_thermostat.yml @@ -0,0 +1,78 @@ +--- +- name: create docker-mounted-files directory + ansible.builtin.file: + path: "/usr/local/docker-mounted-files/docker-thermostat" + state: directory + become: true + +- name: Template thermostat conf.yml + ansible.builtin.template: + src: templates/thermostat-conf.yml.j2 + dest: /usr/local/docker-mounted-files/docker-thermostat/conf.yml + become: true + +- name: Build thermostat image + ansible.builtin.include_role: + name: role_build_container_image + vars: + image: "{{ item }}" + with_items: + - repo_url: https://git.scimetis.net/yohan/docker-thermostat.git + repo_name: docker-thermostat + name: thermostat + result_var: build_result + +- debug: var=build_result + when: build_result.changed + +- name: Gather facts on thermostat container + containers.podman.podman_container_info: + name: thermostat + register: container_info + become: true + +- debug: var=container_info.containers[0].Config.Annotations.git_commit + when: container_info.containers | length == 1 + +- name: Set fact bool_recreate to true + set_fact: + bool_recreate: true + when: + - container_info.containers | length == 1 + - container_info.containers[0].Config.Annotations.git_commit != commit + +- name: create thermostat volume + ansible.builtin.file: + path: "/mnt/apps/volumes/thermostat" + state: directory + become: true + +- name: Delete thermostat container + containers.podman.podman_container: + name: thermostat + state: absent + become: true + when: bool_recreate | default(false) + +- name: Create thermostat container + containers.podman.podman_container: + name: thermostat + image: localhost/thermostat:latest + network: + - host + env: + TZ: "Europe/Paris" + GUNICORN_CMD_ARGS: "--bind=0.0.0.0:3002" + privileged: true + restart_policy: always + volume: + - /usr/local/docker-mounted-files/docker-thermostat/conf.yml:/root/conf.yml + - /mnt/apps/volumes/thermostat:/root/instance + - /run/udev:/run/udev + become: true + when: bool_recreate | default(false) or container_info.containers | length == 0 + +- name: Prune images + containers.podman.podman_prune: + image: true + become: true diff --git a/templates/sensors-polling-conf.j2 b/templates/sensors-polling-conf.j2 new file mode 100644 index 0000000..810e8cf --- /dev/null +++ b/templates/sensors-polling-conf.j2 @@ -0,0 +1,201 @@ +http_port: 3000 + +# The output of the command must be a JSON dict with metrics name as keys and metrics value as value. +polling_conf: + - name: teleinfo + metrics: + - name: Modane_elec_main_power + type: int + - name: Modane_elec_energy_index + type: int + executable: ./read_teleinfo.py + arguments: + - "-f" + - "custom_json" + # interval between sensors polling in seconds + polling_interval: 10.0 + + - name: Modane_temperature_single_bedroom + metrics: + - name: Modane_temperature_single_bedroom + type: float + executable: ./read_one-wire_sensor.py + arguments: + - "Modane_temperature_single_bedroom" + - "/26.3FA954020000/temperature" + + - name: Modane_temperature_double_bedroom + metrics: + - name: Modane_temperature_double_bedroom + type: float + executable: ./read_one-wire_sensor.py + arguments: + - "Modane_temperature_double_bedroom" + - "/26.A6E96B020000/temperature" + + - name: Modane_temperature_living_room + metrics: + - name: Modane_temperature_living_room + type: float + executable: ./read_one-wire_sensor.py + arguments: + - "Modane_temperature_living_room" + - "/26.23D26B020000/temperature" + + - name: Modane_temperature_bathroom + metrics: + - name: Modane_temperature_bathroom + type: float + executable: ./read_one-wire_sensor.py + arguments: + - "Modane_temperature_bathroom" + - "/26.A4C354020000/temperature" + + - name: Modane_temperature_cellar + metrics: + - name: Modane_temperature_cellar + type: float + executable: ./read_yocto_sensor.py + arguments: + - "Modane_temperature_cellar" + - "YTemperature" + - "METEOMK1-65C96" + + #- name: Modane_temperature_outside + # metrics: + # - name: Modane_temperature_outside + # type: float + + - name: Modane_temperature_closet + metrics: + - name: Modane_temperature_closet + type: float + executable: ./read_yocto_sensor.py + arguments: + - "Modane_temperature_closet" + - "YTemperature" + - "TMPSENS1-EDF2D" + + - name: Modane_humidity_single_bedroom + metrics: + - name: Modane_humidity_single_bedroom + type: float + executable: ./read_one-wire_sensor.py + arguments: + - "Modane_humidity_single_bedroom" + - "/26.3FA954020000/humidity" + + - name: Modane_humidity_double_bedroom + metrics: + - name: Modane_humidity_double_bedroom + type: float + executable: ./read_one-wire_sensor.py + arguments: + - "Modane_humidity_double_bedroom" + - "/26.A6E96B020000/humidity" + + - name: Modane_humidity_bathroom + metrics: + - name: Modane_humidity_bathroom + type: float + executable: ./read_one-wire_sensor.py + arguments: + - "Modane_humidity_bathroom" + - "/26.A4C354020000/humidity" + + - name: Modane_humidity_living_room + metrics: + - name: Modane_humidity_living_room + type: float + executable: ./read_one-wire_sensor.py + arguments: + - "Modane_humidity_living_room" + - "/26.23D26B020000/humidity" + + - name: Modane_humidity_cellar + metrics: + - name: Modane_humidity_cellar + type: float + executable: ./read_yocto_sensor.py + arguments: + - "Modane_humidity_cellar" + - "YHumidity" + - "METEOMK1-65C96" + + #- name: Modane_humidity_outside + # metrics: + # - name: Modane_humidity_outside + # type: float + # executable: ./read_yocto_sensor.py + # arguments: + # - "Modane_humidity_outside" + # - "YHumidity" + # - "" + + - name: Modane_luminosity_single_bedroom + metrics: + - name: Modane_luminosity_single_bedroom + type: int + executable: ./read_one-wire_sensor.py + arguments: + - "Modane_luminosity_single_bedroom" + - "/26.3FA954020000/vis" + + - name: Modane_luminosity_double_bedroom + metrics: + - name: Modane_luminosity_double_bedroom + type: int + executable: ./read_one-wire_sensor.py + arguments: + - "Modane_luminosity_double_bedroom" + - "/26.A6E96B020000/vis" + + - name: Modane_luminosity_bathroom + metrics: + - name: Modane_luminosity_bathroom + type: int + executable: ./read_one-wire_sensor.py + arguments: + - "Modane_luminosity_bathroom" + - "/26.A4C354020000/vis" + + - name: Modane_luminosity_living_room + metrics: + - name: Modane_luminosity_living_room + type: int + executable: ./read_one-wire_sensor.py + arguments: + - "Modane_luminosity_living_room" + - "/26.23D26B020000/vis" + + - name: Modane_pressure_cellar + metrics: + - name: Modane_pressure_cellar + type: float + executable: ./read_yocto_sensor.py + arguments: + - "Modane_pressure_cellar" + - "YPressure" + - "METEOMK1-65C96" + + - name: Modane_CO2_single_bedroom + metrics: + - name: Modane_CO2_single_bedroom + type: float + executable: ./read_yocto_sensor.py + arguments: + - "Modane_CO2_single_bedroom" + - "YCarbonDioxide" + - "any" + +# Default interval between sending to record API in seconds +default_recording_interval: 600.0 + +# Default interval between sensors polling in seconds +default_polling_interval: 600.0 + +recording_api_key: "{{ modane_server_thermostat_api_key }}" + +post_url: + int: "http://ovh1.scimetis.net:3001/integer_metric/add" + float: "http://ovh1.scimetis.net:3001/float_metric/add" diff --git a/templates/conf.yml.j2 b/templates/thermostat-conf.yml.j2 similarity index 100% rename from templates/conf.yml.j2 rename to templates/thermostat-conf.yml.j2