I’m looking for a way to show the maximum reached value of an entity. I already looked at the Min/Max value helper but that is only giving the me max value of today not all-time.
Is there a way to accomplish this?
Thanks!
I’m looking for a way to show the maximum reached value of an entity. I already looked at the Min/Max value helper but that is only giving the me max value of today not all-time.
Is there a way to accomplish this?
Thanks!
I do this with an input_number
and an automation:
- alias: Energy - max power recorder
description: Updates the maximum power recorder whenever prior maximum is exceeded
id: 0fef4933-5115-4055-91d2-48d5d3a051b7
trigger:
- platform: numeric_state
entity_id: sensor.power_meter_house
above: input_number.max_power
action:
- service: input_number.set_value
data:
entity_id: input_number.max_power
value: "{{ states('sensor.power_meter_house')|float(0.0) }}"
If statistics are created then you could write q query on it with SQL, it will only kick back one value though
How do you get the value using SQL? And put it in a template.
SQL integration allows you to execute a SQL query (dûh ) against a database. Yoiu just need to know how to write it which is (interesting) not for all.
I can try to provide an example
EDIT: you can also try to get this ‘once’ by a manual query on the db, then put it in the input_number along what @Troon suggested and it will be updated as of then
You can use a Trigger-based Template Sensor.
template:
- trigger:
- platform: state
entity_id: sensor.your_sensor
sensor:
- name: Your Sensor Maximum
state: >
{{ [trigger.to_state.state, this.state] | map('float', -99) | max }}
This is still based on ‘now’, the OP asked for all-time…
You suggestion seems to be similar as what @troon wrote, if would work as of sensor creation, correct?
On the side, so your suggestion would compare what value is stored ‘now’ and only update is it is higher?
I would like to add that both other (non-query) methods also work without the need to having statistics… so this may be the way forward
You’re absolutely right, it depends on what homest means by “all time”.
If it means including the entity’s values from the past then they’ll have to use SQL to query the database.
If it mean the entity’s values starting from now and into the future then they can use a Trigger-based Template Sensor.