History stats from Shelly BLU TRV

I have many Sonoff TRVs in my house and i’m tracking the heating stats daily with this code:

platform: history_stats
name: "Hall värme idag"
entity_id: sensor.element_hall_hvac_aktivitet
state: "heating"
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"

Now I also have 2 Shelly TRV’s in my system, but they dont have the “heating” state. It only have the valve position 0-100
**How can I adjust the code to track when valve is 1-100% open?

Can someone tips me how to adjust the code I already have?

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

1 Like

Like this…?

This how the code looks for counting Sonoff TRV.
(there is a state “heating”)

platform: history_stats
name: "Hall värme idag"
entity_id: sensor.element_hall_hvac_aktivitet
state: "heating"
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"

For the Shelly there is only a sensor that shows 0 if valve is closed and 1-100% when valve is more or less open.

I put in this code and the history stat shows how many hours the valve has been closed(0). How to revert it so it presents hours heating(1-100)?

platform: history_stats
name: "Hall värme idag"
entity_id: sensor.element_hall_valve_open
state: "0"
type: time
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"

Create a template binary sensor helper to track if the valve is open or closed. Once that is created you can reference it in a new history stats sensor.

You can use this as a template:

{{ states('sensor.element_hall_valve_open') | float(0) > 0 }}

I think i need some more help. The valve is giving the information 0-100%. Closed is 0%, 1-100% is open. How can I code the helper to track all time its status is 1-100%? Do I add your suggested text in Configuration.yaml or through the helper interface? Should I use ON as time for history stats from Binary sensor?

Settings → Devices and services → helpers → create helper → template → binary sensor

The code goes into the “state” field.

You can choose an appropriate device class (like “opening”) to change how the sensor is displayed on a dashboard.

And yes, then you use this new helper in your statistics and use “on” as the state.