Dev version

This commit is contained in:
Alexandre
2021-11-25 09:11:37 +01:00
parent f6fe562770
commit 5bfc41d10d
14 changed files with 461 additions and 2 deletions

View File

@@ -0,0 +1,23 @@
## 0.7.8-dev (23-11-2021)
- Update to latest version from m4dm4rtig4n/enedisgateway2mqtt
## 0.7.7-dev (23-11-2021)
- Update to latest version from m4dm4rtig4n/enedisgateway2mqtt
## 0.7.7-dev (21-11-2021)
- Update to latest version from m4dm4rtig4n/enedisgateway2mqtt
## 0.7.5 (18-11-2021)
- Update to latest version from m4dm4rtig4n/enedisgateway2mqtt
- Allows setting TZ
## 0.7.4 (18-11-2021)
- Update to latest version from m4dm4rtig4n/enedisgateway2mqtt
## 0.7.3 (18-11-2021)
- Improve code
## 0.7.1 (17-11-2021)
- Logic change for configuration, from addon options to an external config yaml
- Allows setting options through 3 ways, see addon readme
- Data validation

View File

@@ -0,0 +1,65 @@
ARG BUILD_UPSTREAM="latest-dev"
FROM m4dm4rtig4n/enedisgateway2mqtt:$BUILD_UPSTREAM
# Base system
ARG BASHIO_VERSION=0.13.1
# Copy root filesystem
COPY rootfs /
VOLUME [ "/config" ]
RUN \
################
# Install apps #
################
apt-get clean \
&& apt-get update \
&& apt-get install -y \
jq \
curl \
yamllint \
&& apt-get clean \
\
##################
# Install bashio #
##################
&& mkdir -p /tmp/bashio \
&& curl -L -f -s "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" \
| tar -xzf - --strip 1 -C /tmp/bashio \
&& mv /tmp/bashio/lib /usr/lib/bashio \
&& ln -s /usr/lib/bashio/bashio /usr/bin/bashio \
&& rm -rf /tmp/bashio || true
#RUN ln -snf /usr/share/zoneinfo/Europe/Paris /etc/localtime
RUN chmod 777 /entrypoint.sh
ENTRYPOINT [ "/usr/bin/env" ]
CMD ["/entrypoint.sh"]
VOLUME [ "/data" ]
### LABELS
ARG BUILD_ARCH
ARG BUILD_DATE
ARG BUILD_DESCRIPTION
ARG BUILD_NAME
ARG BUILD_REF
ARG BUILD_REPOSITORY
ARG BUILD_VERSION
LABEL \
io.hass.name="${BUILD_NAME}" \
io.hass.description="${BUILD_DESCRIPTION}" \
io.hass.arch="${BUILD_ARCH}" \
io.hass.type="addon" \
io.hass.version=${BUILD_VERSION} \
maintainer="alexbelgium (https://github.com/alexbelgium)" \
org.opencontainers.image.title="${BUILD_NAME}" \
org.opencontainers.image.description="${BUILD_DESCRIPTION}" \
org.opencontainers.image.vendor="Home Assistant Add-ons" \
org.opencontainers.image.authors="alexbelgium (https://github.com/alexbelgium)" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.url="https://github.com/alexbelgium" \
org.opencontainers.image.source="https://github.com/${BUILD_REPOSITORY}" \
org.opencontainers.image.documentation="https://github.com/${BUILD_REPOSITORY}/blob/main/README.md" \
org.opencontainers.image.created=${BUILD_DATE} \
org.opencontainers.image.revision=${BUILD_REF} \
org.opencontainers.image.version=${BUILD_VERSION}

View File

