Get yesterday's energy value

I would like to get the energy bought and sold the day before but I only get unknown, where am I wrong?

 - platform: template
   name: Energy Purchased Yesterday
   id: purchased_yesterday
   unit_of_measurement: Wh
   accuracy_decimals: 0
   icon: mdi:lightning-bolt

 - platform: template
   name: Energy Feed Yesterday
   id: feed_yesterday
   unit_of_measurement: Wh
   accuracy_decimals: 0
   icon: mdi:lightning-bolt
time:
  - platform: homeassistant
    on_time:
      - seconds: 59
        minutes: 59
        hours: 23
        then:
          - sensor.template.publish:
              id: purchased_yesterday
              state: !lambda |-
                return id(energia_prel_chint).state;
          - sensor.template.publish:
              id: feed_yesterday
              state: !lambda |-
                return id(energia_imm_chint).state;

Can anyone help me?