I use a template sensor in the configuration.yaml which is set up like this:
template:
- trigger:
- platform: time
at: '00:00:00'
- platform: state
entity_id: sensor.tesla_pw2_solar_power_w
sensor:
- name: 'Solar Power Max Daily W'
unique_id: 'tesla_pw2_solar_power_w_daily_max'
unit_of_measurement: 'W'
device_class: power
state: >
{% set t_new = states('sensor.tesla_pw2_solar_power_w') | float(-50) | int() %}
{{ [t_new, this.state | float(-50) | int()] | max if trigger.platform != 'time' else t_new }}