Calculate something and store it in a helper

What is the best way to program something based on states and numbers and then put the result in a helper.

I did this in Python for another home automation software and have a lot of codes available.

Something like check time, check brightness of a sensor, etc.

If you provide a bit more context people may be able to provide better suggestions. It may depend on what you want to do with the helper, whether or not you want to be able to manually change it from the front end, etc.

My first recommendation is a template sensor.

I won’t be presumptuous and say this is the best. It is a way to do it. It also depends on what you would like to do. Here are some examples:

sensor:
  - platform: min_max
    name: "Main Floor Average Temperature"
    type: mean
    round_digits: 1
    entity_ids:
      - sensor.multisensor_6_air_temperature
      - sensor.kitchen_flood_sensor_air_temperature_2
      - sensor.main_floor_temperature
      - sensor.mil_bath_leak_sensor_air_temperature_2
      - sensor.mud_room_fibaro_air_temperature_2

#--------------------------------------

sensor:
  - platform: template
    sensors:
      total_watering_time:
        friendly_name: "Total Cycle Time"
        unique_id: "Total Cycle Time in Minutes"
        unit_of_measurement: "min"
        value_template: >-
          {% set z1 = states('input_number.zone1') | float %}
          {% set z2 = states('input_number.zone2') | float %}
          {% set z3 = states('input_number.zone3') | float %}
          {% set z4 = states('input_number.zone4') | float %}
          {% set z5 = states('input_number.zone5') | float %}
          {% set z6 = states('input_number.zone6') | float %}
          {% set z7 = states('input_number.zone7') | float %}
          {% set z8 = states('input_number.zone8') | float %}
          {% set z9 = states('input_number.zone9') | float %}
          {% set z10 = states('input_number.zone10') | float %}
          {% set z11 = states('input_number.zone11') | float %}

          {{ (z1 + z2 + z3 + z4 + z5 + z6 + z7 +z8 + z9 + z10 + z11) }}

#-------------------------------------------------------------------------------------
template:
  binary_sensor:
    - name: "run_fireplace"
      auto_off: 2:00:00
        {% set time_early = now() > today_at("19:00") %}
        {% set time_late = now() < today_at("24:00") %}
        {% set temp = states('sensor.familyroomsensors_air_temperature') %}
        {{ is_number(temp) and temp | float < 55 and time_early and time_late }}