Automation sets the result of formula as a value of entity

Hi there,

I have a freshly installed PV system with a home battery storage.
I would like to setup the automation, that will interrupt discharging of energy from the battery for the night when I have a cheap tariff but I don’t want to charge the battery either during that time.

I need to set a value for number.goodwe_depth_of_discharge_on_grid at a certain time in a day that will be equal to a following formula:
number.goodwe_depth_of_discharge_on_grid = (100 - sensor.battery_state_of_charge)

I know it must be easy, I am just new to this :slight_smile:

Thanks a lot for any help!

- service: number.set_value
  target:
    entity_id: number.goodwe_depth_of_discharge_on_grid
  data:
    value: "{{ 100 - states('sensor.battery_state_of_charge')|float(0) }}"

The 0 I used in the filter that converts your state from a string to a number, |float(0) is the default value that will be used if your sensor is unavailable for some reason. Choose this value wisely.

Awesome…works flawlessly :slight_smile:

Thanks a lot for your quick help!