Filter Sensor does not show up in UI

Hello everybody,

I am new to HA . Things I want to learn from this topic:

  • How to debug a similar Problem next time
  • How to create a moving average filter for an existing sensor

Problem: I want to switch a dehumidifier on if my average solar power is above 300W during the last hour and switch it of it was below 100W. For that I need to calculate the average solar power.

My Idea was to copy the code block from Filter - Home Assistant

# Example configuration.yaml entry
sensor:
  - platform: filter
    name: "filtered realistic humidity"
    entity_id: sensor.realistic_humidity
    filters:
      - filter: outlier
        window_size: 4
        radius: 4.0
      - filter: lowpass
        time_constant: 10
        precision: 2
  - platform: filter
    name: "filtered realistic temperature"
    entity_id: sensor.realistic_temperature
    filters:
      - filter: outlier
        window_size: 4
        radius: 2.0
      - filter: lowpass
        time_constant: 10
      - filter: time_simple_moving_average
        window_size: "00:05"
        precision: 2

the resulting configuration.yaml looks like this: (bottem section should be interesting)

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

input_number:
  box1:
    name: Heizer_MAX-Leistung [w]
    initial: 2000
    min: 0
    max: 3600
    step: 1
    mode: box
  box2:
    name: Heizer_Regelpunkt [W]
    initial: -50
    min: -600
    max: 5000
    step: 1
    mode: box

template:
  - sensor:
      - name: "Heizer_Prozent"
        unit_of_measurement: "%"
        state: >
          {% if is_state('fan.heizer_pwm_fan', 'on') %}
            {{ state_attr("fan.heizer_pwm_fan", "percentage") }}
          {% else %}
            0
          {% endif %}
      - name: "Heizer_Leistung"
        unit_of_measurement: "W"
        state: >
          {% if is_state('fan.heizer_pwm_fan', 'on') %}
            {{ state_attr("fan.heizer_pwm_fan", "percentage") / 100 * states('input_number.box1')|float }}
          {% else %}
            0
          {% endif %}
      - name: "Heizer_Bool"
        unit_of_measurement: ""
        state: >
          {% if is_state('fan.heizer_pwm_fan', 'on') %}
            1
          {% else %}
            0
          {% endif %}
      - name: "Rechnerische Leistung"
        unique_id: 7145e5a0-caf3-4fef-b99d-d95d0cfd1b0d
        unit_of_measurement: "W"
        state: "{{ states('sensor.leistung_phase_1')|float + states('sensor.leistung_phase_2')|float + states('sensor.leistung_phase_3')|float  }}"
      

mqtt:
  sensor:
    - name: "Leistung"
      #state_topic: "tele/Tasmota_Stromzaehler/SENSOR"
      state_topic: "stat/Tasmota_Stromzaehler/STATUS8"
      suggested_display_precision: 1
      unit_of_measurement: "W"
      #value_template: "{{ value_json.SML.curr_w }}"
      value_template: "{{ value_json.StatusSNS.SML.curr_w }}"
    - name: "Summe_Stromverbrauch"
      state_topic: "tele/Tasmota_Stromzaehler/SENSOR"
      suggested_display_precision: 3
      unit_of_measurement: "kWh"
      value_template: "{{ value_json.SML.total_kwh }}"
    - name: "Summe_Einspeisung"
      state_topic: "tele/Tasmota_Stromzaehler/SENSOR"
      suggested_display_precision: 5
      unit_of_measurement: "kWh"
      value_template: "{{ value_json.SML.export_total_kwh }}"
    - name: "Leistung_Phase_1"
      state_topic: "tele/Tasmota_Stromzaehler/SENSOR"
      unique_id: 7145e5a0-caf3-4fef-b99d-d95d0cfd1b0a
      suggested_display_precision: 1
      unit_of_measurement: "W"
      value_template: "{{ value_json.SML.volt_p1 * value_json.SML.amp_p1 * cos(value_json.SML.phase_angle_p1 * 3.1415926 / 180) }}"
    - name: "Leistung_Phase_2"
      state_topic: "tele/Tasmota_Stromzaehler/SENSOR"
      unique_id: 7145e5a0-caf3-4fef-b99d-d95d0cfd1b0b
      suggested_display_precision: 1
      unit_of_measurement: "W"
      value_template: "{{ value_json.SML.volt_p2 * value_json.SML.amp_p2 * cos(value_json.SML.phase_angle_p2 * 3.1415926 / 180) }}"
    - name: "Leistung_Phase_3"
      state_topic: "tele/Tasmota_Stromzaehler/SENSOR"
      unique_id: 7145e5a0-caf3-4fef-b99d-d95d0cfd1b0c
      suggested_display_precision: 1
      unit_of_measurement: "W"
      value_template: "{{ value_json.SML.volt_p3 * value_json.SML.amp_p3 * cos(value_json.SML.phase_angle_p3 * 3.1415926 / 180) }}"
      
sensor:
  - platform: filter
    name: "Leistung_Balkonkraftwerk_Mittel"
    entity_id: sensor.balkon_power
    filters:
      - filter: time_simple_moving_average
        window_size: "00:60"

Nothing happens. I would expect to find some entity sensor.Leistung_Balkonkraftwerk_Mittel or at least anything containint “Mittel” in my entity list.
The input sensor should exist:

  • do you see any error?
  • which log should I look at for debugging?
  • why does the syntax look different for template + mqtt than for filter? The sequence of the word “sensor” and the “platform” seems illogical to me. Is that some legacy thing?

I will check the topic and edit if the code blocks do not appear as expectet. It’s my first post.
Thank you in advance.

Daniel

Have you restarted HA to pull in the changes to the config? Once you have, look under System / Logs for errors.

Also try window_size: "01:00" — one hour rather than 60 minutes. I don’t know if that’s a problem.

Off-topic, but you should remove the unit_of_measurement: "" line from Heizer_Bool.

Hi Troon,

thank you for your response! The only thing I could see in the log was

File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2006, in forgiving_float_filter
    return float(value)
           ^^^^^^^^^^^^

however: The Sensor came up just fine


Why did I have to restart in this case? For all the other template/mqtt sensor, I just klicked Developer Tools - Reload Yaml
(I am using the german UI, so wording might be wrong)

I edited the Bool Sensor

If you add a new top-level integration (sensor in this case), you need to restart.