I have added the following sensors to my configuration.yaml. The idea was, record the highest setting for these sensors and update them if the value increased. This works, but on a restart they are reset. How can I get around this?
- sensor:
- name: "Maximum Incoming Watts Combined"
unique_id: maximum_incoming_watts_combined
state: >-
{% set old_value = states('sensor.maximum_incoming_watts_combined')|float(default=0) %}
{% set new_value = states('sensor.lux_solar_output_live')|float(default=0) %}
{% if new_value > old_value %}
{{ new_value }}
{% else %}
{{ old_value }}
{% endif %}
- name: "Maximum Incoming Watts Front"
unique_id: maximum_incoming_watts_front
state: >-
{% set old_value = states('sensor.maximum_incoming_watts_front')|float(default=0) %}
{% set new_value = states('sensor.lux_solar_output_array_2_live')|float(default=0) %}
{% if new_value > old_value %}
{{ new_value }}
{% else %}
{{ old_value }}
{% endif %}
- name: "Maximum Incoming Watts Back"
unique_id: maximum_incoming_watts_back
state: >-
{% set old_value = states('sensor.maximum_incoming_watts_back')|float(default=0) %}
{% set new_value = states('sensor.lux_solar_output_array_1_live')|float(default=0) %}
{% if new_value > old_value %}
{{ new_value }}
{% else %}
{{ old_value }}
{% endif %}