Hello, I would like to create an entry that retrieves the data (number) of the last updated state of my sensor: sensor.0x70ac08fffe11f60e_energy And add the data by increasing them on the new entry. This is for an energy sensor in kWh. If you can help me to code this script. Many thanks in advance.
What you are looking for sounds not like a script, but like a template sensor.
The information you provided is very limited (so a more detailed description whould be adviseable for a more detailed answer ) , but based on what I understood the (untested) code should be something like this:
template:
- sensor:
- name: "70ac08fffe11f60e_added_energy"
unit_of_measurement: "kWh"
state: >
{% set sensor_value = states('0x70ac08fffe11f60e_energy') | float(default=0) %}
{% set add_value = 123 %}
{{ (sensor_value + add_value) }}