Help on creating complex automation trigger

Dear forum,
I am trying to trigger on low energy price from Nordpool.
The following pseudocode describes what I am trying to do:

float: low_price_threshold;
float: current_price;
low_price: boolean;
waterheater_set_temp: high, normal;

low_price_threshold = minimum + (average - minimum)/2;
if (low_price_threshold - current_price <= 0) then low_price = true;
else low_price = false;
if low_price then waterheater_set_temp = high;
else waterheater_set_temp = normal;

“average” and “minimum” are attributes from the Nordpool integration. I am quite lacking in my YAML understanding and the GUI doesn’t really help with this. Can anyone help get me going, please?

/Fumble

I managed to get this solved with help from another forum. Here is the result in config.yaml, in case someone is interested:

template:
  - sensor:
      - name: "cheap"
        state: >
          {{float( state_attr( 'sensor.nordpool_kwh_se3_sek_2_05_0' , 'current_price' ) ) < ( ( float( state_attr( 'sensor.nordpool_kwh_se3_sek_2_05_0' , 'average' ) ) + float( state_attr( 'sensor.nordpool_kwh_se3_sek_2_05_0' , 'min' ) ) ) / 2 ) }}
  - sensor:
      - name: "expensive"
        state: >
          {{float( state_attr( 'sensor.nordpool_kwh_se3_sek_2_05_0' , 'current_price' ) ) > ( ( float( state_attr( 'sensor.nordpool_kwh_se3_sek_2_05_0' , 'max' ) ) + float( state_attr( 'sensor.nordpool_kwh_se3_sek_2_05_0' , 'average' ) ) ) / 2 ) }}

It lets me figure out the top and bottom quartils.
/Fumble