I am using esphome for sensor. I have the following sensor value "Leistung" in my .yaml.…
- User
I am using esphome for sensor. I have the following sensor value "Leistung" in my .yaml. I now want to to have another sensor based on that "Leistung" which sends out the two minute rolling average of "Leistung" every 30 seconds.
- platform: sml
name: "Leistung"
sml_id: mysml
obis_code: "1-0:16.7.0"
unit_of_measurement: W
accuracy_decimals: 0
device_class: power
state_class: measurement
filters:
- throttle_average: 30s
- platform: sml
name: "Leistung"
sml_id: mysml
obis_code: "1-0:16.7.0"
unit_of_measurement: W
accuracy_decimals: 0
device_class: power
state_class: measurement
filters:
Assistant
You can create a rolling average sensor in ESPHome using a template sensor with a sliding window filter. Here's how to add it to your configuration:
sensor: - platform: sml name: "Leistung" sml_id: mysml obis_code: "1-0:16.7.0" unit_of_measurement: W accuracy_decimals: 0 device_class: power state_class: measurement filters: - throttle_average: 30s - platform: template name: "Leistung 2min Rolling Average" id: leistung_rolling_avg unit_of_measurement: W accuracy_decimals: 0 device_class: power state_class: measurement lambda: |- return id(leistung).state; update_interval: 30s filters: - sliding_window_moving_average: window_size: 4 send_every: 1The key points here:
- The template sensor reads from your original "Leistung" sensor using
id(leistung).state update_interval: 30smakes it update every 30 secondssliding_window_moving_averagewithwindow_size: 4creates a 2-minute rolling average (4 samples × 30 seconds = 120 seconds)send_every: 1ensures it sends the average every time it updates
Make sure to add an
id: leistungto your original sensor so the template can reference it:- platform: sml name: "Leistung" id: leistung # Add this line sml_id: mysml # ... rest of your configuration- The template sensor reads from your original "Leistung" sensor using
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.