Help on Calculating number of minutes the sensor value is above 2000 for the day

Hi,

I have a power sensor that calculates the current load of my house in Watts.

I want to calculate the number of minutes the load was above a certain value (let’s say 2000)

I tried the following code suggested by ChatGPT but it did not work.

  - platform: history_stats
    name: "Above 2000"
    entity_id: sensor.current_load_power 
    state: "above"
    state_value: 2000
    type: time
    start: "{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}"
    end: "{{ now() }}"

Can someone please show me a way?

Chat-GPT “hallucinates” heavily when it comes to HA configuration. It’s pool of data is about 2 years old and, conservatively, at least 50% of that is people on forums and Reddit posting configurations that don’t work and asking why they don’t work…

You need to set up a Template Binary sensor that is ‘on’ when current load power is over 2000, then base your History-Stats sensor on the binary sensor.

template:
  - binary_sensor:
      - name: "Above 2000"
        state: "{{ states('sensor.current_load_power') | int > 2000 }}"
        availability: "{{ states("sensor.current_load_power") | is_number }}"

sensor:
  - platform: history_stats
    name: "Hours Above 2000"
    entity_id: binary_sensor.above_2000 
    state: "on"
    type: time
    start: "{{ today_at() }}"
    end: "{{ now() }}"
1 Like

It worked. Thank you very much