Counting operating hours under conditions

Hi,

I’m new to HA. I want to count operating hours of a device while its power consumption is above a chosen value.
Is it possible to “combine platform: history_stats” with conditions ?

Code:

Betriebsstundenzaehler Kamin

sensor:

  • platform: history_stats
    name: BhZaehlerPlug7Kamin
    entity_id: switch.plug7_kamin
    state: ‘on’
    type: time
    start: ‘{{ 0 }}’
    end: “{{ now() }}”

condition:
alias: “Kamin Leistung akt > 30 W”
condition: numeric_state
entity_id: sensor.plug7_kamin_energy_power
above: 30

Thanks a lot!
prome

Please have a read of point 11 here.

Create a template binary sensor that is on when your power is above 30W.

Then use that binary sensor in the history stats integration.

template:
  - binary_sensor:
      - name: "Kamin Leistung akt > 30 W"
        state: "{{ states('sensor.plug7_kamin_energy_power') | float(0) > 30 }}"
        device_class: power
1 Like

Good morning Tom_I,

thank you for your quick reply! You helped me a lot.

Have a nice day!

1 Like