haussteuerung:esphome:gaszaehler
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| haussteuerung:esphome:gaszaehler [2025/11/11 04:33] – dominik | haussteuerung:esphome:gaszaehler [2025/11/11 06:57] (current) – [ALT] dominik | ||
|---|---|---|---|
| Line 138: | Line 138: | ||
| return (id(initial_consumption) + (id(total_pulses) * id(impuls_factor))) * brennwert * zustandszahl; | return (id(initial_consumption) + (id(total_pulses) * id(impuls_factor))) * brennwert * zustandszahl; | ||
| </ | </ | ||
| + | |||
| + | ===== Neu ===== | ||
| + | <code | download> | ||
| + | substitutions: | ||
| + | devicename: " | ||
| + | |||
| + | esphome: | ||
| + | name: iot-kl-wl-sc-gaszaehler | ||
| + | friendly_name: | ||
| + | |||
| + | esp32: | ||
| + | board: esp32-c3-devkitm-1 | ||
| + | framework: | ||
| + | type: esp-idf | ||
| + | | ||
| + | |||
| + | preferences: | ||
| + | flash_write_interval: | ||
| + | |||
| + | # Enable logging | ||
| + | logger: | ||
| + | baud_rate: 115200 | ||
| + | level: DEBUG | ||
| + | |||
| + | # Enable Home Assistant API | ||
| + | api: | ||
| + | encryption: | ||
| + | key: !secret api_encryption_key | ||
| + | # services: | ||
| + | # - service: set_initial_gas_reading | ||
| + | # variables: | ||
| + | # reading: float | ||
| + | # then: | ||
| + | # - lambda: |- | ||
| + | # id(initial_consumption) = reading; | ||
| + | # ESP_LOGI(" | ||
| + | # - homeassistant.service: | ||
| + | # service: persistent_notification.create | ||
| + | # data: | ||
| + | # title: " | ||
| + | # message: "Neuer Startwert: {{ reading }} m³" | ||
| + | |||
| + | ota: | ||
| + | - platform: esphome | ||
| + | password: !secret ota_password | ||
| + | |||
| + | wifi: | ||
| + | ssid: !secret wifi_ssid | ||
| + | password: !secret wifi_password | ||
| + | ap: | ||
| + | ssid: " | ||
| + | password: " | ||
| + | #manual_ip: | ||
| + | # static_ip: 192.168.30.133 | ||
| + | # gateway: 192.168.30.1 | ||
| + | # subnet: 255.255.255.0 | ||
| + | |||
| + | # Enable Web server | ||
| + | web_server: | ||
| + | port: 80 | ||
| + | version: 3 | ||
| + | |||
| + | button: | ||
| + | - platform: restart | ||
| + | name: " | ||
| + | id: restart_button | ||
| + | icon: " | ||
| + | |||
| + | # DEBUGGING (inkl. Mem Usage) | ||
| + | # https:// | ||
| + | debug: | ||
| + | update_interval: | ||
| + | |||
| + | status_led: | ||
| + | pin: GPIO8 | ||
| + | |||
| + | # Time component to sync with Home Assistant | ||
| + | time: | ||
| + | - platform: homeassistant | ||
| + | id: ha_time | ||
| + | |||
| + | # Define global variables for thresholds (adjust these as needed) | ||
| + | globals: | ||
| + | - id: low_threshold | ||
| + | type: float | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | - id: high_threshold | ||
| + | type: float | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | - id: impulse_value | ||
| + | type: float | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | |||
| + | # Persistent impulse counter | ||
| + | - id: gas_total_impulses | ||
| + | type: int | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | |||
| + | # Period tracking globals (last_period restore no to reinitialize on boot) | ||
| + | - id: last_hour | ||
| + | type: int | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | - id: last_day | ||
| + | type: int | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | - id: last_week | ||
| + | type: int | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | - id: last_month | ||
| + | type: int | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | - id: last_year | ||
| + | type: int | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | |||
| + | # Start totals for each period (restore true to persist values) | ||
| + | - id: hourly_start_total | ||
| + | type: float | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | - id: daily_start_total | ||
| + | type: float | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | - id: weekly_start_total | ||
| + | type: float | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | - id: monthly_start_total | ||
| + | type: float | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | - id: yearly_start_total | ||
| + | type: float | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | |||
| + | # Editable number for initial consumption (persistent, | ||
| + | number: | ||
| + | - platform: template | ||
| + | name: " | ||
| + | id: initial_consumption | ||
| + | optimistic: true | ||
| + | restore_value: | ||
| + | initial_value: | ||
| + | min_value: 0 | ||
| + | max_value: 1000000 | ||
| + | step: 0.01 | ||
| + | unit_of_measurement: | ||
| + | icon: " | ||
| + | mode: box | ||
| + | |||
| + | sensor: | ||
| + | - platform: adc | ||
| + | pin: GPIO3 | ||
| + | name: "Hall Sensor ADC" | ||
| + | id: hall_adc | ||
| + | update_interval: | ||
| + | attenuation: | ||
| + | unit_of_measurement: | ||
| + | accuracy_decimals: | ||
| + | internal: True | ||
| + | filters: | ||
| + | - median: | ||
| + | window_size: | ||
| + | send_every: 3 | ||
| + | |||
| + | # Template sensor for total impulses (exposes the global) | ||
| + | - platform: template | ||
| + | name: "Total Gas Impulses" | ||
| + | id: gas_total_impulses_sensor | ||
| + | unit_of_measurement: | ||
| + | icon: " | ||
| + | accuracy_decimals: | ||
| + | update_interval: | ||
| + | lambda: |- | ||
| + | return id(gas_total_impulses); | ||
| + | |||
| + | # Template sensor for total consumption | ||
| + | - platform: template | ||
| + | name: "Total Gas Consumption" | ||
| + | id: total_gas_consumption | ||
| + | unit_of_measurement: | ||
| + | icon: " | ||
| + | accuracy_decimals: | ||
| + | update_interval: | ||
| + | lambda: |- | ||
| + | return id(initial_consumption).state + (id(gas_total_impulses) * id(impulse_value)); | ||
| + | |||
| + | # Period checker (runs every 60s to detect period changes and reset starts) | ||
| + | - platform: template | ||
| + | name: " | ||
| + | id: period_checker | ||
| + | update_interval: | ||
| + | lambda: |- | ||
| + | auto now = id(ha_time).now(); | ||
| + | if (!now.is_valid()) return NAN; | ||
| + | |||
| + | float current_total = id(total_gas_consumption).state; | ||
| + | |||
| + | // Hourly | ||
| + | int current_hour = now.hour; | ||
| + | if (current_hour != id(last_hour)) { | ||
| + | id(hourly_start_total) = current_total; | ||
| + | id(last_hour) = current_hour; | ||
| + | } | ||
| + | |||
| + | // Daily | ||
| + | int current_day = now.day_of_month; | ||
| + | if (current_day != id(last_day)) { | ||
| + | id(daily_start_total) = current_total; | ||
| + | id(last_day) = current_day; | ||
| + | } | ||
| + | |||
| + | // Weekly (Monday-based week number) | ||
| + | char week_buf[3]; | ||
| + | now.strftime(week_buf, | ||
| + | int current_week = atoi(week_buf); | ||
| + | if (current_week != id(last_week)) { | ||
| + | id(weekly_start_total) = current_total; | ||
| + | id(last_week) = current_week; | ||
| + | } | ||
| + | |||
| + | // Monthly | ||
| + | int current_month = now.month; | ||
| + | if (current_month != id(last_month)) { | ||
| + | id(monthly_start_total) = current_total; | ||
| + | id(last_month) = current_month; | ||
| + | } | ||
| + | |||
| + | // Yearly | ||
| + | int current_year = now.year; | ||
| + | if (current_year != id(last_year)) { | ||
| + | id(yearly_start_total) = current_total; | ||
| + | id(last_year) = current_year; | ||
| + | } | ||
| + | |||
| + | return 0.0; // Dummy value, hide this sensor in HA if possible | ||
| + | |||
| + | # Periodic consumption sensors (update every 60s) | ||
| + | - platform: template | ||
| + | name: "Gas Consumption Hourly" | ||
| + | id: hourly_gas | ||
| + | unit_of_measurement: | ||
| + | icon: " | ||
| + | accuracy_decimals: | ||
| + | update_interval: | ||
| + | lambda: |- | ||
| + | return id(total_gas_consumption).state - id(hourly_start_total); | ||
| + | |||
| + | - platform: template | ||
| + | name: "Gas Consumption Daily" | ||
| + | id: daily_gas | ||
| + | unit_of_measurement: | ||
| + | icon: " | ||
| + | accuracy_decimals: | ||
| + | update_interval: | ||
| + | lambda: |- | ||
| + | return id(total_gas_consumption).state - id(daily_start_total); | ||
| + | |||
| + | - platform: template | ||
| + | name: "Gas Consumption Weekly" | ||
| + | id: weekly_gas | ||
| + | unit_of_measurement: | ||
| + | icon: " | ||
| + | accuracy_decimals: | ||
| + | update_interval: | ||
| + | lambda: |- | ||
| + | return id(total_gas_consumption).state - id(weekly_start_total); | ||
| + | |||
| + | - platform: template | ||
| + | name: "Gas Consumption Monthly" | ||
| + | id: monthly_gas | ||
| + | unit_of_measurement: | ||
| + | icon: " | ||
| + | accuracy_decimals: | ||
| + | update_interval: | ||
| + | lambda: |- | ||
| + | return id(total_gas_consumption).state - id(monthly_start_total); | ||
| + | |||
| + | - platform: template | ||
| + | name: "Gas Consumption Yearly" | ||
| + | id: yearly_gas | ||
| + | unit_of_measurement: | ||
| + | icon: " | ||
| + | accuracy_decimals: | ||
| + | update_interval: | ||
| + | lambda: |- | ||
| + | return id(total_gas_consumption).state - id(yearly_start_total); | ||
| + | |||
| + | ##### ESP Werte | ||
| + | - platform: wifi_signal | ||
| + | name: "ESP32 WiFi Signal" | ||
| + | id: esp32_wifi_signal | ||
| + | update_interval: | ||
| + | - platform: uptime | ||
| + | name: "ESP32 Uptime (s)" | ||
| + | unit_of_measurement: | ||
| + | update_interval: | ||
| + | icon: mdi: | ||
| + | - platform: internal_temperature | ||
| + | name: "ESP32 CPU Temperatur" | ||
| + | unit_of_measurement: | ||
| + | update_interval: | ||
| + | device_class: | ||
| + | state_class: | ||
| + | icon: mdi:chip | ||
| + | |||
| + | ##### DEBUGGING | ||
| + | - platform: debug | ||
| + | free: | ||
| + | name: "Heap Free" | ||
| + | # | ||
| + | # name: "Heap Fragmentation" | ||
| + | block: | ||
| + | name: "Heap Max Block" | ||
| + | loop_time: | ||
| + | name: "Loop Time" | ||
| + | #psram: | ||
| + | # name: "Free PSRAM" | ||
| + | cpu_frequency: | ||
| + | name: "CPU Frequency" | ||
| + | |||
| + | binary_sensor: | ||
| + | - platform: template | ||
| + | name: "Hall Impulse Detector" | ||
| + | id: hall_detector | ||
| + | device_class: | ||
| + | #internal: True | ||
| + | lambda: |- | ||
| + | static bool last_state = false; | ||
| + | float current_value = id(hall_adc).state; | ||
| + | bool current_state = (current_value > id(high_threshold)); | ||
| + | bool impulse_detected = (!last_state && current_state); | ||
| + | last_state = current_state; | ||
| + | return impulse_detected; | ||
| + | # | ||
| + | filters: | ||
| + | - delayed_off: | ||
| + | on_press: | ||
| + | then: | ||
| + | - lambda: |- | ||
| + | id(gas_total_impulses) += 1; | ||
| + | id(gas_total_impulses_sensor).publish_state(id(gas_total_impulses)); | ||
| + | id(total_gas_consumption).publish_state(id(initial_consumption).state + (id(gas_total_impulses) * id(impulse_value))); | ||
| + | |||
| + | text_sensor: | ||
| + | - platform: uptime | ||
| + | name: "ESP32 Uptime" | ||
| + | format: | ||
| + | separator: " " | ||
| + | days: " | ||
| + | hours: | ||
| + | minutes: | ||
| + | |||
| + | - platform: wifi_info | ||
| + | ip_address: | ||
| + | name: "ESP32 IP Address" | ||
| + | ssid: | ||
| + | name: "ESP32 Connected SSID" | ||
| + | bssid: | ||
| + | name: "ESP32 Connected BSSID" | ||
| + | mac_address: | ||
| + | name: "ESP32 Mac Address" | ||
| + | scan_results: | ||
| + | name: "ESP32 Latest WiFi Scan" | ||
| + | dns_address: | ||
| + | name: "ESP32 DNS Address" | ||
| + | | ||
| + | # DEBUGGING | ||
| + | - platform: debug | ||
| + | device: | ||
| + | name: " | ||
| + | reset_reason: | ||
| + | name: "Reset Reason" | ||
| + | </ | ||
| + | |||
haussteuerung/esphome/gaszaehler.1762831980.txt.gz · Last modified: by dominik
