Daily sensor alternative

I’ve just upgraded to 2023.6 and the custom integration Daily Sensor no longer works. I use it to get the daily max/min for my temperature sensors. Is there a “better” way of doing this without using a custom integration? Thanks

Hi

Can you give a little more details?

You have a sensor that show the current temperature.

Do you just need to create two new sensors: One for maximum and one for minimum?

Or you want the min and max as attributes?

And reset at midnight I assume.

Check out the statistics sensor. It is a rolling window but it may get you what you’re looking for

Here is my proposal

We use a triggered template sensor

In my configuration.yaml I define this line

template: !include_dir_merge_list template_items

I then have a directory called template_items where I place all my various template sensors

I made a minmax.yaml that looks like this

- trigger:
    - platform: state
      entity_id: sensor.mi_sensor_living_room_temperature
      id: tempupdate
    - platform: time
      at: "00:00:00"
      id: reset
  sensor:
    - name: "Temperature Max Test"
      unique_id: temperature_max_test
      device_class: temperature
      unit_of_measurement: '°C'
      state: >
        {% if trigger.id == 'reset' or  float(states('sensor.mi_sensor_living_room_temperature')) > float(this.state, -100) %}
          {{ float(states('sensor.mi_sensor_living_room_temperature')) }}
        {% else %}
          {{ float(this.state) }}
        {% endif %}
    - name: "Temperature Min Test"
      unique_id: temperature_min_test
      device_class: temperature
      unit_of_measurement: '°C'
      state: >
        {% if trigger.id == 'reset' or  float(states('sensor.mi_sensor_living_room_temperature')) < float(this.state, 100) %}
          {{ float(states('sensor.mi_sensor_living_room_temperature')) }}
        {% else %}
          {{ float(this.state) }}
        {% endif %}

Let me walk through it.

First we define two triggers.

The first is the sensor we are monitoring for min and max. That is obvious
The next is a time trigger that triggers at midnight

Each sets a trigger ID so we know which kind of trigger we had.

The sensor is now defined by a template

We check is the trigger is a reset. If so then we set the max and min equal to the current value

For the max we compare the monitored sensor with the current value of the min or max sensor itself. If the new value is larger or smaller we set the max or min. If not then we set it to itself.

The values we get are text strings so we have to put float() around. And when we start the sensors for the first time or reset HA we need the sensors to set the value from the monitored sensor so I put a very low default value for minimum and very high value for max.

I am not sure how we could make this sensor wake up from a reset and just be what is was before the reset. But it has to be a number for the comparison to work and not cause a code error.

I have several Sonoff ZigBee temperature sensors. When configured with the Daily Sensor integration, I get two new entities for each of them, a max and a min, which reset their values at midnight. I can use these in Dashboards like any other entity.

(I’ve seen the comments below and I’ll have a look at them hopefully later today.)

Trigger templates sensors restore their state on restart (you are talking about restart, when you say reset, aren’t you? Because your midnight id is reset as well).

Further idea: I would check against is_number because with .5 you will get errors in your log if such sensor is not a number (e.g. when source is not available or returns not a number for whatever reasons). So if not a number take the old value as well (because of this rule and the restore it will be always a number).

And your first float does not have a default, so it would result in an error as well, but even if you set default to 0 it would be >-100 and would store the wrong 0, resp. a 0 where the source has only delivered not a number once.

E.g.

            {% if trigger.id == 'reset' %}
              {{ float(states('sensor.mi_sensor_living_room_temperature'), 'None') }}
            {% else %}
              {% if is_number(states('sensor.mi_sensor_living_room_temperature')) %}
                {% if float(states('sensor.mi_sensor_living_room_temperature')) > float(this.state, -100) %}
                  {{ float(states('sensor.mi_sensor_living_room_temperature')) }}
                {% else %}
                  {{ float(this.state) }}
                {% endif %}
              {% else %}
                {{ float(this.state) }}
              {% endif %}
            {% endif %}

ofc, can be condenced somehow with some or’s and elif, but this way easier to read.

Thanks for the suggestion. As you say, it’s a rolling window which isn’t quite what I want. I want to know what the max and min temperatures are each day. A rolling window will be confusing.

Thanks for your suggestions, it looks like it’ll work. As it happens there is a workaround to get the daily sensor to work but this is a great place to go if it stops working again.