Integracja Tauron e-licznik

Dorzucę od siebie przepis jak to zrobić w dockerze, oszczędzi to czasu na kompilowanie binarek na raspberry pi i umożliwi provisioning malinki jakimiś skryptami :slight_smile:

  1. Zarejestruj się w Tauronowym e-Licznik, aktywuj HAN, uzyskaj ID licznika i jego klucz szyfrujący
  2. Zaczynamy od tego, że malinka posiada czystego RaspiOS (Raspbian?)
apt update
apt upgrade
dpkg-reconfigure tzdata
reboot
  1. Instalujemy dockera
sudo apt-get remove docker docker-engine docker.io containerd runc

sudo apt-get install     apt-transport-https     ca-certificates     curl     gnupg     lsb-release vim htop ncdu mc

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo   "deb [arch=armhf signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

apt update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose
vim /etc/docker/daemon.json
{
  "log-driver": "journald"
}
systemctl restart docker.service
  1. Tworzymy skrypty do autostartu kontenerów dockerowych
mkdir /etc/docker/compose/wmbusmeters -p
vim /etc/systemd/system/docker-compose@.service
[Unit]
Description=%i service with docker compose
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=true
WorkingDirectory=/etc/docker/compose/%i
ExecStart=/usr/bin/docker-compose up -d --remove-orphans
ExecStop=/usr/bin/docker-compose down

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
vim /etc/docker/compose/wmbusmeters/docker-compose.yml
version: "2"
services:
  wmbusmeters:
    image: weetmuts/wmbusmeters
    container_name: wmbusmeters
    privileged: true
    restart: always
    volumes:
      - /opt/wmbusmeters:/wmbusmeters_data
      - /etc/localtime:/etc/localtime:ro
      - /dev/:/dev/
  1. Konfigurujemy wmbusmeters
vim /opt/wmbusmeters/etc/wmbusmeters.conf
loglevel=info
logtelegrams=false
format=json
meterfiles=/wmbusmeters_data/logs/meter_readings
meterfilesaction=overwrite
logfile=/wmbusmeters_data/logs/wmbusmeters.log
device=rtl433:868.95M:t1
shell=/usr/bin/mosquitto_pub -h 192.168.1.69 -u loginMQTT -P hasłoMQTT -t wmbusmeters/$METER_ID -m "$METER_JSON"
vim /opt/wmbusmeters/etc/wmbusmeters.d/domek
name=domek
type=amiplus
id=id_licznika
key=klucz_licznika
  1. Uruchamiamy wmbusmeters
systemctl start docker-compose@wmbusmeters
systemctl enable docker-compose@wmbusmeters
  1. Zostaje nam obserwować na MQTT czy pojawiły się odczyty z licznika :slight_smile:
  2. Konfiguracja Home Assistanta:
sensor:
  - platform: mqtt
    name: "Licznik domek Energia pobrana"
    state_topic: "wmbusmeters/85021882"
    unit_of_measurement: "kWh"
    value_template: "{{ value_json.total_energy_consumption_kwh }}"
    json_attributes_topic: "wmbusmeters"
    state_class: total_increasing
    device_class: energy
  - platform: mqtt
    name: "Licznik domek Moc pobierana"
    state_topic: "wmbusmeters/85021882"
    unit_of_measurement: "kW"
    value_template: "{{ value_json.current_power_consumption_kw }}"
    json_attributes_topic: "wmbusmeters"
    state_class: measurement
    device_class: energy
  - platform: mqtt
    name: "Licznik domek Calkowia moc oddana do sieci"
    state_topic: "wmbusmeters/85021882"
    unit_of_measurement: "kWh"
    value_template: "{{ value_json.total_energy_production_kwh }}"
    json_attributes_topic: "wmbusmeters"
    state_class: total_increasing
    device_class: energy
  - platform: mqtt
    name: "Licznik domek Moc oddawana"
    state_topic: "wmbusmeters/85021882"
    unit_of_measurement: "kW"
    value_template: "{{ value_json.current_power_production_kw }}"
    json_attributes_topic: "wmbusmeters"
    state_class: measurement
    device_class: energy
  - platform: mqtt
    name: "Licznik domek Ostatni odczyt"
    state_topic: "wmbusmeters/85021882"
    value_template: "{{ value_json.device_date_time }}"
    json_attributes_topic: "wmbusmeters"

Drobny update, czasami licznik nadaje zera, albo wmbusmeters czyta zera z telegramu licznika. Totalnie to zaburza później widok energii w HA.

Rozwiązaniem jest filtrowanie zer i ponawianie poprzedniego odczytu jako aktualnego.
Mądrzejszy o to doświadczenie, musiałem wywalić historię encji związanych z licznikiem i zbierać historię od nowa (czyli jestem wczorajszy dzień w plecy)

sensor:
  - platform: mqtt
    name: "Domek Energia pobrana"
    state_topic: "wmbusmeters/id_licznika"
    unit_of_measurement: "kWh"
    # value_template: "{{ value_json.total_energy_consumption_kwh }}"
    value_template: >
      {% if value_json.total_energy_consumption_kwh == 0 %}
          {{ states('sensor.domek_energia_pobrana') }}
        {% else %}
          {{ value_json.total_energy_consumption_kwh }}
        {% endif %}
    json_attributes_topic: "wmbusmeters"
    state_class: total_increasing
    device_class: energy
  - platform: mqtt
    name: "Domek Moc pobierana"
    state_topic: "wmbusmeters/id_licznika"
    unit_of_measurement: "kW"
    # value_template: "{{ value_json.current_power_consumption_kw }}"
    value_template: >
      {% if value_json.current_power_consumption_kw == 0 %}
          {{ states('sensor.domek_moc_pobierana') }}
        {% else %}
          {{ value_json.current_power_consumption_kw }}
        {% endif %}
    json_attributes_topic: "wmbusmeters"
    state_class: measurement
    device_class: power
  - platform: mqtt
    name: "Domek Calkowia moc oddana do sieci"
    state_topic: "wmbusmeters/id_licznika"
    unit_of_measurement: "kWh"
    # value_template: "{{ value_json.total_energy_production_kwh }}"
    value_template: >
      {% if value_json.current_power_consumption_kw == 0 %}
          {{ states('sensor.domek_moc_pobierana') }}
        {% else %}
          {{ value_json.current_power_consumption_kw }}
        {% endif %}
    json_attributes_topic: "wmbusmeters"
    state_class: total_increasing
    device_class: energy
  - platform: mqtt
    name: "Domek Moc oddawana"
    state_topic: "wmbusmeters/id_licznika"
    unit_of_measurement: "kW"
    # value_template: "{{ value_json.current_power_production_kw }}"
    value_template: >
      {% if value_json.current_power_production_kw == 0 %}
          {{ states('sensor.domek_moc_oddawana') }}
        {% else %}
          {{ value_json.current_power_production_kw }}
        {% endif %}
    json_attributes_topic: "wmbusmeters"
    state_class: measurement
    device_class: power
  - platform: mqtt
    name: "Domek Ostatni odczyt"
    state_topic: "wmbusmeters/id_licznika"
    value_template: "{{ value_json.device_date_time }}"
    json_attributes_topic: "wmbusmeters"
    device_class: timestamp
    state_class: measurement
4 polubienia