Last one month sensor measurement reading

I have a energy sensor which is cumulative sensor ( total increasing )

  - platform: mqtt
    name: "device power"
    state_topic: "/device/SENSOR"
    value_template: "{{ value_json.ENERGY.Total }}"
    unit_of_measurement: "kWh"
    availability_topic: "/device/LWT"
    qos: 1
    payload_available: "Online"
    payload_not_available: "Offline"
    device_class: energy
    state_class: total_increasing

I want a new entity which shows the past one month consumption reading i.e total energy consumed in past 30 days and it should be continous running reading

eg:
{{ device_power(current value)  - device_power(30 days previous value)  }}

How to achieve the function , i search the forum but i cannot find any solution.

This is exactly what the Utility Meter integration is for. Use a monthly cycle and you’re all set:

By using the Monthly cycle in the Utility meter the reading will be reset to 0 at start of month
But I dont want it to be reset to 0

I want to know the past one month consumption reading i.e total energy consumed in past 30 days and it should be continous running total

Ok, then you will need to increase your recorder purge_keep_days to 30 and use a history stats sensor for the last 30 days. This will (eventually) tripple the size of your database, assuming your are using the default purge value of 10 days.