Kompletny YAML poniżej, wcześniej wszystko działało
esphome:
name: woda
friendly_name: Woda
esp8266:
board: esp01_1m
logger:
api:
encryption:
key: "PU9Hx1vRZLB3+ywutsvPiAjJQp4Yd4cnuzM9h+hJRg0="
services:
- service: set_water_val
variables:
water_val_hour: float
water_val_day: float
water_val_yesterday: float
water_val_week: float
water_val_year: float
water_val_lastmonth: float
then:
- globals.set:
id: hour_value
value: !lambda |-
if((water_val_hour) and (water_val_hour)>0.001){
ESP_LOGD("system", "Set hourly value to: %f", water_val_hour);
return (water_val_hour);
}else{
ESP_LOGD("system", "Skip setting hourly value");
return id(hour_value);
};
id(waterhour).publish_state(id(hour_value));
- globals.set:
id: daily_value
value: !lambda |-
if((water_val_day) and (water_val_day)>0.001){
ESP_LOGD("system", "Set daily value to: %f", water_val_day);
return (water_val_day);
}else{
ESP_LOGD("system", "Skip setting hourly value");
return id(hour_value);
};
id(waterday).publish_state(id(daily_value));
- globals.set:
id: yesterday_value
value: !lambda |-
if((water_val_yesterday) and (water_val_yesterday)>0.001){
ESP_LOGD("system", "Set yesterday value to: %f", water_val_yesterday);
return (water_val_yesterday);
}else{
ESP_LOGD("system", "Skip setting yesterday value");
return id(yesterday_value);
};
id(wateryesterday).publish_state(id(hour_value));
- globals.set:
id: week_value
value: !lambda |-
if((water_val_week) and (water_val_week)>0.001){
ESP_LOGD("system", "Set weekly value to: %f", water_val_week);
return (water_val_week);
}else{
ESP_LOGD("system", "Skip setting weekly value");
return id(week_value);
};
id(waterweek).publish_state(id(week_value));
- globals.set:
id: lastmonth_value
value: !lambda |-
if((water_val_lastmonth) and (water_val_lastmonth)>0.001){
ESP_LOGD("system", "Set last month value to: %f", water_val_lastmonth);
return (water_val_lastmonth);
}else{
ESP_LOGD("system", "Skip setting last month value");
return id(lastmonth_value);
};
id(waterlastmonth).publish_state(id(lastmonth_value));
- globals.set:
id: year_value
value: !lambda |-
if((water_val_year) and (water_val_year)>0.001){
ESP_LOGD("system", "Set last yearly value to: %f", water_val_year);
return (water_val_year);
}else{
ESP_LOGD("system", "Skip setting last yearly value");
return id(year_value);
};
id(wateryear).publish_state(id(year_value));
- logger.log:
tag: "system"
format: "All new Values set: hour: %.3f, day: %.3f, week: %.3f, last month: %.3f, year: %.3f"
level: INFO
args:
[
"id(hour_value)",
"id(daily_value)",
"id(week_value)",
"id(lastmonth_value)",
"id(year_value)",
]
ota:
- platform: esphome
password: "2e5524d762159533414b83ae9b796600"
## ----------------------------------------------------------------
## GLOBALS VARIABLES
## ----------------------------------------------------------------
globals:
- id: boot_counter
type: int
restore_value: yes
initial_value: "0"
- id: last_value
type: float
restore_value: yes
initial_value: "0.00"
- id: current_value
type: float
restore_value: yes
initial_value: "0.00"
- id: hour_value
type: float
restore_value: yes
initial_value: "0.00"
- id: daily_value
type: float
restore_value: yes
initial_value: "0.00"
- id: yesterday_value
type: float
restore_value: yes
initial_value: "0.00"
- id: week_value
type: float
restore_value: yes
initial_value: "0.00"
- id: lastmonth_value
type: float
restore_value: yes
initial_value: "0.00"
- id: year_value
type: float
restore_value: yes
initial_value: "0.00"
- id: send_millisecond
type: int
restore_value: no
initial_value: '0'
- id: cc1101_state
type: int
restore_value: no
initial_value: '0'
- id: alarm_error_text
type: std::vector<std::string>
restore_value: no
initial_value: '{"no error", "general_alarm","leakage","meter_blocked","back_flow","underflow","overflow","submarine","sensor_fraud","mechanical_fraud"}'
##initial_value: '{"Keiner", "Fehler","Zähler undicht","Zähler blockiert","Wasser Rückfluss","Wasser Unterlauf","Wasser Überlauf","Überschwemung","Sensor Fehler", "Mechanischer Fehler"}'
- id: cc1101_state_message
type: std::vector<std::string>
restore_value: no
initial_value: '{"Init", "Oczekiwanie na dane", "Odbieranie danych", "Ready", "Error"}'
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Woda Fallback Hotspot"
password: "MH1FDq1D3xXk"
captive_portal:
## ---------------------------------------------------
## SNTP COMPONENT
## ---------------------------------------------------
time:
- platform: sntp
id: time_sntp
timezone: Europe/Berlin
servers:
# - !secret local_sntp
- 0.at.pool.ntp.org
- 0.pool.ntp.org
on_time_sync:
# Components should trigger on_time_sync when they update the system clock.
then:
- if:
condition:
lambda: 'return id(device_lastBoot_time).state == "";'
then:
- text_sensor.template.publish:
id: device_lastBoot_time
state: !lambda return id(time_sntp).now().strftime("%Y-%m-%dT%H:%M:%S %Z");
- logger.log:
level: WARN
tag: "system"
format: "Synchronized sntp clock"
- script.execute: set_status_message
on_time:
# check cc1101 telegram state message
- seconds: 30
then:
- script.execute: set_status_message
# reset hourly value
- seconds: 0
minutes: 0
then:
- globals.set:
id: hour_value
value: "0.00"
- lambda: id(waterhour).publish_state(id(hour_value));
- logger.log:
tag: "system"
level: INFO
format: "Reset value hour, starting next hour"
# reset daily value and set yesterday value
- seconds: 0
minutes: 0
hours: 0
then:
- lambda: |-
id(yesterday_value)=id(daily_value);
id(wateryesterday).publish_state(id(yesterday_value));
id(daily_value)=0.00;
id(waterday).publish_state(id(daily_value));
- logger.log:
tag: "system"
level: INFO
format: "Set yesterday value and reset value daily, starting new day"
# reset weekly value, start new week
- seconds: 0
minutes: 0
hours: 0
days_of_week: MON
then:
- globals.set:
id: week_value
value: "0.00"
- lambda: id(waterweek).publish_state(id(week_value));
- logger.log:
tag: "system"
level: INFO
format: "Reset value weekly, starting new week"
# new year, reset yearly value
- seconds: 0
minutes: 0
hours: 0
days_of_month: 1
months: JAN
then:
- globals.set:
id: year_value
value: "0.00"
- lambda: id(wateryear).publish_state(id(year_value));
- logger.log:
tag: "system"
level: INFO
format: "Reset value yearly, starting new year"
## ---------------------------------------------------
## SCRIPTS COMPONENT
## ---------------------------------------------------
script:
# id(set_status_message).execute();
- id: set_status_message
then:
- lambda: |-
int msgcode = int(id(cc1101_state));
std::string message = id(cc1101_state_message)[msgcode];
ESP_LOGD("wmbus", "cc1101 state message: %s, error code: %d", message.c_str(), msgcode);
id(watermeter_status_message).publish_state(message);
external_components:
- source: github://SzczepanLeon/esphome-components@3.2.3
components: [ wmbus ]
wmbus:
mosi_pin: GPIO13 #D7 MOSI Attached to Hardware SPI controller MOSI SPI Interface
miso_pin: GPIO12 #D6 MISO Attached to Hardware SPI controller MISO SPI Interface
clk_pin: GPIO14 #D5 SCK Attached to Hardware SPI controller CLK
cs_pin: GPIO15 #D8 CSN Attached to Hardware SPI controller, Controls Boot Mode; CS SPI Interface 10k Pull-Down, boot fails if pulled high !!!
gdo0_pin: GPIO05 #D1 SDA Clock output. High Impedance !
gdo2_pin: GPIO04 #D2 SCL FIFO status signals. High Impedance !
## ---------------------------------------------------
## SENSORS
## ---------------------------------------------------
sensor:
- platform: wmbus
meter_id: 0x215F7AA7
type: izar
add_prefix: True
total_water_m3:
name: "Woda na ogródek"
- platform: wmbus
# Meter ID (usually from sticker). Can be specified as decimal or hex.
# only HEX is working for my watermeter !
# see: https://github.com/SzczepanLeon/esphome-components/issues/6
# edit watermeterid in the secrets file
# add_prefix: enable/disable add watermeterid to lqi, rssi, total_water_m3
meter_id: 0x214FD45A
type: izar
add_prefix: False
# The LQI value reported by the CC1101 is a 7 bit unsigned number with a range from 0 to 127.
# Note that a lower value indicates a better link.
# The LQI of a received packet will be bad (higher number) when there is lot of interference.
lqi:
id: wmbus_cc1101_lqi
name: "CC1101 LQI"
entity_category: "diagnostic"
unit_of_measurement: "lqi"
state_class: "measurement"
# The RSSI value reported by the CC1101 is a 8 bit signed number with an effective
# range from -138 dBm to -10.5 dBm when the CC1101 is operating around 868 MHz.
# RSSI stands for received signal strength (power) indication (in dBm).
# A higher value indicates higher power. (internal only)
rssi:
id: wmbus_cc1101_rssi
name: "CC1101 RSSI"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: "diagnostic"
state_class: "measurement"
icon: mdi:rss
# get the total watermter m3 from the wmbus telegram, log the timestamp
# for the last reading and calculates the statitics value
# and update all sensors: last_value, watercurrent, hour_value, daily_value
# week_value, month_value, year_value and watermeter_lastupdate
total_water_m3:
id: "waterdisplay"
name: "Wskazanie bieżące"
unit_of_measurement: "m³"
state_class: total_increasing
device_class: "water"
accuracy_decimals: 3
icon: mdi:counter
# Send the value periodically with the specified time interval.
# If the sensor value changes during the interval the interval will not reset.
# The last value of the sensor will be sent. 60s means, that every minute the
# last state will be published.
# The IZAR Watermeter will publish data all 8s (see transmit_period_s),
# but we need this only evers minute.
# filters:
# - heartbeat: 60s
# update and calulatet all watermeter sensor data values
on_value:
then:
- lambda: |-
if ((id(last_value) > 0.00) and (id(waterdisplay).state)>(id(last_value)) ) {
id(cc1101_state) = 2;
ESP_LOGI("wmbus", "Water Display value: %.3f, last value: %.3f", id(waterdisplay).state, id(last_value));
id(current_value) = float(id(waterdisplay).state-id(last_value)) * 1000.00;
id(watercurrent).publish_state(id(current_value));
id(hour_value)+=id(current_value);
id(waterhour).publish_state(id(hour_value));
id(daily_value)+=id(current_value);
id(waterday).publish_state(id(daily_value));
id(week_value)+=id(current_value);
id(waterweek).publish_state(id(week_value));
id(year_value)+=id(current_value);
id(wateryear).publish_state(id(year_value));
ESP_LOGD("wmbus", "Set current value to %.3f litre and publish the data", id(current_value));
}else{
id(current_value) = 0.00;
id(cc1101_state) = 1;
id(watercurrent).publish_state(id(current_value));
ESP_LOGI("wmbus", "Reset current value to: %.3f, Waterdisplay value: %.3f, last value: %.3f", id(current_value), id(waterdisplay).state, id(last_value));
}
id(last_value)=id(waterdisplay).state;
# update the timestamp for the last waterdisplay state
- text_sensor.template.publish:
id: watermeter_lastupdate
state: !lambda return id(time_sntp).now().strftime("%Y-%m-%dT%H:%M:%S %Z");
# update the reading timeout for the watermeter display
- sensor.template.publish:
id: watermeter_read_timeout
state: !lambda |-
int time_used = ( millis() - id(send_millisecond) );
ESP_LOGD("wmbus", "Diff millisecond is: %d", time_used);
id(send_millisecond) = millis();
return float(time_used)/1000;
# update the watermeter status
- script.execute: set_status_message
# water current month (wM-Bus v2.1.4)
current_month_total_water_l:
name: Miesiąc bieżący
id: "watermonth"
accuracy_decimals: 2
unit_of_measurement: "l"
icon: mdi:water-outline
state_class: total_increasing
device_class: "water"
# get the last month total watermter m3 from the wmbus telegram (wM-Bus 2.1.10)
last_month_total_water_m3:
name: "Wskazanie w poprzednim miesiącu"
id: "waterdisplay_lastmonth"
unit_of_measurement: "m³"
state_class: total_increasing
device_class: "water"
accuracy_decimals: 3
icon: mdi:counter
# get the battery life time (wM-Bus v2.1.4)
remaining_battery_life_y:
name: "Żywotność baterii"
id: "watermeter_batterie"
accuracy_decimals: 2
unit_of_measurement: "Years"
state_class: "measurement"
entity_category: "diagnostic"
icon: mdi:battery
# get the last transmit periode (wM-Bus v2.1.4)
transmit_period_s:
name: "Update Intervall"
id: "watermeter_transmit_periode"
unit_of_measurement: "sec"
state_class: "measurement"
accuracy_decimals: 2
entity_category: "diagnostic"
icon: mdi:timelapse
## get the current watermeter alarms and publish the text message (wM-Bus 2.1.10)
current_alarms:
id: "watermeter_current_alarms"
name: "Alarm Code"
entity_category: "diagnostic"
icon: mdi:message-alert-outline
on_value:
then:
- lambda: |-
int error_code = int(x);
std::string message = "";
if(error_code==0){
message = id(alarm_error_text)[error_code];
id(watermeter_alarm_message).publish_state(message);
ESP_LOGD("wmbus", "Alarm message: %s, error code: %d", message, error_code);
}else{
for (int i = 1; i < 10; ++i) {
if (error_code & (1 << i)) {
if (!message.empty()) {
message += ", ";
}
message += id(alarm_error_text)[i];
}
}
id(watermeter_alarm_message).publish_state(message);
ESP_LOGW("wmbus", "WARNING Alarm message: %s, error code: %d", message.c_str(), error_code);
id(watermeter_alarm_timestamp).publish_state(id(time_sntp).now().strftime("%Y-%m-%dT%H:%M:%S %Z").c_str());
}
## get the prevois watermeter alarms and publish the text message (wM-Bus 2.1.10)
previous_alarms:
id: "watermeter_previous_alarms"
name: "Kod poprzedniego alarmu"
icon: mdi:message-alert
entity_category: "diagnostic"
on_value:
then:
- lambda: |-
int error_code = int(x);
std::string message = "";
if(error_code==0){
message = id(alarm_error_text)[error_code];
id(watermeter_alarm_message).publish_state(message);
ESP_LOGD("wmbus", "Alarm message: %s, error code: %d", message, error_code);
}else{
for (int i = 1; i < 10; ++i) {
if (error_code & (1 << i)) {
if (!message.empty()) {
message += ", ";
}
message += id(alarm_error_text)[i];
}
}
ESP_LOGW("wmbus", "WARNING Alarm message: %s, error code: %d", message.c_str(), error_code);
id(watermeter_alarm_timestamp).publish_state(id(time_sntp).now().strftime("%Y-%m-%dT%H:%M:%S %Z").c_str());
}
id(watermeter_alarm_perv_message).publish_state(message);
if(id(watermeter_alarm_timestamp).has_state() == false) {
id(watermeter_alarm_timestamp).publish_state("--");
}
# water current
- platform: template
name: Aktualnie
id: "watercurrent"
accuracy_decimals: 2
unit_of_measurement: "l"
icon: mdi:water-well
state_class: "measurement"
device_class: "water"
lambda: return (id(current_value));
# water current hour
- platform: template
name: Godzina
id: "waterhour"
accuracy_decimals: 2
unit_of_measurement: "l"
icon: mdi:water-well-outline
state_class: total_increasing
device_class: "water"
lambda: return (id(hour_value));
# water today
- platform: template
name: Dzisiaj
id: "waterday"
accuracy_decimals: 2
unit_of_measurement: "l"
icon: mdi:water-well-outline
device_class: "water"
state_class: total_increasing
lambda: return (id(daily_value));
# water yesterday
- platform: template
name: Wczoraj
id: "wateryesterday"
accuracy_decimals: 2
unit_of_measurement: "l"
icon: mdi:water-well-outline
device_class: "water"
state_class: total_increasing
lambda: return (id(yesterday_value));
# water current week
- platform: template
name: Tydzień
id: "waterweek"
accuracy_decimals: 2
unit_of_measurement: "l"
icon: mdi:water-well-outline
device_class: "water"
state_class: total_increasing
lambda: return (id(week_value));
# water last month
- platform: template
name: Miesiąc poprzedni
id: "waterlastmonth"
accuracy_decimals: 2
unit_of_measurement: "l"
state_class: total_increasing
device_class: "water"
lambda: return (id(lastmonth_value));
# water current year
- platform: template
name: Rok
id: "wateryear"
accuracy_decimals: 2
unit_of_measurement: "l"
state_class: total_increasing
device_class: "water"
lambda: return (id(year_value));
# service call delay
- platform: template
name: watermeter read timeout
id: watermeter_read_timeout
icon: mdi:clock-start
accuracy_decimals: 2
unit_of_measurement: "sec"
state_class: "measurement"
entity_category: "diagnostic"
# Wifi quality RSSI (%)
- platform: wifi_signal
name: "WLAN Signal"
id: wifi_signal_db
update_interval: 180s
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
entity_category: "diagnostic"
unit_of_measurement: "%"
# device internal temperature (only webview)
# - platform: internal_temperature
# name: Device Internal Temperature
# id: device_internal_temperature
# icon: mdi:thermometer-lines
# state_class: "measurement"
# update_interval: 60s
# entity_category: "diagnostic"
# disabled_by_default: true
# Uptime device in hours
- platform: uptime
name: "Online od"
id: uptime_human
icon: mdi:clock-start
filters:
- lambda: return x / 3600;
unit_of_measurement: "h"
entity_category: "diagnostic"
state_class: "measurement"
accuracy_decimals: 2
# device boot counter
- platform: template
name: "Boot counter"
id: bootcounter
icon: mdi:counter
accuracy_decimals: 0
state_class: "measurement"
entity_category: "diagnostic"
lambda: return (id(boot_counter));
## ---------------------------------------------------
## SWITCHES
## ---------------------------------------------------
switch:
# reset boot counter value
- platform: template
name: "Boot Counter Reset"
icon: mdi:lock-reset
turn_on_action:
then:
- lambda: |-
id(boot_counter) = 0;
id(bootcounter).publish_state(id(boot_counter));
- logger.log:
level: WARN
tag: "system"
format: "${device_name_short} reset boot counter o.k!"
- component.update: bootcounter
# reset all global vars
- platform: template
name: "Reset values"
icon: mdi:lock-reset
turn_on_action:
then:
- lambda: |-
id(last_value) = 0.00;
id(boot_counter) = 0;
id(bootcounter).publish_state(id(boot_counter));
id(current_value) = 0.00;
id(watercurrent).publish_state(id(current_value));
id(hour_value) = 0.00;
id(waterhour).publish_state(id(hour_value));
id(daily_value) = 0.00;
id(waterday).publish_state(id(daily_value));
id(yesterday_value) = 0.00;
id(wateryesterday).publish_state(id(yesterday_value));
id(week_value) = 0.00;
id(waterweek).publish_state(id(week_value));
id(lastmonth_value) = 0.00;
id(waterlastmonth).publish_state(id(lastmonth_value));
id(year_value) = 0.00;
id(wateryear).publish_state(id(year_value));
- logger.log:
level: INFO
tag: "system"
format: "all values reset!"
# restarts the device
- platform: restart
name: "Restart"
id: restart_switch
icon: mdi:restart
## ---------------------------------------------------
## TEXT SENSOR
## ---------------------------------------------------
text_sensor:
# watermeter status message (updated by script: set_status_message)
- platform: template
name: "Status Info"
id: watermeter_status_message
icon: mdi:bell
entity_category: "diagnostic"
# watermeter alarm message
- platform: template
name: "Alarm"
id: watermeter_alarm_message
icon: mdi:alarm-light
entity_category: "diagnostic"
# watermeter previous alarm message
- platform: template
name: "Poprzedni alarm"
id: watermeter_alarm_perv_message
icon: mdi:alarm-light
entity_category: "diagnostic"
# watermeter alarm timestamp
- platform: template
name: "Alarm timestamp"
id: watermeter_alarm_timestamp
icon: mdi:alarm-light
entity_category: "diagnostic"
# optional device version (only on webserver)
- platform: version
name: "Version"
icon: mdi:application-cog-outline
id: appver
hide_timestamp: true
disabled_by_default: true
# Last boot timestamp (only on webserver)
- platform: template
name: "Device Last Boot"
disabled_by_default: true
id: device_lastBoot_time
icon: mdi:clock-start
# waterdisplay timestamp last update
- platform: template
name: "Last update Timestamp"
id: watermeter_lastupdate
icon: mdi:clock-start
entity_category: "diagnostic"
# optional device timestamp (only for webserver)
- platform: template
id: systime
disabled_by_default: true
icon: mdi:clock-start
lambda: return id(time_sntp).now().strftime("%Y-%m-%dT%H:%M:%S %Z");
# connected to ssid (only for webserver)
# error: src/esphome/components/wifi_info/wifi_info_text_sensor.h:32:49: error: 'class esphome::wifi::WiFiComponent' has no member named 'get_dns_address'; did you mean 'get_ip_address'?
# don'nt know how to fix it
#- platform: wifi_info
# ssid:
# name: ${friendly_name} WLAN SSID
# id: wlan_ssid
# disabled_by_default: true
# icon: mdi:wifi-settings