@@ -0,0 +1,43 @@
# Home assistant add-on: Enedisgateway2mqtt
[![Donate][donation-badge]](https://www.buymeacoffee.com/alexbelgium)
[donation-badge]: https://img.shields.io/badge/Buy%20me%20a%20coffee-%23d32f2f?logo=buy-me-a-coffee&style=flat&logoColor=white
![Supports
Architecture][aarch64-shield] ![Supports amd64 Architecture][amd64-shield] ![Supports armhf Architecture][armhf-shield] ![Supports armv7 Architecture][armv7-shield]
_Thanks to everyone having starred my repo! To star it click on the image below, then it will be on top right. Thanks!_
[![Stargazers repo roster for @alexbelgium/hassio-addons](https://reporoster.com/stars/alexbelgium/hassio-addons)](https://github.com/alexbelgium/hassio-addons/stargazers)
## About
Enedisgateway2mqtt use Enedis Gateway API to send data in your MQTT Broker.
See its github for all informations : https://github.com/m4dm4rtig4n/enedisgateway2mqtt/blob/master/README.md
## Configuration
Install, then start the addon a first time to initialize the templates.
Everything is configured using the config.yaml file found in /config/enedisgateway2mqtt/enedisgateway2mqtt.conf.
The complete list of options can be seen here : https://github.com/m4dm4rtig4n/enedisgateway2mqtt#environment-variable
## Installation
The installation of this add-on is pretty straightforward and not different in
comparison to installing any other Hass.io add-on.
1. [Add my Hass.io add-ons repository][repository] to your Hass.io instance.
1. Install this add-on.
1. Click the `Save` button to store your configuration.
1. Start the add-on.
1. Check the logs of the add-on to see if everything went well.
1. Carefully configure the add-on to your preferences, see the official documentation for for that.
[smb-shield]: https://img.shields.io/badge/SMB--green?style=plastic.svg
[repository]: https://github.com/alexbelgium/hassio-addons
[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg
[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg
[armhf-shield]: https://img.shields.io/badge/armhf-yes-green.svg
[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg

View File

@@ -0,0 +1,38 @@
#include <tunables/global>
profile inadyn_addon flags=(attach_disconnected,mediate_deleted) {
#include <abstractions/base>
capability,
file,
mount,
umount,
remount,
capability setgid,
capability setuid,
# S6-Overlay
/bin/** ix,
/usr/bin/** ix,
/usr/lib/bashio/** ix,
/etc/s6/** rix,
/run/s6/** rix,
/etc/services.d/** rwix,
/etc/cont-init.d/** rwix,
/etc/cont-finish.d/** rwix,
/init rix,
/var/run/** mrwkl,
/var/run/ mrwkl,
/dev/i2c-1 mrwkl,
# Data access
/data/** rw,
# suppress ptrace denials when using 'docker ps' or using 'ps' inside a container
ptrace (trace,read) peer=docker-default,
# docker daemon confinement requires explict allow rule for signal
signal (receive) set=(kill,term) peer=/usr/bin/docker,
}

View File

@@ -0,0 +1,25 @@
{
"arch": [
"aarch64",
"amd64",
"armv7",
"armhf"
],
"description": "use Enedis Gateway API to send data in your MQTT Broker (latest-dev channel)",
"map": [
"config:rw"
],
"name": "Enedisgateway2mqtt Dev",
"options": {
"CONFIG_LOCATION": "/config/enedisgateway2mqtt_dev/config.yaml",
"TZ": "Europe/Paris"
},
"schema": {
"CONFIG_LOCATION": "str",
"TZ": "str?"
},
"slug": "enedisgateway2mqtt_dev",
"upstream": "0.7.8-dev",
"url": "https://github.com/alexbelgium/hassio-addons",
"version": "0.7.8-dev"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@@ -0,0 +1,16 @@
#!/bin/bash
echo "Starting..."
####################
# Starting scripts #
####################
for SCRIPTS in scripts/*; do
[ -e "$SCRIPTS" ] || continue
echo "$SCRIPTS: executing"
chown $(id -u):$(id -g) $SCRIPTS
chmod a+x $SCRIPTS
sed -i 's|/usr/bin/with-contenv bashio|/usr/bin/env bashio|g' $SCRIPTS || true
./$SCRIPTS || echo "$SCRIPTS: exiting $?"
done

View File

@@ -0,0 +1,30 @@
#!/bin/bash
# If dockerfile failed install manually
if [ ! -f "/usr/bin/bashio" ]; then
echo "Bashio does not exist, executing script"
(
# Remove errors on apt-get
export DEBIAN_FRONTEND=noninteractive
################
# Install apps #
################
apt-get clean &&
apt-get update &&
apt-get install -yq --no-install-recommends \
jq \
curl \
yamllint
###################
# Install bashio #
##################
BASHIO_VERSION=0.13.1
mkdir -p /tmp/bashio
curl -L -f -s "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" |
tar -xzf - --strip 1 -C /tmp/bashio
mv /tmp/bashio/lib /usr/lib/bashio
ln -s /usr/lib/bashio/bashio /usr/bin/bashio
rm -rf /tmp/bashio
) >/dev/null
echo "Bashio installed"
fi

View File

@@ -0,0 +1,39 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Displays a simple add-on banner on startup
# ==============================================================================
if bashio::supervisor.ping; then
bashio::log.blue \
'-----------------------------------------------------------'
bashio::log.blue " Add-on: $(bashio::addon.name)"
bashio::log.blue " $(bashio::addon.description)"
bashio::log.blue \
'-----------------------------------------------------------'
bashio::log.blue " Add-on version: $(bashio::addon.version)"
if bashio::var.true "$(bashio::addon.update_available)"; then
bashio::log.magenta ' There is an update available for this add-on!'
bashio::log.magenta \
" Latest add-on version: $(bashio::addon.version_latest)"
bashio::log.magenta ' Please consider upgrading as soon as possible.'
else
bashio::log.green ' You are running the latest version of this add-on.'
fi
bashio::log.blue " System: $(bashio::info.operating_system)" \
" ($(bashio::info.arch) / $(bashio::info.machine))"
bashio::log.blue " Home Assistant Core: $(bashio::info.homeassistant)"
bashio::log.blue " Home Assistant Supervisor: $(bashio::info.supervisor)"
bashio::log.blue \
'-----------------------------------------------------------'
bashio::log.blue \
' Please, share the above information when looking for help'
bashio::log.blue \
' or support in, e.g., GitHub, forums'
bashio::log.green \
' https://github.com/alexbelgium/hassio-addons'
bashio::log.blue \
'-----------------------------------------------------------'
fi

View File

@@ -0,0 +1,41 @@
#!/bin/bash
###################################
# Export all addon options as env #
###################################
# For all keys in options.json
JSONSOURCE="/data/options.json"
# Export keys as env variables
# echo "All addon options were exported as variables"
mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE})
for KEYS in ${arr[@]}; do
# export key
VALUE=$(jq .$KEYS ${JSONSOURCE})
export ${KEYS}=${VALUE//[\"\']/} &>/dev/null
done
################
# Set timezone #
################
if [ ! -z "TZ" ] && [ -f /etc/localtime ]; then
if [ -f /usr/share/zoneinfo/$TZ ]; then
echo "Timezone set from $(cat /etc/timezone) to $TZ"
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone
else
echo "WARNING : Timezone $TZ is invalid, it will be kept to default value of $(cat /etc/timezone)"
fi
fi
############
# Set user #
############
if [ ! -z "PUID" ] && [ ! -z "GUID" ]; then
echo "Custom user defined : $PUID:$GUID"
PUID=${PUID:-911}
PGID=${PGID:-911}
groupmod -o -g "$PGID" abc
usermod -o -u "$PUID" abc
fi

View File

@@ -0,0 +1,76 @@
#!/usr/bin/env bashio
##################
# INITIALIZATION #
##################
# Where is the config
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
DATABASESOURCE="$(dirname "${CONFIGSOURCE}")/enedisgateway.db"
# Make sure folder exist
mkdir -p "$(dirname "${CONFIGSOURCE}")"
mkdir -p "$(dirname "${DATABASESOURCE}")"
# Check absence of config file
if [ -f /data/config.yaml ] && [ ! -L /data/config.yaml ]; then
bashio::log.warning "A current config was found in /data, it is backuped to ${CONFIGSOURCE}.bak"
mv /data/config.yaml $CONFIGSOURCE.bak
fi
# Check if config file is there, or create one from template
if [ -f $CONFIGSOURCE ]; then
# Create symlink if not existing yet
[ ! -L /data/config.yaml ] && ln -sf $CONFIGSOURCE /data
bashio::log.info "Using config file found in $CONFIGSOURCE"
# Check if yaml is valid
EXIT_CODE=0
yamllint -d relaxed --no-warnings $CONFIGSOURCE &> ERROR || EXIT_CODE=$?
if [ $EXIT_CODE = 0 ]; then
echo "Config file is a valid yaml"
else
cat ERROR
bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above. You can check yaml validity with the online tool yamllint.com"
bashio::exit.nok
fi
else
# Create symlink for addon to create config
touch ${CONFIGSOURCE}
ln -sf $CONFIGSOURCE /data
rm $CONFIGSOURCE
# Need to restart
bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting."
fi
# Remove previous link or file
[ -f /data/enedisgateway.db ] && rm /data/enedisgateway.db
# Check if database is here or create symlink
if [ -f $DATABASESOURCE ]; then
# Create symlink if not existing yet
ln -sf ${DATABASESOURCE} /data && echo "creating symlink"
bashio::log.info "Using database file found in $DATABASESOURCE"
else
# Create symlink for addon to create database
touch ${DATABASESOURCE}
ln -sf $DATABASESOURCE /data
rm $DATABASESOURCE
fi
##############
# Launch App #
##############
echo " "
bashio::log.info "Starting the app"
echo " "
# Test mode
if [ $TZ = "test" ]; then
echo "secret mode found, launching script in /config/test.sh"
cd /config
chmod 777 test.sh
./test.sh
fi
python -u /app/main.py || bashio::log.fatal "The app has crashed. Are you sure you entered the correct config options?"

View File

@@ -0,0 +1,63 @@
##########
# GLOBAL #
##########
debug: false
####################
## MQTT ##
####################
mqtt:
host: MOSQUITO_SERVER # MANDATORY
port: 1883
username: ""
password: ""
prefix: enedis_gateway
client_id: enedis_gateway
retain: true
qos: 0
####################
## Home assistant ##
####################
home_assistant:
discovery: false
discovery_prefix: homeassistant
card_myenedis: false
###############
## Influx DB ##
###############
#influxdb:
# host: MY_INFLUXDB_SERVER
# port: 8086
# token: MY_TOKEN
# org: MY_ORG
# bucket: MY_BUCKET
####################
## ENEDIS GATEWAY ##
####################
enedis_gateway:
PDL_1: # MANDATORY
token: PDL_1_TOKEN # MANDATORY
plan: BASE # BASE or HP/HC
consumption: true
consumption_detail: true
consumption_price_hc: 0
consumption_price_hp: 0
consumption_price_base: 0
production: false
production_detail: false
# offpeak_hours: "" # USE ONLY IF YOU WANT OVERLOAD DEFAULT VALUE, Format : 22h36-00h10;01h00-06h00
addresses: true
# PDL_2:
# token: PDL_2_TOKEN
# plan: HP/HC
# consumption: true
# consumption_detail: true
# consumption_price_hc: 0.1781
# consumption_price_hp: 0.1337
# consumption_price_base: 0.1781
# production: false
# production_detail: false
# addresses: true