Sensor - Derive status of a device from power consumption

Dear forum,

I do have a device, a heat pump, which can have three states which I want to derive from its power consumption:

  1. “STANDBY” i.e., power consumption <= 150 Watt
  2. “HEATING” (aka “Heizung”), power consumption above 150 Watt AND below 2300 Watt
  3. “WARM WATER” (aka “Warmwasser”), power above 2300 Watt

As you can see in attached history chart, the heat pump has some overshoot and drops in the power consumption while being in a certain state.

I want to create a sensor that derives the heat pump’s status - but with some kind of “smoothing” of the raw data to avoid e.g., the status to change from “WARM WATER” to “HEATING” for some minutes when the power consumption drops while the heat pump is in WARM WATER state.

I do have a working template sensor - but without that “smoothing” logic. And I am missing an idea how to that. Something like what we have in automation (below x for xx:xx:xx) would be sufficient, I guess. But no idea how to implement this in a template sensor.

Thanks for some hints and tips.

Jürgen

template:
  - sensor:
    - name: "Wärmepumpe - Status"
      unique_id: sensor.waermepumpe_status
      state: >
        {% if states('sensor.stromwaerme_waerme_aktuell')|int < 150 %}
          Standby 
        {% elif states('sensor.stromwaerme_waerme_aktuell')|int < 2300 %}
          Heizung
        {% elif states('sensor.stromwaerme_waerme_aktuell')|int >= 2300 %}
          Warmwasser
        {% else %}
          Unbekannt
        {% endif %}

Example power consumption: “Heating” between 1:00 and 1:30 am as well as 4:20 and 6:20 am; “warm water” state between 2:00 and 3:25 am

You can use triggers in template sensors: Template - Home Assistant
This means you can set a trigger for when the state changes for x amount of time, just like in an automation. The conditions for triggers and other rules that you set in an automation would have to be managed within the template.

Another possibility, that’s how I display the state of my washing machine and dryer, would be to use an automation and set the state of an entity from there. This adds the bonus of debugging capabilities (my washing cycle power consumptions are quite complex) and using the UI.

Hi Florian,

thanks for that input :slight_smile: Helpful - I started experimenting.

Would you mind sharing your setup for the 2nd / the “automation” option? I am not sure I get that yet completely. I assume you use the python set_state script (which I installed in the meantime) but I am struggling how the automation(s) look like. A glance at your YAML definitions of it would likely help me a lot.

My dryer is a bit easier:

trigger:
  - platform: numeric_state
    entity_id: sensor.trockner_power
    above: "50"
    id: "1"
    for:
      hours: 0
      minutes: 0
      seconds: 10
  - platform: numeric_state
    entity_id: sensor.trockner_power
    id: "2"
    below: "50"
    for:
      hours: 0
      minutes: 0
      seconds: 10
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: "1"
          - condition: or
            conditions:
              - condition: state
                entity_id: var.trockner_status
                state: Aus
              - condition: state
                entity_id: var.trockner_status
                state: Fertig
        sequence:
          - service: var.set
            data:
              entity_id: var.trockner_status
              value: Programm läuft
      - conditions:
          - condition: trigger
            id: "2"
        sequence:
          - choose:
              - conditions:
                  - condition: state
                    entity_id: var.trockner_status
                    state: Programm läuft
                sequence:
                  - service: var.set
                    data:
                      entity_id: var.trockner_status
                      value: Fertig
            default: []
          - delay:
              hours: 0
              minutes: 5
              seconds: 0
              milliseconds: 0
          - condition: state
            entity_id: sensor.trockner_power
            state: "0.0"
          - service: var.set
            data:
              entity_id: var.trockner_status
              value: Aus

I guess I don’t need to translate the german words :wink:

I am not using the script. I use the custom component var to store information. You could also store it in an input_text and derive a template sensor from that.