Statistics sensor weighing a lot in HASS

I have found statistics not to be the easiest thing to show up within HASS, although I have several ideas in which it would be interesting to have it.

For instance:

  • How long is the TV turned on per day (from 6AM to 9:30PM)?
  • How long is the electric heater turned on during the evening?

For that purpose, I have done the following, using Statistics sensor:

### Check how much time TV is on, from 6am to 9:30pm
- platform: history_stats
  name: "TV ON today"
  entity_id: media_player.tv_sala
  state: 'on'
  type: time
  start: '{{ now().replace(hour=6).replace(minute=0).replace(second=0) }}'
  end: '{{ now().replace(hour=21).replace(minute=30).replace(second=0) }}'

- platform: mqtt
  state_topic: "time_from"
  name: "Time from"
  force_update: True

- platform: mqtt
  state_topic: "time_to"
  name: "Time to"
  force_update: True

### Check how much time Tomada is on, during plug control period
- platform: history_stats
  name: "Aquecimento"
  entity_id: switch.tomada
  state: 'on'
  type: time
### Determine start time in the day before
  start: '{{ as_timestamp(now().replace(hour=0).replace(minute=0).replace(second=0)) - (3600*24) + (states.sensor.time_from.state.split(":")[0] | int * 3600) + (states.sensor.time_from.state.split(":")[1] | int * 60) }}'
### Determine end date in current day
  end: '{{ as_timestamp(now().replace(hour=0).replace(minute=0).replace(second=0)) + (states.sensor.time_to.state.split(":")[0] | int * 3600) + (states.sensor.time_to.state.split(":")[1] | int * 60) }}'

Both statistics sensors work, but while the first doesn’t seem to have to have any relevant impact in performance, the second simply slows down HASS significantly (at the point of having lights based on movement sensor to take long time more to turn on).
HASS is currently running on an RPi 3 along with Homebridge, Mosquitto, MySQL, Prometheus and Grafana.

Has anyone faced issues like this one before?

I know the template is complex, but would this justify the added slowlyness? I was planning to have more sensors like this (to calculate daily electricity consumption/costs), but I stopped thinking about after this inconvenience…