Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- substitutions:
- device_name: "{{ device.device_name }}"
- mqtt_path: "{{ device.mqtt.path }}"
- mqtt_prefix: ${mqtt_path}/${device_name}
- node_name: "{{ device.name.long }}"
- mqtt_broker: "{{ general_mqtt_config.ip }}"
- template_version: "3"
- human_readable_name: "{{ device.name.long | replace('ö', 'oe') | replace('ü', 'ue')}}"
- # Secrets
- auth_password: !secret web_auth_password
- mqtt_user: "{{ device.mqtt.username }}"
- mqtt_password: {{ device.mqtt.password }}
- mqtt_ssl_fingerprint: !secret mqtt_ssl_fingerprint
- mqtt_topic_last_value: ${mqtt_prefix}/last_value
- esphome:
- name: ${device_name}
- esp32:
- board: az-delivery-devkit-v4
- framework:
- type: arduino
- # Enable logging
- logger:
- ota:
- password: ${auth_password}
- wifi:
- ssid: !secret wifi_ssid
- password: !secret wifi_password
- ap:
- ssid: "${device_name} Fallback"
- password: !secret fallback_hotspot_password
- mdns:
- disabled: true
- captive_portal:
- web_server:
- port: 80
- auth:
- username: admin
- password: ${auth_password}
- time:
- - platform: sntp
- id: sntp_time
- servers:
- - "192.168.20.1"
- mqtt:
- broker: ${mqtt_broker}
- # port: 8883 # SSL
- port: 8884
- username: ${mqtt_user}
- password: ${mqtt_password}
- discovery: true
- discovery_retain: true
- discovery_unique_id_generator: mac
- discovery_object_id_generator: device_name
- topic_prefix: ${mqtt_prefix}
- # ssl_fingerprints:
- # - ${mqtt_ssl_fingerprint}
- birth_message:
- topic: ${mqtt_prefix}/status
- payload: online
- retain: true
- will_message:
- topic: ${mqtt_prefix}/status
- payload: offline
- retain: true
- on_message:
- - topic: ${mqtt_topic_last_value}
- then:
- - globals.set:
- id: last_value
- value: !lambda |-
- auto value = parse_number<float>(x);
- if(value.has_value()) {
- ESP_LOGI("main", "Using last value from MQTT: %f", value.value());
- return value.value();
- }
- ESP_LOGE("main", "Last value from MQTT couldn't be parsed: %s", x.c_str());
- return 0.0f;
- globals:
- - id: last_value
- type: float
- restore_value: no
- initial_value: NAN
- switch:
- - platform: restart
- name: "${human_readable_name} reset"
- id: reset
- text_sensor:
- # https://esphome.io/components/text_sensor/version.html
- - platform: version
- name: version
- - platform: wifi_info
- ip_address:
- name: "${human_readable_name} ip_address"
- ssid:
- name: "ssid"
- bssid:
- name: "bssid"
- mac_address:
- name: "mac_address"
- scan_results:
- name: "scan_results"
- - platform: template
- id: "template_version"
- name: "template_version"
- lambda: |-
- return {"${template_version}"};
- update_interval: 300s
- - platform: template
- id: "human_readable_name"
- name: "human_readable_name"
- lambda: |-
- return {"${human_readable_name}"};
- update_interval: 300s
- binary_sensor:
- - platform: gpio
- pin: 14
- name: "Raw Impulse"
- id: "raw_impulse"
- internal: true
- sensor:
- - platform: pulse_counter
- pin: 14
- name: "Gas Impuls"
- id: "gas_delta_60"
- device_class: "gas"
- state_class: "total"
- icon: "mdi:fire"
- unit_of_measurement: "m³"
- accuracy_decimals: 2
- update_interval: 60s
- filters:
- - debounce: 1.0s
- - multiply: 0.01
- total:
- name: "Total m^3"
- id: "total_m3"
- device_class: "gas"
- state_class: "total"
- icon: "mdi:fire"
- unit_of_measurement: "m³"
- accuracy_decimals: 2
- filters:
- - debounce: 1.0s
- - multiply: 0.01
- - lambda: |-
- auto restored_value = id(last_value);
- if(isnan(restored_value)) {
- restored_value = 0.0f;
- }
- ESP_LOGI("main", "Adding last_value %f to total value", restored_value);
- return restored_value + x;
- - filter_out: 0.0
- on_value:
- then:
- - mqtt.publish:
- topic: ${mqtt_topic_last_value}
- payload: !lambda "return to_string(x);"
- retain: true
- # - platform: total_daily_energy
- # name: "Total m^3 (daily)"
- # id: "total_m3_daily"
- # power_id: total_m3
- # device_class: "gas"
- # state_class: "total"
- # unit_of_measurement: "m³"
- # https://esphome.io/components/sensor/wifi_signal.html
- - platform: wifi_signal
- name: "${human_readable_name} wifi_signal"
- update_interval: 60s
- # https://esphome.io/components/sensor/uptime.html
- - platform: uptime
- name: "${human_readable_name} uptime"
- unit_of_measurement: seconds
- filters:
- - lambda: return x;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement