Sensor value dynamic

Hi,
I have a switch that i use and store value in a file.
Example:

  - platform: command_line
    switches:
        vacation_mode:
            command_on: "echo -e '1' > sw5.ini"
            command_off: "echo -e '0' > sw5.ini"
            command_state: "cat sw5.ini"
            value_template: "{{ value == '1' }}"

I want to do a sensor that i can store and read value from with unit_of_measurement: ‘kW’.
How can I achieve that?

configuration:

template:
  - trigger:
      - platform: time_pattern
        # This will update every night
        hours: 0
        minutes: 1
    sensor:
      # Keep track how many days have past since a date
      - name: "last_power_meter_consumption"
        state: '{{ (states.sensor.power_meter_consumption.state | float | round (3) ) }}'
        unit_of_measurement: "kW"
 

  - trigger:
      - platform: time_pattern
        # This will update every night
        hours: 0
        minutes: 0
    sensor:
      # Keep track how many days have past since a date
      - name: "previous_day_power_meter_consumption"
        state: '{{ (states.sensor.power_meter_consumption.state | float | round (3) - states.sensor.last_power_meter_consumption.state | float | round (3) ) }}'
        unit_of_measurement: "kW"