├── emoncms ├── rootfs │ └── etc │ │ ├── php8 │ │ ├── blacklist.txt │ │ ├── php-fpm.d │ │ │ └── www.conf │ │ └── conf.d │ │ │ └── 99-emoncms.ini │ │ ├── fix-attrs.d │ │ └── 01-emoncms │ │ ├── services.d │ │ ├── nginx │ │ │ ├── finish │ │ │ └── run │ │ └── php-fpm │ │ │ ├── finish │ │ │ └── run │ │ ├── cont-init.d │ │ ├── nginx.sh │ │ └── emoncms.sh │ │ └── nginx │ │ ├── nginx.conf │ │ └── nginx-ssl.conf ├── .README.j2 ├── icon.png ├── build.json ├── config.json ├── Dockerfile └── DOCS.md ├── repository.json ├── .pre-commit-config.yaml ├── .github ├── dependabot.yml └── workflows │ ├── publish.yml │ └── ci.yml ├── README.md ├── LICENSE.md ├── CONTRIBUTION.md ├── .devcontainer ├── devcontainer.json ├── Dockerfile └── start_ha.sh └── .vscode └── tasks.json /emoncms/rootfs/etc/php8/blacklist.txt: -------------------------------------------------------------------------------- 1 | /data/emoncms/* 2 | -------------------------------------------------------------------------------- /emoncms/.README.j2: -------------------------------------------------------------------------------- 1 | # Home Assistant Community Add-on: Emoncms 2 | 3 | TBD 4 | -------------------------------------------------------------------------------- /emoncms/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inverse/hassio-addon-emoncms/HEAD/emoncms/icon.png -------------------------------------------------------------------------------- /emoncms/rootfs/etc/fix-attrs.d/01-emoncms: -------------------------------------------------------------------------------- 1 | /var/www/emoncms true nginx 0644 0755 2 | /data/emoncms/phpfina true nginx 0644 0755 3 | /data/emoncms/phptimeseries true nginx 0644 0755 4 | -------------------------------------------------------------------------------- /repository.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "name": "Home Assistant Emoncms Repository", 4 | "url": "https://github.com/inverse/hassio-addon-emoncms", 5 | "maintainer": "Malachi Soord " 6 | } 7 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v2.4.0 4 | hooks: 5 | - id: trailing-whitespace 6 | - id: end-of-file-fixer 7 | - id: check-yaml 8 | - id: check-added-large-files 9 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | - package-ecosystem: "docker" 8 | directory: "/" 9 | schedule: 10 | interval: "daily" 11 | -------------------------------------------------------------------------------- /emoncms/rootfs/etc/php8/php-fpm.d/www.conf: -------------------------------------------------------------------------------- 1 | [www] 2 | user = nginx 3 | group = nginx 4 | listen = 127.0.0.1:9001 5 | pm = dynamic 6 | pm.max_children = 10 7 | pm.start_servers = 3 8 | pm.min_spare_servers = 2 9 | pm.max_spare_servers = 5 10 | pm.max_requests = 1024 11 | clear_env = no 12 | -------------------------------------------------------------------------------- /emoncms/rootfs/etc/php8/conf.d/99-emoncms.ini: -------------------------------------------------------------------------------- 1 | [general] 2 | max_execution_time = 900 3 | opcache.enable=1 4 | opcache.interned_strings_buffer=8 5 | opcache.max_accelerated_files=4096 6 | opcache.memory_consumption=32 7 | opcache.revalidate_freq=0 8 | opcache.validate_timestamps=0 9 | opcache.blacklist_filename=/etc/php8/blacklist.txt 10 | -------------------------------------------------------------------------------- /emoncms/build.json: -------------------------------------------------------------------------------- 1 | { 2 | "build_from": { 3 | "aarch64": "ghcr.io/hassio-addons/base/aarch64:11.1.0", 4 | "amd64": "ghcr.io/hassio-addons/base/amd64:11.1.0", 5 | "armhf": "ghcr.io/hassio-addons/base/armhf:11.1.0", 6 | "armv7": "ghcr.io/hassio-addons/base/armv7:11.1.0", 7 | "i386": "ghcr.io/hassio-addons/base/i386:11.1.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /emoncms/rootfs/etc/services.d/nginx/finish: -------------------------------------------------------------------------------- 1 | #!/usr/bin/execlineb -S0 2 | # ============================================================================== 3 | # Home Assistant Community Add-on: Emoncms 4 | # Take down the S6 supervision tree when Nginx fails 5 | # ============================================================================== 6 | if -n { s6-test $# -ne 0 } 7 | if -n { s6-test ${1} -eq 256 } 8 | 9 | s6-svscanctl -t /var/run/s6/services 10 | -------------------------------------------------------------------------------- /emoncms/rootfs/etc/services.d/php-fpm/finish: -------------------------------------------------------------------------------- 1 | #!/usr/bin/execlineb -S0 2 | # ============================================================================== 3 | # Home Assistant Community Add-on: Emoncms 4 | # Take down the S6 supervision tree when PHP FPM fails 5 | # ============================================================================== 6 | if -n { s6-test $# -ne 0 } 7 | if -n { s6-test ${1} -eq 256 } 8 | 9 | s6-svscanctl -t /var/run/s6/services 10 | -------------------------------------------------------------------------------- /emoncms/rootfs/etc/services.d/nginx/run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/with-contenv bashio 2 | # ============================================================================== 3 | # Home Assistant Community Add-on: Emoncms 4 | # Runs the Nginx daemon 5 | # ============================================================================== 6 | # Wait for PHP-FPM to become available 7 | bashio::net.wait_for 9001 8 | bashio::log.info "Starting NGinx server..." 9 | exec nginx -g "daemon off;" 10 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: 'Publish' 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | publish: 9 | name: Publish 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout the repository 13 | uses: actions/checkout@v3 14 | - name: Login to DockerHub 15 | uses: docker/login-action@v2 16 | with: 17 | username: ${{ secrets.DOCKERHUB_USERNAME }} 18 | password: ${{ secrets.DOCKERHUB_TOKEN }} 19 | - name: Publish 20 | uses: home-assistant/builder@master 21 | with: 22 | args: | 23 | --all \ 24 | --target emoncms \ 25 | --docker-hub inversechi 26 | -------------------------------------------------------------------------------- /emoncms/rootfs/etc/cont-init.d/nginx.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/with-contenv bashio 2 | # ============================================================================== 3 | # Home Assistant Community Add-on: Emoncms 4 | # Configures NGINX for use with Emoncms 5 | # ============================================================================== 6 | declare certfile 7 | declare keyfile 8 | 9 | bashio::config.require.ssl 10 | 11 | if bashio::config.true 'ssl'; then 12 | rm /etc/nginx/nginx.conf 13 | mv /etc/nginx/nginx-ssl.conf /etc/nginx/nginx.conf 14 | 15 | certfile=$(bashio::config 'certfile') 16 | keyfile=$(bashio::config 'keyfile') 17 | 18 | sed -i "s#%%certfile%%#${certfile}#g" /etc/nginx/nginx.conf 19 | sed -i "s#%%keyfile%%#${keyfile}#g" /etc/nginx/nginx.conf 20 | fi 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Home Assistant Add-on: Emoncms 2 | 3 | ## Note 4 | 5 | This addon is very much unmaintained, thankfully there is a more maintained addmon provided by [Open Building Management](https://github.com/Open-Building-Management/emoncms). 6 | 7 | ## About 8 | 9 | [Emoncms][emoncms] is a powerful open-source web-app for processing, logging and visualising energy, temperature and other environmental data. 10 | 11 | Disclaimer: This addon is WIP and not ready for stable use. If you do choose to adopt it please report back any issues your having and how they can be improved. 12 | 13 | [Full Documentation][docs] 14 | 15 | ## Contributing 16 | 17 | See the [contributing](CONTRIBUTION.md) documentation for more information. 18 | 19 | ## License 20 | 21 | MIT License 22 | 23 | [emoncms]: https://emoncms.org/ 24 | [docs]: emoncms/DOCS.md 25 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2021 Malachi Soord 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /emoncms/rootfs/etc/services.d/php-fpm/run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/with-contenv bashio 2 | # ============================================================================== 3 | # Home Assistant Community Add-on: Emoncms 4 | # Runs the PHP-FPM daemon 5 | # ============================================================================== 6 | export MYSQL_HOST 7 | export MYSQL_NAME 8 | export MYSQL_USERNAME 9 | export MYSQL_PASSWORD 10 | export MYSQL_PORT 11 | 12 | if bashio::config.has_value 'remote_mysql_host';then 13 | MYSQL_HOST=$(bashio::config "remote_mysql_host") 14 | MYSQL_NAME=$(bashio::config "remote_mysql_database") 15 | MYSQL_USERNAME=$(bashio::config "remote_mysql_username") 16 | MYSQL_PASSWORD=$(bashio::config "remote_mysql_password") 17 | MYSQL_PORT=$(bashio::config "remote_mysql_port") 18 | else 19 | MYSQL_HOST=$(bashio::services "mysql" "host") 20 | MYSQL_NAME=emoncms 21 | MYSQL_USERNAME=$(bashio::services "mysql" "username") 22 | MYSQL_PASSWORD=$(bashio::services "mysql" "password") 23 | MYSQL_PORT=$(bashio::services "mysql" "port") 24 | fi 25 | 26 | bashio::log.info "Starting PHP-FPM server..." 27 | exec php-fpm8 -R --nodaemonize 28 | -------------------------------------------------------------------------------- /CONTRIBUTION.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | This guide outlines the steps required for contributing to this project. 4 | 5 | ## Submitting issues 6 | 7 | Be sure to check existing issues first before submitting a new issue report. 8 | 9 | Try to include as much information as possible, with screenshots if it helps explain the problem. 10 | 11 | ## Development 12 | 13 | The easiest way to get your development environment setup is to use [Visual Studio Code][0] with the [Visual Studio Code Remote - Containers][1] extension. Follow the instructions on there on the pre-requisites to getting going. 14 | 15 | First open this project within the container. It make take some time to pull the relevant base images and build the container. 16 | 17 | Next, Open the task view and run "Start Home Assistant". This make take some time but after a few minutes you should be able to get a working instance of Home Assistant up on `http://localhost:8123`. 18 | 19 | From here you'll be able to set things up like you would normally and install the MariaDB addon to provide the database for this extension. 20 | 21 | 22 | [0]: https://code.visualstudio.com/ 23 | [1]: https://code.visualstudio.com/docs/remote/containers 24 | -------------------------------------------------------------------------------- /emoncms/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Emoncms", 3 | "version": "0.7.1", 4 | "slug": "emoncms", 5 | "description": "Emoncms is a powerful open-source web-app for processing, logging and visualising energy, temperature and other environmental data.", 6 | "url": "https://github.com/inverse/hassio-addon-emoncms", 7 | "webui": "[PROTO:ssl]://[HOST]:[PORT:9541]", 8 | "startup": "system", 9 | "init": false, 10 | "arch": ["aarch64", "amd64", "armhf", "armv7", "i386"], 11 | "services": ["mysql:want"], 12 | "map": ["ssl"], 13 | "ports": { 14 | "80/tcp": 9541 15 | }, 16 | "ports_description": { 17 | "80/tcp": "Emoncms web interface" 18 | }, 19 | "options": { 20 | "ssl": true, 21 | "certfile": "fullchain.pem", 22 | "keyfile": "privkey.pem" 23 | }, 24 | "schema": { 25 | "log_level": "list(trace|debug|info|notice|warning|error|fatal)?", 26 | "ssl": "bool", 27 | "certfile": "str", 28 | "keyfile": "str", 29 | "remote_mysql_host": "str?", 30 | "remote_mysql_database": "str?", 31 | "remote_mysql_username": "str?", 32 | "remote_mysql_password": "str?", 33 | "remote_mysql_port": "int?" 34 | }, 35 | "image": "inversechi/hassio-emoncms-{arch}" 36 | } 37 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: 'Test' 2 | 3 | on: 4 | pull_request: 5 | branches: ["master"] 6 | push: 7 | branches: ["master"] 8 | 9 | jobs: 10 | lint-general: 11 | name: Lint 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout the repository 15 | uses: actions/checkout@v3 16 | - name: Install pre-commit 17 | run: pip install pre-commit 18 | - name: Lint 19 | run: pre-commit run --all-files 20 | lint-addon: 21 | name: Add-on configuration 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Checkout the repository 25 | uses: actions/checkout@v3 26 | - name: 🚀 Run Home Assistant Add-on Lint 27 | uses: frenck/action-addon-linter@v2.10 28 | with: 29 | path: "./emoncms" 30 | build: 31 | name: Test build 32 | needs: 33 | - lint-general 34 | - lint-addon 35 | runs-on: ubuntu-latest 36 | steps: 37 | - name: Checkout the repository 38 | uses: actions/checkout@v3 39 | - name: Test build 40 | uses: home-assistant/builder@master 41 | with: 42 | args: | 43 | --test \ 44 | --all \ 45 | --target emoncms \ 46 | --docker-hub inversechi 47 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/vscode-remote/devcontainer.json 2 | // TODO: When https://github.com/microsoft/vscode-remote-release/issues/2129 is fixed, move to ${localWorkspaceFolderBasename}\ 3 | { 4 | "name": "Home Assistant Add-On", 5 | "context": "..", 6 | "dockerFile": "Dockerfile", 7 | "appPort": 8123, 8 | "runArgs": [ 9 | "-e", 10 | "GIT_EDITOR=code --wait", 11 | "--privileged" 12 | ], 13 | "settings": { 14 | "terminal.integrated.shell.linux": "/bin/bash" 15 | }, 16 | "workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/test_hassio/addons/local/emoncms,type=bind,consistency=delegated", 17 | "workspaceFolder": "/workspaces/test_hassio/addons/local/emoncms", 18 | "mounts": [ 19 | // Cache docker images between devcontainer rebuilds (and share between devcontainers) 20 | "source=vsc-hassio-docker,target=/var/lib/docker,type=volume" 21 | ] 22 | 23 | // Post-create command to initialize the workspace. For example, for a node.js add-on you may want: 24 | // "postCreateCommand": "cd /workspaces/test_hassio/addons/local/myaddon && npm install", 25 | // "extensions": [ 26 | // "dbaeumer.vscode-eslint", 27 | // "maty.vscode-mocha-sidebar" 28 | // ] 29 | } 30 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "Start Home Assistant", 8 | "type": "shell", 9 | "command": "/usr/local/bin/start_ha.sh", 10 | "group": { 11 | "kind": "test", 12 | "isDefault": true, 13 | }, 14 | "presentation": { 15 | "reveal": "always", 16 | "panel": "new" 17 | }, 18 | "problemMatcher": [] 19 | },{ 20 | "label": "Cleanup stale Home Assistant environment", 21 | "type": "shell", 22 | "command": "/usr/local/bin/start_ha.sh --cleanup", 23 | "group": "test", 24 | "presentation": { 25 | "reveal": "always", 26 | "panel": "new" 27 | }, 28 | "problemMatcher": [] 29 | },{ 30 | "label": "Run Home Assistant CLI", 31 | "type": "shell", 32 | "command": "docker run --rm -ti -v /etc/machine-id:/etc/machine-id --network=hassio --add-host hassio:172.30.32.2 homeassistant/amd64-hassio-cli:dev", 33 | "group": "test", 34 | "presentation": { 35 | "reveal": "always", 36 | "panel": "new" 37 | }, 38 | "problemMatcher": [] 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /emoncms/rootfs/etc/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | worker_processes 1; 2 | pid /var/run/nginx.pid; 3 | user nginx nginx; 4 | 5 | # Write error log to the add-on log. 6 | error_log /proc/1/fd/1 error; 7 | 8 | events { 9 | worker_connections 1024; 10 | } 11 | 12 | http { 13 | include mime.types; 14 | 15 | log_format homeassistant '[$time_local] $status ' 16 | '$http_x_forwarded_for($remote_addr) ' 17 | '$request ($http_user_agent)'; 18 | 19 | access_log /proc/1/fd/1 homeassistant; 20 | client_max_body_size 4G; 21 | default_type application/octet-stream; 22 | gzip on; 23 | keepalive_timeout 65; 24 | sendfile on; 25 | server_tokens off; 26 | tcp_nodelay on; 27 | tcp_nopush on; 28 | 29 | server { 30 | server_name hassio.local; 31 | listen 80 default_server; 32 | root /var/www/emoncms; 33 | index index.php; 34 | 35 | location ~ .php$ { 36 | fastcgi_pass 127.0.0.1:9001; 37 | fastcgi_read_timeout 900; 38 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 39 | fastcgi_index index.php; 40 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 41 | include fastcgi_params; 42 | } 43 | 44 | location ~ ^(.*)\.(css|js|gif|jpe?g|png|)$ { 45 | } 46 | 47 | location / { 48 | index index.php; 49 | rewrite ^/(.*)$ /index.php?q=$1 last; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:20.04 2 | 3 | WORKDIR /workspaces 4 | 5 | # Default ENV 6 | ENV LANG C.UTF-8 7 | ENV DEBIAN_FRONTEND noninteractive 8 | 9 | # Set shell 10 | SHELL ["/bin/bash", "-o", "pipefail", "-c"] 11 | 12 | # Use the mirror protocol for a fast mirror 13 | RUN sed -i -e 's/http:\/\/archive\.ubuntu\.com\/ubuntu\//mirror:\/\/mirrors\.ubuntu\.com\/mirrors\.txt/' /etc/apt/sources.list 14 | 15 | # Install docker, jq, socat 16 | # https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/ 17 | RUN apt-get update && apt-get install -y --no-install-recommends \ 18 | apt-transport-https \ 19 | ca-certificates \ 20 | curl \ 21 | dbus \ 22 | software-properties-common \ 23 | gpg-agent \ 24 | git \ 25 | jq \ 26 | socat \ 27 | sudo \ 28 | && curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - \ 29 | && add-apt-repository "deb https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \ 30 | && apt-get update && apt-get install -y --no-install-recommends \ 31 | docker-ce \ 32 | docker-ce-cli \ 33 | containerd.io 34 | # This is a development container. Don't bother to clean up apt cache, this way we have it handy later 35 | 36 | COPY .devcontainer/start_ha.sh /usr/local/bin/start_ha.sh 37 | 38 | # Install dependencies for the add-on development below. For example, if you're running Node.js, 39 | # you may want something like the following... 40 | # RUN apt-get install -y --no-install-recommends nodejs npm 41 | 42 | # Generate a machine-id for this container 43 | RUN rm /etc/machine-id && dbus-uuidgen --ensure=/etc/machine-id 44 | 45 | ENV DEBIAN_FRONTEND=dialog 46 | -------------------------------------------------------------------------------- /emoncms/rootfs/etc/nginx/nginx-ssl.conf: -------------------------------------------------------------------------------- 1 | worker_processes 1; 2 | pid /var/run/nginx.pid; 3 | user nginx nginx; 4 | 5 | 6 | 7 | events { 8 | worker_connections 1024; 9 | } 10 | 11 | http { 12 | include mime.types; 13 | 14 | log_format homeassistant '[$time_local] $status ' 15 | '$http_x_forwarded_for($remote_addr) ' 16 | '$request ($http_user_agent)'; 17 | 18 | access_log /proc/1/fd/1 homeassistant; 19 | client_max_body_size 4G; 20 | default_type application/octet-stream; 21 | gzip on; 22 | keepalive_timeout 65; 23 | sendfile on; 24 | server_tokens off; 25 | tcp_nodelay on; 26 | tcp_nopush on; 27 | 28 | server { 29 | server_name hassio.local; 30 | listen 80 default_server ssl; 31 | root /var/www/emoncms; 32 | index index.php; 33 | 34 | ssl_certificate /ssl/%%certfile%%; 35 | ssl_certificate_key /ssl/%%keyfile%%; 36 | ssl_protocols TLSv1.2; 37 | ssl_prefer_server_ciphers on; 38 | ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA; 39 | ssl_ecdh_curve secp384r1; 40 | ssl_session_timeout 10m; 41 | ssl_session_cache shared:SSL:10m; 42 | ssl_session_tickets off; 43 | ssl_stapling on; 44 | ssl_stapling_verify on; 45 | 46 | add_header X-Content-Type-Options nosniff; 47 | add_header X-XSS-Protection "1; mode=block"; 48 | add_header X-Robots-Tag none; 49 | 50 | location ~ .php$ { 51 | fastcgi_pass 127.0.0.1:9001; 52 | fastcgi_read_timeout 900; 53 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 54 | fastcgi_index index.php; 55 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 56 | include fastcgi_params; 57 | } 58 | 59 | location ~ ^(.*)\.(css|js|gif|jpe?g|png|)$ { 60 | } 61 | 62 | location / { 63 | index index.php; 64 | rewrite ^/(.*)$ /index.php?q=$1 last; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /.devcontainer/start_ha.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eE 3 | 4 | DOCKER_TIMEOUT=30 5 | DOCKER_PID=0 6 | 7 | 8 | function start_docker() { 9 | local starttime 10 | local endtime 11 | 12 | echo "Starting docker..." 13 | dockerd 2> /dev/null & 14 | DOCKER_PID=$! 15 | 16 | echo "Waiting for docker to initialize..." 17 | starttime="$(date +%s)" 18 | endtime="$(date +%s)" 19 | until docker info >/dev/null 2>&1; do 20 | if [ $((endtime - starttime)) -le $DOCKER_TIMEOUT ]; then 21 | sleep 1 22 | endtime=$(date +%s) 23 | else 24 | echo "Timeout while waiting for docker to come up" 25 | exit 1 26 | fi 27 | done 28 | echo "Docker was initialized" 29 | } 30 | 31 | 32 | function stop_docker() { 33 | local starttime 34 | local endtime 35 | 36 | echo "Stopping in container docker..." 37 | if [ "$DOCKER_PID" -gt 0 ] && kill -0 "$DOCKER_PID" 2> /dev/null; then 38 | starttime="$(date +%s)" 39 | endtime="$(date +%s)" 40 | 41 | # Now wait for it to die 42 | kill "$DOCKER_PID" 43 | while kill -0 "$DOCKER_PID" 2> /dev/null; do 44 | if [ $((endtime - starttime)) -le $DOCKER_TIMEOUT ]; then 45 | sleep 1 46 | endtime=$(date +%s) 47 | else 48 | echo "Timeout while waiting for container docker to die" 49 | exit 1 50 | fi 51 | done 52 | else 53 | echo "Your host might have been left with unreleased resources" 54 | fi 55 | } 56 | 57 | 58 | function install() { 59 | docker pull homeassistant/amd64-hassio-supervisor:latest 60 | docker pull homeassistant/amd64-hassio-cli:latest 61 | } 62 | 63 | function cleanup_hass_data() { 64 | rm -rf /workspaces/test_hassio/{apparmor,backup,config.json,dns,dns.json,homeassistant,homeassistant.json,ingress.json,share,ssl,tmp,updater.json} 65 | rm -rf /workspaces/test_hassio/addons/{core,data,git} 66 | } 67 | 68 | function cleanup_docker() { 69 | echo "Cleaning up stopped containers..." 70 | docker rm $(docker ps -a -q) 71 | } 72 | 73 | function run_supervisor() { 74 | docker run --rm --privileged \ 75 | --name hassio_supervisor \ 76 | --security-opt seccomp=unconfined \ 77 | --security-opt apparmor:unconfined \ 78 | -v /run/docker.sock:/run/docker.sock \ 79 | -v /run/dbus:/run/dbus \ 80 | -v "/workspaces/test_hassio":/data \ 81 | -v /etc/machine-id:/etc/machine-id:ro \ 82 | -e SUPERVISOR_SHARE="/workspaces/test_hassio" \ 83 | -e SUPERVISOR_NAME=hassio_supervisor \ 84 | -e SUPERVISOR_DEV=1 \ 85 | -e HOMEASSISTANT_REPOSITORY="homeassistant/qemux86-64-homeassistant" \ 86 | homeassistant/amd64-hassio-supervisor:latest 87 | } 88 | 89 | case "$1" in 90 | "--cleanup") 91 | echo "Cleaning up old environment" 92 | cleanup_docker || true 93 | cleanup_hass_data || true 94 | exit 0;; 95 | *) 96 | echo "Creating development Home Assistant environment" 97 | start_docker 98 | trap "stop_docker" ERR 99 | install 100 | cleanup_docker || true 101 | run_supervisor 102 | stop_docker;; 103 | esac 104 | -------------------------------------------------------------------------------- /emoncms/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG BUILD_FROM=ghcr.io/hassio-addons/base/amd64:11.1.0 2 | # hadolint ignore=DL3006 3 | FROM ${BUILD_FROM} 4 | 5 | # Set shell 6 | SHELL ["/bin/bash", "-o", "pipefail", "-c"] 7 | 8 | # Setup base 9 | RUN \ 10 | apk add --no-cache \ 11 | nginx=1.20.2-r1 \ 12 | mariadb-client=10.6.10-r0 \ 13 | php8-ctype=8.0.25-r0 \ 14 | php8-curl=8.0.25-r0 \ 15 | php8-fpm=8.0.25-r0 \ 16 | php8-gettext=8.0.25-r0 \ 17 | php8-mbstring=8.0.25-r0 \ 18 | php8-mysqli=8.0.25-r0 \ 19 | php8-opcache=8.0.25-r00 \ 20 | php8-session=8.0.25-r0 \ 21 | php8-zip=8.0.25-r0 \ 22 | php8=8.0.25-r0 \ 23 | \ 24 | && ln -s /usr/bin/php8 /usr/bin/php \ 25 | && apk add --no-cache --virtual .build-dependencies \ 26 | git=2.34.5-r0 \ 27 | \ 28 | && git clone --branch 11.2.3 --depth=1 \ 29 | https://github.com/emoncms/emoncms.git /var/www/emoncms ; cd /var/www/emoncms \ 30 | && git clone --branch 2.3.3 --depth=1 \ 31 | https://github.com/emoncms/dashboard.git /var/www/emoncms/Modules/dashboard \ 32 | && git clone --branch 2.2.3 --depth=1 \ 33 | https://github.com/emoncms/graph.git /var/www/emoncms/Modules/graph \ 34 | && git clone --branch 2.6.7 --depth=1 \ 35 | https://github.com/emoncms/app.git /var/www/emoncms/Modules/app \ 36 | && git clone --branch 2.2.0 --depth=1 \ 37 | https://github.com/emoncms/device.git /var/www/emoncms/Modules/device \ 38 | \ 39 | && apk del --no-cache --purge .build-dependencies \ 40 | \ 41 | && rm -f -r /var/www/emoncms/.git \ 42 | && rm -f -r /var/www/emoncms/Modules/dashboard/.git \ 43 | && rm -f -r /var/www/emoncms/Modules/graph/.git \ 44 | && rm -f -r /var/www/emoncms/Modules/app/.git \ 45 | && rm -f -r /var/www/emoncms/Modules/device/.git \ 46 | && find /var/www/emoncms -type f -name ".htaccess" -depth -exec rm -f {} \; \ 47 | && find /var/www/emoncms -type f -name "*.md" -depth -exec rm -f {} \; \ 48 | && find /var/www/emoncms -type f -name ".gitignore" -depth -exec rm -f {} \; \ 49 | && find /var/www/emoncms -type f -name ".empty" -depth -exec rm -f {} \; 50 | 51 | # Copy root filesystem 52 | COPY rootfs / 53 | 54 | # Build arguments 55 | ARG BUILD_ARCH 56 | ARG BUILD_DATE 57 | ARG BUILD_REF 58 | ARG BUILD_VERSION 59 | 60 | # Labels 61 | LABEL \ 62 | io.hass.name="Emoncms" \ 63 | io.hass.description="Emoncms is a powerful open-source web-app for processing, logging and visualising energy, temperature and other environmental data." \ 64 | io.hass.arch="${BUILD_ARCH}" \ 65 | io.hass.type="addon" \ 66 | io.hass.version=${BUILD_VERSION} \ 67 | maintainer="Malachi Soord" \ 68 | org.opencontainers.image.title="Emoncms" \ 69 | org.opencontainers.image.description="Emoncms is a powerful open-source web-app for processing, logging and visualising energy, temperature and other environmental data." \ 70 | org.opencontainers.image.vendor="Home Assistant Community Add-ons" \ 71 | org.opencontainers.image.authors="Malachi Soord" \ 72 | org.opencontainers.image.licenses="MIT" \ 73 | org.opencontainers.image.url="https://addons.community" \ 74 | org.opencontainers.image.source="https://github.com/inverse/hassio-addon-emoncms" \ 75 | org.opencontainers.image.documentation="https://github.com/inverse/hassio-addon-emoncms/blob/master/README.md" \ 76 | org.opencontainers.image.created=${BUILD_DATE} \ 77 | org.opencontainers.image.revision=${BUILD_REF} \ 78 | org.opencontainers.image.version=${BUILD_VERSION} 79 | -------------------------------------------------------------------------------- /emoncms/DOCS.md: -------------------------------------------------------------------------------- 1 | # Home Assistant Community Add-on: Emoncms 2 | 3 | [Emoncms][0] is a powerful open-source web-app for processing, logging and visualising energy, temperature and other environmental data. 4 | 5 | This addon packages the installation allowing you to run it easily along side your existing Home Assistant installation. 6 | 7 | ## Installation 8 | 9 | You can install this addon like how you would any 3rd party addon. 10 | 11 | 1. Navigate within your Home Assistant frontend to __Supervisor__ then __Add-on Store__ 12 | 13 | 2. Click the 3-dots menu at upper right, then __Repositories__ and add this repository URL: https://github.com/inverse/hassio-addon-emoncms 14 | 15 | 3. Once added, scroll down the page to find the new repository section, click on the addon titled "Emoncms" 16 | 17 | ## Configuration 18 | 19 | __Note__: _Remember to restart the add-on when the configuration is changed._ 20 | 21 | Example add-on configuration: 22 | 23 | ```yaml 24 | log_level: info 25 | ssl: false 26 | certfile: fullchain.pem 27 | keyfile: privkey.pem 28 | ``` 29 | 30 | __Note__: _This is just an example, don't copy and past it! Create your own!_ 31 | 32 | ### Option: `log_level` 33 | 34 | The `log_level` option controls the level of log output by the addon and can 35 | be changed to be more or less verbose, which might be useful when you are 36 | dealing with an unknown issue. Possible values are: 37 | 38 | - `trace`: Show every detail, like all called internal functions. 39 | - `debug`: Shows detailed debug information. 40 | - `info`: Normal (usually) interesting events. 41 | - `warning`: Exceptional occurrences that are not errors. 42 | - `error`: Runtime errors that do not require immediate action. 43 | - `fatal`: Something went terribly wrong. Add-on becomes unusable. 44 | 45 | Please note that each level automatically includes log messages from a 46 | more severe level, e.g., `debug` also shows `info` messages. By default, 47 | the `log_level` is set to `info`, which is the recommended setting unless 48 | you are troubleshooting. 49 | 50 | ### Option: `ssl` 51 | 52 | Enables/Disables SSL (HTTPS) on the web interface of Emoncms 53 | Panel. Set it `true` to enable it, `false` otherwise. 54 | 55 | ### Option: `certfile` 56 | 57 | The certificate file to use for SSL. 58 | 59 | __Note__: _The file MUST be stored in `/ssl/`, which is the default_ 60 | 61 | ### Option: `keyfile` 62 | 63 | The private key file to use for SSL. 64 | 65 | __Note__: _The file MUST be stored in `/ssl/`, which is the default_ 66 | 67 | ### Option: `remote_mysql_host` 68 | 69 | If using an external database, the hostname/address for the MySQL/MariaDB database. 70 | 71 | Only applies if a remote MySQL database is used, the username with permissions. 72 | 73 | ### Option: `remote_mysql_password` 74 | 75 | Only applies if a remote MySQL database is used, the password of the above user. 76 | 77 | ### Option: `remote_mysql_port` 78 | 79 | Only applies if a remote MySQL database is used, the port that the database 80 | server is listening on. 81 | 82 | ## Database usage 83 | 84 | By default, Emoncms will automatically use and configure the Home Assistant 85 | MariaDB addon which should be installed prior to startup, this can be changed 86 | within the configuration to use an external MySql/MariaDB Database. Please note 87 | that there is no easy upgrade path between the two options. 88 | 89 | ## Known issues and limitations 90 | 91 | Please report any issues. 92 | 93 | - [EmonESP][1] does not currently support parsing the port from the "Emoncms Server" input field, making it complex to map this addon on a non-standard HTTP port. See [issue][2] 94 | 95 | ## License 96 | 97 | MIT License 98 | 99 | [0]: https://emoncms.org/ 100 | [1]: https://github.com/openenergymonitor/EmonESP 101 | [2]: https://github.com/inverse/hassio-addon-emoncms/issues/13 102 | -------------------------------------------------------------------------------- /emoncms/rootfs/etc/cont-init.d/emoncms.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/with-contenv bashio 2 | # ============================================================================== 3 | # Home Assistant Community Add-on: EmonCms 4 | # Configures EmonCms 5 | # ============================================================================== 6 | 7 | declare mysql_host 8 | declare mysql_database 9 | declare mysql_username 10 | declare mysql_password 11 | declare mysql_port 12 | 13 | if bashio::config.has_value "remote_mysql_host"; then 14 | if ! bashio::config.has_value 'remote_mysql_database'; then 15 | bashio::exit.nok \ 16 | "Remote database has been specified but no database is configured" 17 | fi 18 | 19 | if ! bashio::config.has_value 'remote_mysql_username'; then 20 | bashio::exit.nok \ 21 | "Remote database has been specified but no username is configured" 22 | fi 23 | 24 | if ! bashio::config.has_value 'remote_mysql_password'; then 25 | bashio::log.fatal \ 26 | "Remote database has been specified but no password is configured" 27 | fi 28 | 29 | if ! bashio::config.exists 'remote_mysql_port'; then 30 | bashio::exit.nok \ 31 | "Remote database has been specified but no port is configured" 32 | fi 33 | else 34 | if ! bashio::services.available 'mysql'; then 35 | bashio::log.fatal \ 36 | "Local database access should be provided by the MariaDB addon" 37 | bashio::exit.nok \ 38 | "Please ensure it is installed and started" 39 | fi 40 | 41 | mysql_host=$(bashio::services "mysql" "host") 42 | mysql_password=$(bashio::services "mysql" "password") 43 | mysql_port=$(bashio::services "mysql" "port") 44 | mysql_username=$(bashio::services "mysql" "username") 45 | mysql_database=emoncms 46 | 47 | bashio::log.warning "Emoncms is using the Maria DB addon" 48 | bashio::log.warning "Please ensure this is included in your backups" 49 | bashio::log.warning "Uninstalling the MariaDB addon will remove any data" 50 | 51 | 52 | bashio::log.info "Creating database for Emoncms if required" 53 | 54 | mysql \ 55 | -u "${mysql_username}" -p"${mysql_password}" \ 56 | -h "${mysql_host}" -P "${mysql_port}" \ 57 | -e "CREATE DATABASE IF NOT EXISTS \`${mysql_database}\` ;" 58 | fi 59 | 60 | 61 | cd /var/www/emoncms 62 | 63 | 64 | bashio::log.info "Configuring settings.php" 65 | 66 | cp example.settings.php settings.php 67 | sed -i "s/\"server\" => \"localhost\"/\"server\" => getenv('MYSQL_HOST')/g" settings.php 68 | sed -i "s/\"database\" => \"emoncms\"/\"database\" => getenv('MYSQL_NAME')/g" settings.php 69 | sed -i "s/\"_DB_USER_\"/getenv('MYSQL_USERNAME')/g" settings.php 70 | sed -i "s/\"_DB_PASSWORD_\"/getenv('MYSQL_PASSWORD')/g" settings.php 71 | sed -i "s/\"port\" => 3306/\"port\" => getenv('MYSQL_PORT')/g" settings.php 72 | 73 | 74 | sed -i "s/\/var\/opt\/emoncms\/phpfina\//\/data\/emoncms\/phpfina\//g" settings.php 75 | sed -i "s/\/var\/opt\/emoncms\/phptimeseries\//\/data\/emoncms\/phptimeseries\//g" settings.php 76 | 77 | # Configure logging 78 | 79 | bashio::log.info "Setting up logging" 80 | 81 | mkdir -p /var/log/emoncms 82 | touch /var/log/emoncms/emoncms.log 83 | chmod 666 /var/log/emoncms/emoncms.log 84 | 85 | # Configure persistant storage 86 | 87 | bashio::log.info "Setting up persistant storage" 88 | 89 | # Ensure persistant storage exists 90 | if ! bashio::fs.directory_exists "/data/emoncms"; then 91 | bashio::log.debug 'Data directory not initialized, doing that now...' 92 | 93 | # Create directories 94 | mkdir -p /data/emoncms/phpfina 95 | mkdir -p /data/emoncms/phptimeseries 96 | 97 | # Ensure file permissions 98 | chown -R nginx:nginx /data/emoncms 99 | find /data/emoncms -not -perm 0644 -type f -exec chmod 0644 {} \; 100 | find /data/emoncms -not -perm 0755 -type d -exec chmod 0755 {} \; 101 | fi 102 | 103 | # Run migrations 104 | 105 | bashio::log.info "Running migrations if needed" 106 | 107 | export MYSQL_HOST 108 | export MYSQL_NAME 109 | export MYSQL_USERNAME 110 | export MYSQL_PASSWORD 111 | export MYSQL_PORT 112 | 113 | if bashio::config.has_value 'remote_mysql_host';then 114 | MYSQL_HOST=$(bashio::config "remote_mysql_host") 115 | MYSQL_NAME=$(bashio::config "remote_mysql_database") 116 | MYSQL_USERNAME=$(bashio::config "remote_mysql_username") 117 | MYSQL_PASSWORD=$(bashio::config "remote_mysql_password") 118 | MYSQL_PORT=$(bashio::config "remote_mysql_port") 119 | else 120 | MYSQL_HOST=$(bashio::services "mysql" "host") 121 | MYSQL_NAME=emoncms 122 | MYSQL_USERNAME=$(bashio::services "mysql" "username") 123 | MYSQL_PASSWORD=$(bashio::services "mysql" "password") 124 | MYSQL_PORT=$(bashio::services "mysql" "port") 125 | fi 126 | 127 | php scripts/emoncms-cli admin:dbupdate 128 | --------------------------------------------------------------------------------