I use UI to build 2 sensors via the helper / template (Settings => Devices & services => Helpers):
- 1st one being a statistics template to grab max value (ie
value_max) over last 90 minutes or last 50 samples of my temperature sensor. - 2nd one is also a statistics template to grab min value over same period of the same sensor
(I can share screenshots if needed.)
And then in my configuration.yaml, I also have this, also a template, to compare the max and min.
template:
- sensor:
- name: "ecobee Homekit Max-Min Temp Difference over 1.5hr"
unique_id: ecobee_homekit_max_min_temp_difference_over_1_5hr
state: >
{{ states('sensor.ecobee_homekit_max_temp') | float(0) -
states('sensor.ecobee_homekit_min_temp') | float(0) }}
The idea is that if the max and min being the same for long enough, I'm going to run an automation to restart my HomeKit. The setup has been working for months.
But my question being, is there a way to consolidate the 3 of those template sensors into one?
I think it is possible, but not quite sure where to start. Hence the question. Figured it could be a good opportunity to improve my jinja2-template-fu.