How to copy sensor value with unit to another read-only entity

I have 2 sensors, sensor.a(sum of kWh value) & sensor.b(total price)

Possible to copy that 2 sensor value to another sensor, let said sensor.a to sensor.c & sensor.b to sensor.d on every 19th of month as read only sensor? both sensor is numeric value.

I already figure out how to trigger every 19th of month by below command

  - platform: time
    at: "23:59:00"
  - condition: template
    value_template: "{{ now().day == 19 }}"

but I not able to figure out how to copy that 2 sensors to read only sensor(sensor.c & sensor.d). This 2 sensor.c & sensor.d will be use to display on frontend as monthly value.

If you want a read only sensors, don’t use an automation. Use triggered template sensors.


  - trigger:
      - platform: template
        value_template: "{{ now().day == 19 and now().hour == 23 and now().minute == 59 }}" 
      - name: Sensor C
        state: "{{ states('sensor.a') }}"
        unit_of_measurement: kWh
        device_class: energy

      - name: Sensor D
        state: "{{ states('sensor.b') }}"
        unit_of_measurement: kWh
        device_class: energy

However… having provided you with a solution I can now tell you it may be the wrong one.

It is much easier to create utility meters with a monthly cycle and an offset. You can do this from the UI.

1 Like

At first, thanks for the reply, utility meter in this case might not suitable as it will keep on adding the previously value, the sensor.a(kwh) already final value which collect from multiple device’s utility meter. I will try your triggered template sensor to see the outcome.

Both sensors will be unknown until 23:59 on the 19th of next month. To test it just change the day, hours and minutes in the template trigger.

I will try it short while. Thanks again.

Template trigger so far so good, thank again

1 Like

is that possible to add the notify me function to this “triggered template” once data is copy? what I know i can do it on automation but not in configuration file. I have setup the telegram notification that ready to use, just not sure how to setup “copy done” notification in configuration file.

You would have to use an automation for that.

Trigger on sensor C or D changing.

alias: "sensors saved notification"
  - platform: state
    entity_id: sensor.c
      - unknown
      - unavailable
      - unknown
      - unavailable
  - service: notify.telegram # your notification service here
      title: "💾 <b>Sensors Saved</b>"
      message: >
        Sensor C is {{ states('sensor.c') }} kWh

        Sensor D is {{ states('sensor.d') }} kWh

There are a number of tips in the message. The double newline will show up as a single newline in the message. Emoji and html bold text use in the title.

1 Like

Thanks for reply, will try this out.

it work perfectly !! thanks again. I never tot the telegram notification can notify the value as well.